Aktueller Stand
This commit is contained in:
41
backend/node_modules/fastify/test/buffer.test.js
generated
vendored
41
backend/node_modules/fastify/test/buffer.test.js
generated
vendored
@@ -1,7 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const { test } = require('node:test')
|
||||
const Fastify = require('..')
|
||||
|
||||
test('Buffer test', async t => {
|
||||
@@ -12,7 +11,7 @@ test('Buffer test', async t => {
|
||||
return request.body
|
||||
})
|
||||
|
||||
test('should return 200 if the body is not empty', async t => {
|
||||
await test('should return 200 if the body is not empty', async t => {
|
||||
t.plan(3)
|
||||
|
||||
const response = await fastify.inject({
|
||||
@@ -24,12 +23,12 @@ test('Buffer test', async t => {
|
||||
}
|
||||
})
|
||||
|
||||
t.error(response.error)
|
||||
t.equal(response.statusCode, 200)
|
||||
t.same(response.payload.toString(), '{"hello":"world"}')
|
||||
t.assert.ifError(response.error)
|
||||
t.assert.strictEqual(response.statusCode, 200)
|
||||
t.assert.deepStrictEqual(response.payload.toString(), '{"hello":"world"}')
|
||||
})
|
||||
|
||||
test('should return 400 if the body is empty', async t => {
|
||||
await test('should return 400 if the body is empty', async t => {
|
||||
t.plan(3)
|
||||
|
||||
const response = await fastify.inject({
|
||||
@@ -41,13 +40,35 @@ test('Buffer test', async t => {
|
||||
}
|
||||
})
|
||||
|
||||
t.error(response.error)
|
||||
t.equal(response.statusCode, 400)
|
||||
t.same(JSON.parse(response.payload.toString()), {
|
||||
t.assert.ifError(response.error)
|
||||
t.assert.strictEqual(response.statusCode, 400)
|
||||
t.assert.deepStrictEqual(JSON.parse(response.payload.toString()), {
|
||||
error: 'Bad Request',
|
||||
code: 'FST_ERR_CTP_EMPTY_JSON_BODY',
|
||||
message: 'Body cannot be empty when content-type is set to \'application/json\'',
|
||||
statusCode: 400
|
||||
})
|
||||
})
|
||||
|
||||
await test('should return 400 if the body is invalid json', async t => {
|
||||
t.plan(3)
|
||||
|
||||
const response = await fastify.inject({
|
||||
method: 'DELETE',
|
||||
url: '/',
|
||||
payload: Buffer.from(']'),
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
t.assert.ifError(response.error)
|
||||
t.assert.strictEqual(response.statusCode, 400)
|
||||
t.assert.deepStrictEqual(JSON.parse(response.payload.toString()), {
|
||||
error: 'Bad Request',
|
||||
code: 'FST_ERR_CTP_INVALID_JSON_BODY',
|
||||
message: 'Body is not valid JSON but content-type is set to \'application/json\'',
|
||||
statusCode: 400
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user