strong-tie/inbound-calls
0
1'use strict'2 3const { test } = require('node:test')4const Fastify = require('../..')5 6test('fastify.all should add all the methods to the same url', async t => {7 const fastify = Fastify()8 9 const requirePayload = [10 'POST',11 'PUT',12 'PATCH'13 ]14 15 const supportedMethods = fastify.supportedMethods16 t.plan(supportedMethods.length)17 18 fastify.all('/', (req, reply) => {19 reply.send({ method: req.raw.method })20 })21 22 await Promise.all(supportedMethods.map(async method => injectRequest(method)))23 24 async function injectRequest (method) {25 const options = {26 url: '/',27 method28 }29 30 if (requirePayload.includes(method)) {31 options.payload = { hello: 'world' }32 }33 34 const res = await fastify.inject(options)35 const payload = JSON.parse(res.payload)36 t.assert.deepStrictEqual(payload, { method })37 }38})39 