helpyourneighbour/backend/src/__tests__/helpRequests.test.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

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);
});