From 5f695c06d7337421e282a43d09f4f66d9ea29295 Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Fri, 6 Mar 2026 20:46:45 +0000 Subject: [PATCH] auto(agent): Add comprehensive error handling tests for addresses route --- backend/src/__tests__/addresses.test.js | 57 +++++++++++++++++++++++++ docs/runtime/pick_next_task_state.env | 4 +- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/backend/src/__tests__/addresses.test.js b/backend/src/__tests__/addresses.test.js index 8986916..87715c2 100644 --- a/backend/src/__tests__/addresses.test.js +++ b/backend/src/__tests__/addresses.test.js @@ -164,4 +164,61 @@ test('POST /addresses/verify - request not pending', async () => { assert.strictEqual(res.status, 409); const data = await res.json(); assert.ok(data.error); +}); + +// Additional test for error handling in change-request route +test('POST /addresses/change-request - database error', async () => { + // Mock existing address in DB + await pool.query( + `INSERT INTO addresses (user_id, address_encrypted, postal_verified_at) + VALUES (?, ?, CURRENT_TIMESTAMP)`, + [mockUser.userId, encryptText('Old Address')] + ); + + // Temporarily disable the database to simulate an error + const originalQuery = pool.query; + pool.query = async () => { throw new Error('Database error'); }; + + const req = createTestRequest('/addresses/change-request', 'POST', { + newAddress: 'New Test Address' + }); + + const res = await app.request(req); + + assert.strictEqual(res.status, 500); + const data = await res.json(); + assert.ok(data.error); + + // Restore the original query function + pool.query = originalQuery; +}); + +// Additional test for error handling in verify route +test('POST /addresses/verify - database error during transaction', async () => { + // Mock a change request first + const code = '123456'; + const codeHash = 'hashed_code'; + await pool.query( + `INSERT INTO address_change_requests (user_id, new_address_encrypted, verification_code_hash, status) + VALUES (?, ?, ?, 'pending_letter')`, + [mockUser.userId, encryptText('New Address'), codeHash] + ); + + // Temporarily disable the database to simulate an error + const originalQuery = pool.query; + pool.query = async () => { throw new Error('Database error'); }; + + const req = createTestRequest('/addresses/verify', 'POST', { + requestId: 1, + code + }); + + const res = await app.request(req); + + assert.strictEqual(res.status, 500); + const data = await res.json(); + assert.ok(data.error); + + // Restore the original query function + pool.query = originalQuery; }); \ No newline at end of file diff --git a/docs/runtime/pick_next_task_state.env b/docs/runtime/pick_next_task_state.env index ab7d297..05d5ea1 100644 --- a/docs/runtime/pick_next_task_state.env +++ b/docs/runtime/pick_next_task_state.env @@ -1,2 +1,2 @@ -LAST_ROUTE=reviews.js -UPDATED_AT=2026-03-06T20:44:18Z +LAST_ROUTE=addresses.js +UPDATED_AT=2026-03-06T20:46:06Z