From e4334715899ea5cf7fe65addac3f310ce099ea7d Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Fri, 6 Mar 2026 20:33:43 +0000 Subject: [PATCH] auto(agent): enhance validation tests for helpRequests route --- backend/src/__tests__/helpRequests.test.js | 141 +++++++++++++++++++++ docs/runtime/pick_next_task_state.env | 4 +- 2 files changed, 143 insertions(+), 2 deletions(-) diff --git a/backend/src/__tests__/helpRequests.test.js b/backend/src/__tests__/helpRequests.test.js index 599071c..51705a6 100644 --- a/backend/src/__tests__/helpRequests.test.js +++ b/backend/src/__tests__/helpRequests.test.js @@ -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', diff --git a/docs/runtime/pick_next_task_state.env b/docs/runtime/pick_next_task_state.env index 24c4d76..36f98bd 100644 --- a/docs/runtime/pick_next_task_state.env +++ b/docs/runtime/pick_next_task_state.env @@ -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