File size: 853 Bytes
23ac194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
'use strict'

const { test } = require('node:test')
const Fastify = require('../..')

test('fastify.all should add all the methods to the same url', async t => {
  const fastify = Fastify()

  const requirePayload = [
    'POST',
    'PUT',
    'PATCH'
  ]

  const supportedMethods = fastify.supportedMethods
  t.plan(supportedMethods.length)

  fastify.all('/', (req, reply) => {
    reply.send({ method: req.raw.method })
  })

  await Promise.all(supportedMethods.map(async method => injectRequest(method)))

  async function injectRequest (method) {
    const options = {
      url: '/',
      method
    }

    if (requirePayload.includes(method)) {
      options.payload = { hello: 'world' }
    }

    const res = await fastify.inject(options)
    const payload = JSON.parse(res.payload)
    t.assert.deepStrictEqual(payload, { method })
  }
})