Skip to content

Commit 0046632

Browse files
committed
test(track-user): verified plain text body returns 400
Signed-off-by: Himanshujha7 <tigmanshujah@gmail.com>
1 parent e9da96e commit 0046632

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

app/api/track-user/route.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ describe('POST /api/track-user', () => {
4848
expect(data.success).toBe(false);
4949
expect(data.error).toBe('Malformed JSON request body');
5050
});
51+
it('returns 400 when body is plain text (not JSON)', async () => {
52+
const req = new Request('http://localhost/api/track-user', {
53+
method: 'POST',
54+
headers: { 'Content-Type': 'text/plain' },
55+
body: 'not json',
56+
});
57+
const response = await POST(req);
58+
expect(response.status).toBe(400);
59+
const data = await response.json();
60+
expect(data.success).toBe(false);
61+
});
5162

5263
it('returns 400 when username is missing', async () => {
5364
const response = await POST(makeRequest({}));

0 commit comments

Comments
 (0)