From a972cdc55897a46917fb8c2d513376b61e1d4366 Mon Sep 17 00:00:00 2001 From: alexeh Date: Sun, 3 Mar 2024 10:46:45 +0300 Subject: [PATCH] Refactor setupUser test utility --- api/test/utils/userAuth.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/api/test/utils/userAuth.ts b/api/test/utils/userAuth.ts index f568c0590..c3cfbf8a6 100644 --- a/api/test/utils/userAuth.ts +++ b/api/test/utils/userAuth.ts @@ -14,7 +14,8 @@ export type TestUser = { jwtToken: string; user: User; password: string }; export async function setupTestUser( applicationManager: TestApplication, roleName: ROLES = ROLES.ADMIN, - extraData: Partial = { password: 'Password123!' }, + extraData: Partial> = {}, + password: string = 'Password123', ): Promise { const salt = await genSalt(); const role = new Role(); @@ -22,22 +23,20 @@ export async function setupTestUser( const entityManager = applicationManager.get(EntityManager); const userRepository = entityManager.getRepository(User); - const { password, ...restOfExtraData } = extraData; - await setUpRolesAndPermissions(entityManager); let existingUser = await userRepository.findOne({ - where: { email: E2E_CONFIG.users.signUp.email }, + where: { email: extraData.email ?? E2E_CONFIG.users.signUp.email }, }); if (!existingUser) { existingUser = await userRepository.save({ ...E2E_CONFIG.users.signUp, salt, - password: await hash(password!, salt), + password: await hash(password, salt), isActive: true, isDeleted: false, roles: [role], - ...restOfExtraData, + ...extraData, }); }