1 | 'use strict'
|
2 |
|
3 | const t = require('tap')
|
4 | const test = t.test
|
5 | const Fastify = require('..')
|
6 |
|
7 | const schema = {
|
8 | schema: { },
|
9 | config: {
|
10 | value1: 'foo',
|
11 | value2: true
|
12 | }
|
13 | }
|
14 |
|
15 | function handler (req, reply) {
|
16 | reply.send(reply.context.config)
|
17 | }
|
18 |
|
19 | test('config', t => {
|
20 | t.plan(9)
|
21 | const fastify = Fastify()
|
22 |
|
23 | fastify.get('/get', {
|
24 | schema: schema.schema,
|
25 | config: Object.assign({}, schema.config)
|
26 | }, handler)
|
27 |
|
28 | fastify.route({
|
29 | method: 'GET',
|
30 | url: '/route',
|
31 | schema: schema.schema,
|
32 | handler: handler,
|
33 | config: Object.assign({}, schema.config)
|
34 | })
|
35 |
|
36 | fastify.route({
|
37 | method: 'GET',
|
38 | url: '/no-config',
|
39 | schema: schema.schema,
|
40 | handler: handler
|
41 | })
|
42 |
|
43 | fastify.inject({
|
44 | method: 'GET',
|
45 | url: '/get'
|
46 | }, (err, response) => {
|
47 | t.error(err)
|
48 | t.strictEqual(response.statusCode, 200)
|
49 | t.deepEquals(JSON.parse(response.payload), Object.assign({ url: '/get' }, schema.config))
|
50 | })
|
51 |
|
52 | fastify.inject({
|
53 | method: 'GET',
|
54 | url: '/route'
|
55 | }, (err, response) => {
|
56 | t.error(err)
|
57 | t.strictEqual(response.statusCode, 200)
|
58 | t.deepEquals(JSON.parse(response.payload), Object.assign({ url: '/route' }, schema.config))
|
59 | })
|
60 |
|
61 | fastify.inject({
|
62 | method: 'GET',
|
63 | url: '/no-config'
|
64 | }, (err, response) => {
|
65 | t.error(err)
|
66 | t.strictEqual(response.statusCode, 200)
|
67 | t.deepEquals(JSON.parse(response.payload), { url: '/no-config' })
|
68 | })
|
69 | })
|