auto(agent): enhance profile route tests with decryption error handling
This commit is contained in:
parent
5d5b2460b5
commit
1e37764fe1
2 changed files with 41 additions and 2 deletions
|
|
@ -146,4 +146,43 @@ test('GET / should return user profile with decrypted phone', async () => {
|
||||||
pool.query = originalQuery;
|
pool.query = originalQuery;
|
||||||
decryptText = originalDecrypt;
|
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;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
LAST_ROUTE=offers.js
|
LAST_ROUTE=profile.js
|
||||||
UPDATED_AT=2026-03-06T20:54:13Z
|
UPDATED_AT=2026-03-06T21:01:14Z
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue