forked from hemerajs/fastify-hemera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.test.js
72 lines (62 loc) · 1.33 KB
/
basic.test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict'
// eslint-disable-next-line node/no-unpublished-require
const { test } = require('tap')
// eslint-disable-next-line node/no-unpublished-require
const ts = require('hemera-testsuite')
const build = require('./example')
let fastify = null
let server = null
const port = 4234
test('setup', t => {
server = ts.start_server(port, err => {
t.error(err)
fastify = build({
plugins: [],
nats: `nats://127.0.0.1:${port}`
})
t.end()
})
})
test('reply decorator', t => {
t.plan(2)
fastify.inject(
{
method: 'GET',
url: '/reply?a=1&b=2'
},
(err, res) => {
t.error(err)
const payload = JSON.parse(res.payload)
t.deepEqual(payload, { result: 3 })
}
)
})
test('fastify decorator', t => {
t.plan(1)
fastify.hemera
.act({ topic: 'math', cmd: 'add', a: 1, b: 2 })
.then(result => {
t.deepEqual(result.data, { result: 3 })
})
.catch(() => t.fail('should not land in catch'))
})
test('request decorator', t => {
t.plan(2)
fastify.inject(
{
method: 'GET',
url: '/request?a=1&b=2'
},
(err, res) => {
t.error(err)
const payload = JSON.parse(res.payload)
t.deepEqual(payload, { result: 3 })
}
)
})
test('teardown', function teardown(t) {
fastify.close(() => {
server.kill()
t.end()
})
})