auto(agent): Add comprehensive error handling tests for addresses route
This commit is contained in:
parent
3d217914dc
commit
5f695c06d7
2 changed files with 59 additions and 2 deletions
|
|
@ -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;
|
||||
});
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue