CoolFace
Apppublic

strong-tie/inbound-calls

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