we went to mocks - now going to unit-setup.ts - centralized
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 37m47s
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 37m47s
This commit is contained in:
@@ -53,15 +53,20 @@ describe('User API Routes Integration Tests', () => {
|
||||
});
|
||||
|
||||
// After all tests, clean up by deleting the created user.
|
||||
// This now cleans up ALL users created by this test suite to prevent pollution.
|
||||
afterAll(async () => {
|
||||
if (testUser) {
|
||||
logger.debug(`[user.integration.test.ts afterAll] Cleaning up user ID: ${testUser.user_id}`);
|
||||
// This requires an authenticated call to delete the account.
|
||||
const response = await apiClient.deleteUserAccount(TEST_PASSWORD, authToken);
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
logger.error(`Failed to clean up user in test: ${errorData.message}`);
|
||||
const pool = getPool();
|
||||
try {
|
||||
// Find all users created during this test run by their email pattern.
|
||||
const res = await pool.query("SELECT user_id FROM public.users WHERE email LIKE 'user-test-%' OR email LIKE 'delete-me-%' OR email LIKE 'reset-me-%'");
|
||||
if (res.rows.length > 0) {
|
||||
const userIds = res.rows.map(r => r.user_id);
|
||||
logger.debug(`[user.integration.test.ts afterAll] Cleaning up ${userIds.length} test users...`);
|
||||
// Use a direct DB query for cleanup, which is faster and more reliable than API calls.
|
||||
await pool.query('DELETE FROM public.users WHERE user_id = ANY($1::uuid[])', [userIds]);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Failed to clean up test users from database.', { error });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user