forked from fastify/fastify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcase-insensitive.test.js
123 lines (102 loc) · 2.72 KB
/
case-insensitive.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use strict'
const { test } = require('node:test')
const Fastify = require('..')
const sget = require('simple-get').concat
test('case insensitive', (t, done) => {
t.plan(4)
const fastify = Fastify({
caseSensitive: false
})
t.after(() => fastify.close())
fastify.get('/foo', (req, reply) => {
reply.send({ hello: 'world' })
})
fastify.listen({ port: 0 }, err => {
t.assert.ifError(err)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/FOO'
}, (err, response, body) => {
t.assert.ifError(err)
t.assert.strictEqual(response.statusCode, 200)
t.assert.deepStrictEqual(JSON.parse(body), {
hello: 'world'
})
done()
})
})
})
test('case insensitive inject', (t, done) => {
t.plan(4)
const fastify = Fastify({
caseSensitive: false
})
t.after(() => fastify.close())
fastify.get('/foo', (req, reply) => {
reply.send({ hello: 'world' })
})
fastify.listen({ port: 0 }, err => {
t.assert.ifError(err)
fastify.inject({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/FOO'
}, (err, response) => {
t.assert.ifError(err)
t.assert.strictEqual(response.statusCode, 200)
t.assert.deepStrictEqual(JSON.parse(response.payload), {
hello: 'world'
})
done()
})
})
})
test('case insensitive (parametric)', (t, done) => {
t.plan(5)
const fastify = Fastify({
caseSensitive: false
})
t.after(() => fastify.close())
fastify.get('/foo/:param', (req, reply) => {
t.assert.strictEqual(req.params.param, 'bAr')
reply.send({ hello: 'world' })
})
fastify.listen({ port: 0 }, err => {
t.assert.ifError(err)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/FoO/bAr'
}, (err, response, body) => {
t.assert.ifError(err)
t.assert.strictEqual(response.statusCode, 200)
t.assert.deepStrictEqual(JSON.parse(body), {
hello: 'world'
})
done()
})
})
})
test('case insensitive (wildcard)', (t, done) => {
t.plan(5)
const fastify = Fastify({
caseSensitive: false
})
t.after(() => fastify.close())
fastify.get('/foo/*', (req, reply) => {
t.assert.strictEqual(req.params['*'], 'bAr/baZ')
reply.send({ hello: 'world' })
})
fastify.listen({ port: 0 }, err => {
t.assert.ifError(err)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/FoO/bAr/baZ'
}, (err, response, body) => {
t.assert.ifError(err)
t.assert.strictEqual(response.statusCode, 200)
t.assert.deepStrictEqual(JSON.parse(body), {
hello: 'world'
})
done()
})
})
})