diff --git a/backend/src/__tests__/profile.test.js b/backend/src/__tests__/profile.test.js index 96015f6..3ad7642 100644 --- a/backend/src/__tests__/profile.test.js +++ b/backend/src/__tests__/profile.test.js @@ -146,4 +146,43 @@ test('GET / should return user profile with decrypted phone', async () => { pool.query = originalQuery; decryptText = originalDecrypt; } +}); + +// Test profile route GET / with invalid decryption +test('GET / should handle decryption error gracefully', async () => { + const req = { + user: { userId: 1 } + }; + + const res = { + status: (code) => { + res.statusCode = code; + return res; + }, + json: (data) => { + res.body = data; + } + }; + + // Mock the pool.query function to simulate database fetch + const originalQuery = pool.query; + pool.query = async (sql, params) => { + if (sql.includes('SELECT id, name, email, phone_encrypted FROM users')) { + return [[{ + id: 1, + name: 'Test User', + email: 'test@example.com', + phone_encrypted: 'invalid_encrypted_data' + }]]; + } + return []; + }; + + try { + await router.get('/', req, res); + assert.strictEqual(res.statusCode, 500); + assert.deepStrictEqual(res.body, { error: 'Failed to decrypt phone number' }); + } finally { + 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 eeea4e0..dd1702b 100644 --- a/docs/runtime/pick_next_task_state.env +++ b/docs/runtime/pick_next_task_state.env @@ -1,2 +1,2 @@ -LAST_ROUTE=offers.js -UPDATED_AT=2026-03-06T20:54:13Z +LAST_ROUTE=profile.js +UPDATED_AT=2026-03-06T21:01:14Z