UNPKG

2.54 kBJavaScriptView Raw
1'use strict'
2
3const t = require('tap')
4const test = t.test
5const Fastify = require('..')
6const sget = require('simple-get').concat
7
8test('case insensitive', t => {
9 t.plan(4)
10
11 const fastify = Fastify({
12 caseSensitive: false
13 })
14 t.tearDown(fastify.close.bind(fastify))
15
16 fastify.get('/foo', (req, reply) => {
17 reply.send({ hello: 'world' })
18 })
19
20 fastify.listen(0, err => {
21 t.error(err)
22
23 sget({
24 method: 'GET',
25 url: 'http://localhost:' + fastify.server.address().port + '/FOO'
26 }, (err, response, body) => {
27 t.error(err)
28 t.strictEqual(response.statusCode, 200)
29 t.deepEqual(JSON.parse(body), {
30 hello: 'world'
31 })
32 })
33 })
34})
35
36test('case insensitive inject', t => {
37 t.plan(4)
38
39 const fastify = Fastify({
40 caseSensitive: false
41 })
42 t.tearDown(fastify.close.bind(fastify))
43
44 fastify.get('/foo', (req, reply) => {
45 reply.send({ hello: 'world' })
46 })
47
48 fastify.listen(0, err => {
49 t.error(err)
50
51 fastify.inject({
52 method: 'GET',
53 url: 'http://localhost:' + fastify.server.address().port + '/FOO'
54 }, (err, response) => {
55 t.error(err)
56 t.strictEqual(response.statusCode, 200)
57 t.deepEqual(JSON.parse(response.payload), {
58 hello: 'world'
59 })
60 })
61 })
62})
63
64test('case insensitive (parametric)', t => {
65 t.plan(5)
66
67 const fastify = Fastify({
68 caseSensitive: false
69 })
70 t.tearDown(fastify.close.bind(fastify))
71
72 fastify.get('/foo/:param', (req, reply) => {
73 t.strictEqual(req.params.param, 'bAr')
74 reply.send({ hello: 'world' })
75 })
76
77 fastify.listen(0, err => {
78 t.error(err)
79
80 sget({
81 method: 'GET',
82 url: 'http://localhost:' + fastify.server.address().port + '/FoO/bAr'
83 }, (err, response, body) => {
84 t.error(err)
85 t.strictEqual(response.statusCode, 200)
86 t.deepEqual(JSON.parse(body), {
87 hello: 'world'
88 })
89 })
90 })
91})
92
93test('case insensitive (wildcard)', t => {
94 t.plan(5)
95
96 const fastify = Fastify({
97 caseSensitive: false
98 })
99 t.tearDown(fastify.close.bind(fastify))
100
101 fastify.get('/foo/*', (req, reply) => {
102 t.strictEqual(req.params['*'], 'bAr/baZ')
103 reply.send({ hello: 'world' })
104 })
105
106 fastify.listen(0, err => {
107 t.error(err)
108
109 sget({
110 method: 'GET',
111 url: 'http://localhost:' + fastify.server.address().port + '/FoO/bAr/baZ'
112 }, (err, response, body) => {
113 t.error(err)
114 t.strictEqual(response.statusCode, 200)
115 t.deepEqual(JSON.parse(body), {
116 hello: 'world'
117 })
118 })
119 })
120})