auto(agent): enhance profile route tests with decryption error handling

This commit is contained in:
OpenClaw 2026-03-06 21:01:45 +00:00
parent 5d5b2460b5
commit 1e37764fe1
2 changed files with 41 additions and 2 deletions

View file

@ -147,3 +147,42 @@ test('GET / should return user profile with decrypted phone', async () => {
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;
}
});

View file

@ -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