Reputation: 11
I am writing an end-to-end test for a NestJS API endpoint that creates a table. The issue is that the test consistently returns a 400 Bad Request, while the same request in Postman works perfectly and returns 201 Created. Here is the test code I am using:
it('Test #1: Table creation with "name: table | capacity', async () =\> {
const data = {
capacity: 22,
name: 'test',
};
const result = await request
.post('/tables')
.send(data)
.auth(await tokenOwner, { type: 'bearer' })
.expect(201);
console.log(JSON.stringify(data));
console.log(result.statusCode);
console.log(result);
});
Confirmed that the endpoint works in Postman with the exact same payload and authentication. Verified the token is correct and valid by logging it. Added console.log to check the payload and response during the test, and the payload appears correct.
Upvotes: 1
Views: 43