-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathtest.js
44 lines (36 loc) · 869 Bytes
/
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
'use strict'
const t = require('tap')
const path = require('node:path')
const Fastify = require('fastify')
const autoLoad = require('../../../')
t.plan(10)
const app = Fastify()
app.register(autoLoad, {
dir: path.join(__dirname, 'routes'),
autoHooks: true,
cascadeHooks: true
})
app.ready(function (err) {
t.error(err)
app.inject({
url: '/'
}, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200)
t.same(res.json(), { path: '/' })
})
app.inject({
url: '/entity'
}, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200)
t.same(res.json(), { path: '/entity', hooked: ['root'] })
})
app.inject({
url: '/entity/1'
}, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200)
t.same(res.json(), { path: '/entity/1', hooked: ['root'], params: { entity: 1 } })
})
})