auto(agent): enhance profile route tests with valid decryption case
This commit is contained in:
parent
f867cbb1f8
commit
bc32b660be
2 changed files with 54 additions and 2 deletions
|
|
@ -94,4 +94,56 @@ test('GET / should return user profile', async () => {
|
||||||
} finally {
|
} finally {
|
||||||
pool.query = originalQuery;
|
pool.query = originalQuery;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test profile route GET / with valid decryption
|
||||||
|
test('GET / should return user profile with decrypted phone', 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: 'valid_encrypted_data'
|
||||||
|
}]];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mock decryptText to return a valid phone number
|
||||||
|
const originalDecrypt = decryptText;
|
||||||
|
decryptText = (payload) => {
|
||||||
|
if (payload === 'valid_encrypted_data') return '123-456-7890';
|
||||||
|
throw new Error('Decryption failed');
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await router.get('/', req, res);
|
||||||
|
assert.strictEqual(res.statusCode, 200);
|
||||||
|
assert.deepStrictEqual(res.body, {
|
||||||
|
id: 1,
|
||||||
|
name: 'Test User',
|
||||||
|
email: 'test@example.com',
|
||||||
|
phone: '123-456-7890'
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
pool.query = originalQuery;
|
||||||
|
decryptText = originalDecrypt;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
LAST_ROUTE=offers.js
|
LAST_ROUTE=profile.js
|
||||||
UPDATED_AT=2026-03-06T20:42:06Z
|
UPDATED_AT=2026-03-06T20:43:06Z
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue