auto(agent): Add tests for helpRequests route
This commit is contained in:
parent
54d5b5d876
commit
902804c317
1 changed files with 40 additions and 0 deletions
40
backend/src/__tests__/helpRequests.test.js
Normal file
40
backend/src/__tests__/helpRequests.test.js
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('assert');
|
||||||
|
const { app } = require('../app');
|
||||||
|
|
||||||
|
test('GET /help-requests should return all help requests', async () => {
|
||||||
|
const response = await app.inject({
|
||||||
|
method: 'GET',
|
||||||
|
url: '/help-requests'
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(response.statusCode, 200);
|
||||||
|
assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('POST /help-requests should create a new help request', async () => {
|
||||||
|
const newRequest = {
|
||||||
|
title: 'Test Help Request',
|
||||||
|
description: 'This is a test help request',
|
||||||
|
location: 'Test Location'
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await app.inject({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/help-requests',
|
||||||
|
payload: newRequest
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(response.statusCode, 201);
|
||||||
|
assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('POST /help-requests should validate required fields', async () => {
|
||||||
|
const response = await app.inject({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/help-requests',
|
||||||
|
payload: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(response.statusCode, 400);
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue