-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.js
More file actions
70 lines (69 loc) · 2.03 KB
/
test.js
File metadata and controls
70 lines (69 loc) · 2.03 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require('./test-init.js')
const { expect } = require('chai')
const request = require('supertest')
const nock = require('nock')
const app = require('./index')
const pkg = require('./package.json')
describe('app tests', () => {
it('TARGET should be used in hello', (done) => {
process.env.TARGET = 'world'
const out = `Hello world! I am at version: ${pkg.version}.`
request(app)
.get('/')
.expect(200)
.end((err, res) => {
if (err) {
return done(err)
}
expect(res.text).to.be.equal(out)
return done()
})
})
it('if SERVANTS is set, then role MASTER is chosen, so buttons are rendered', (done) => {
process.env.SERVANTS = 'bla,dibla'
const shouldContain = '<button onClick="fetchServant'
request(app)
.get('/')
.expect(200)
.end((err, res) => {
if (err) {
return done(err)
}
expect(res.text).to.include(shouldContain)
return done()
})
})
it('if INFORMANT is set, then informant will give a message', (done) => {
const message = "it's ok"
delete process.env.SERVANTS
process.env.INFORMANT = 'http://some.informant'
nock(process.env.INFORMANT).get('/').reply(200, message)
request(app)
.get('/')
.expect(200)
.end((err, res) => {
if (err) {
return done(err)
}
expect(res.text).to.include(` My informant told me this: "${message}".`)
return done()
})
})
it("if INFORMANT is set but can't respond, then informant will give another message", (done) => {
delete process.env.SERVANTS
process.env.INFORMANT = 'http://some.informant'
nock(process.env.INFORMANT).get('/').replyWithError({ code: 'ETIMEDOUT' })
request(app)
.get('/')
.expect(200)
.end((err, res) => {
if (err) {
return done(err)
}
expect(res.text).to.include(
` I couldn't reach my informant at ${process.env.INFORMANT}. Status Code: ETIMEDOUT`,
)
return done()
})
})
})