UNPKG

837 BJavaScriptView Raw
1'use strict'
2
3const t = require('tap')
4const test = t.test
5const Fastify = require('../..')
6const supportedMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS']
7
8test('fastify.all should add all the methods to the same url', t => {
9 t.plan(supportedMethods.length * 2)
10
11 const fastify = Fastify()
12
13 fastify.all('/', (req, reply) => {
14 reply.send({ method: req.raw.method })
15 })
16
17 supportedMethods.forEach(injectRequest)
18
19 function injectRequest (method) {
20 const options = {
21 url: '/',
22 method: method
23 }
24
25 if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
26 options.payload = { hello: 'world' }
27 }
28
29 fastify.inject(options, (err, res) => {
30 t.error(err)
31 var payload = JSON.parse(res.payload)
32 t.deepEqual(payload, { method: method })
33 })
34 }
35})