-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
56 lines (48 loc) · 1.47 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
exports.StartServer = function () {
const restify = require('restify')
const body = {
testsuite: {
package: 'http://exist-db.org/apps/my-app/tests',
timestamp: '2018-07-12T15:25:38.227Z',
tests: '1',
failures: '0',
errors: '0',
pending: '0',
time: 'PT0.02S',
testcase: [{
name: 'templating-foo',
class: 'tests:templating-foo'
}]
}
}
// this rest server mocks the reponses of exist-db's rest api for unit testing without a running eXist instance.
const server = restify.createServer({
// server.use(restify.plugins.bodyParser())
// server.use(restify.plugins.authorizationParser());
name: 'mock-exist',
version: '1.0.0'
})
// can be reached at eXist api's URI
function respond (req, res, next) {
res.setHeader('content-type', 'application/xml')
res.charSet('UTF-8')
res.send('<hello>world</hello>')
next()
}
// respond with the result of running XQsuite test
function runs (req, res, next) {
res.setHeader('content-type', 'application/json')
res.charSet('utf-8')
res.send(200, body)
next()
}
server.get('/exist/rest/db/', respond)
server.head('/exist/rest/db/', respond)
server.get('/exist/rest/db/my-app/modules/test-runner.xq', runs)
server.head('/exist/rest/db/my-app/modules/test-runner.xq', runs)
// do not use 8080!
server.listen(3000, function () {
console.log('%s listening at %s', server.name, server.url)
})
// server.close()
}