Skip to content

Commit

Permalink
fix: delete crisp test users (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
annarhughes committed Jan 25, 2024
1 parent 87d4dd3 commit 30a9cfa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,20 @@ export class UserService {
}

public async deleteCypressTestUsers(clean = false): Promise<UserEntity[]> {
let deletedUsers: UserEntity[] = [];
try {
const queryResult = await this.userRepository
.createQueryBuilder('user')
.select()
.where('user.name LIKE :searchTerm', { searchTerm: `%Cypress test%` })
.getMany();

const deletedUsers = await Promise.all(
deletedUsers = await Promise.all(
queryResult.map(async (user) => {
try {
await deleteCrispProfile(user.email);
// TODO: replace me - temporarily disabled due to too many tests accounts to delete, causing 429 errors on crisp API
// once crisp test users have been cleared using the clean function, and there are <50 test users in crisp, this can be replaced
// await deleteCrispProfile(user.email);
await this.authService.deleteFirebaseUser(user.firebaseUid);
await this.userRepository.delete(user);
return user;
Expand All @@ -392,8 +395,6 @@ export class UserService {
}
}),
);

return deletedUsers;
} catch (error) {
// If this fails we don't want to break cypress tests but we want to be alerted
this.logger.error(`deleteCypressTestUsers - Unable to delete all cypress users`, error);
Expand All @@ -413,6 +414,9 @@ export class UserService {
// If this fails we don't want to break cypress tests but we want to be alerted
this.logger.error(`deleteCypressTestUsers - Unable to clean all cypress users`, error);
}

this.logger.log(`deleteCypressTestUsers - Successfully deleted ${deletedUsers.length} users`);
return deletedUsers;
}

public async getUsers(
Expand Down

0 comments on commit 30a9cfa

Please sign in to comment.