auto(agent): enhance validation tests for helpRequests route
This commit is contained in:
parent
532b361c98
commit
e433471589
2 changed files with 143 additions and 2 deletions
|
|
@ -39,6 +39,48 @@ test('POST /help-requests should validate required fields', async () => {
|
|||
assert.strictEqual(response.statusCode, 400);
|
||||
});
|
||||
|
||||
test('POST /help-requests should validate title length', async () => {
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/help-requests',
|
||||
payload: {
|
||||
title: 'Sh',
|
||||
description: 'This is a test help request',
|
||||
valueChf: 50.0
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(response.statusCode, 400);
|
||||
});
|
||||
|
||||
test('POST /help-requests should validate description length', async () => {
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/help-requests',
|
||||
payload: {
|
||||
title: 'Test Help Request',
|
||||
description: 'Short',
|
||||
valueChf: 50.0
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(response.statusCode, 400);
|
||||
});
|
||||
|
||||
test('POST /help-requests should validate valueChf is positive', async () => {
|
||||
const response = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/help-requests',
|
||||
payload: {
|
||||
title: 'Test Help Request',
|
||||
description: 'This is a test help request',
|
||||
valueChf: -10.0
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(response.statusCode, 400);
|
||||
});
|
||||
|
||||
test('PUT /help-requests/:id should update a help request', async () => {
|
||||
const newRequest = {
|
||||
title: 'Test Help Request',
|
||||
|
|
@ -72,6 +114,105 @@ test('PUT /help-requests/:id should update a help request', async () => {
|
|||
assert.strictEqual(updateResponse.statusCode, 200);
|
||||
});
|
||||
|
||||
test('PUT /help-requests/:id should validate title length', async () => {
|
||||
const newRequest = {
|
||||
title: 'Test Help Request',
|
||||
description: 'This is a test help request',
|
||||
valueChf: 50.0
|
||||
};
|
||||
|
||||
// First create a request
|
||||
const createResponse = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/help-requests',
|
||||
payload: newRequest
|
||||
});
|
||||
|
||||
assert.strictEqual(createResponse.statusCode, 201);
|
||||
|
||||
const requestId = createResponse.json().id;
|
||||
|
||||
// Then try to update with invalid title
|
||||
const updateResponse = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/help-requests/${requestId}`,
|
||||
payload: {
|
||||
title: 'Sh',
|
||||
description: 'Updated Description',
|
||||
valueChf: 75.0,
|
||||
status: 'in_progress'
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(updateResponse.statusCode, 400);
|
||||
});
|
||||
|
||||
test('PUT /help-requests/:id should validate description length', async () => {
|
||||
const newRequest = {
|
||||
title: 'Test Help Request',
|
||||
description: 'This is a test help request',
|
||||
valueChf: 50.0
|
||||
};
|
||||
|
||||
// First create a request
|
||||
const createResponse = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/help-requests',
|
||||
payload: newRequest
|
||||
});
|
||||
|
||||
assert.strictEqual(createResponse.statusCode, 201);
|
||||
|
||||
const requestId = createResponse.json().id;
|
||||
|
||||
// Then try to update with invalid description
|
||||
const updateResponse = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/help-requests/${requestId}`,
|
||||
payload: {
|
||||
title: 'Updated Title',
|
||||
description: 'Short',
|
||||
valueChf: 75.0,
|
||||
status: 'in_progress'
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(updateResponse.statusCode, 400);
|
||||
});
|
||||
|
||||
test('PUT /help-requests/:id should validate valueChf is positive', async () => {
|
||||
const newRequest = {
|
||||
title: 'Test Help Request',
|
||||
description: 'This is a test help request',
|
||||
valueChf: 50.0
|
||||
};
|
||||
|
||||
// First create a request
|
||||
const createResponse = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/help-requests',
|
||||
payload: newRequest
|
||||
});
|
||||
|
||||
assert.strictEqual(createResponse.statusCode, 201);
|
||||
|
||||
const requestId = createResponse.json().id;
|
||||
|
||||
// Then try to update with invalid valueChf
|
||||
const updateResponse = await app.inject({
|
||||
method: 'PUT',
|
||||
url: `/help-requests/${requestId}`,
|
||||
payload: {
|
||||
title: 'Updated Title',
|
||||
description: 'Updated Description',
|
||||
valueChf: -10.0,
|
||||
status: 'in_progress'
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(updateResponse.statusCode, 400);
|
||||
});
|
||||
|
||||
test('DELETE /help-requests/:id should delete a help request', async () => {
|
||||
const newRequest = {
|
||||
title: 'Test Help Request',
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
LAST_ROUTE=contacts.js
|
||||
UPDATED_AT=2026-03-06T20:32:06Z
|
||||
LAST_ROUTE=helpRequests.js
|
||||
UPDATED_AT=2026-03-06T20:33:06Z
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue