Skip to content

Commit

Permalink
setup roles and permissions for test user
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Dec 20, 2023
1 parent 67309c0 commit f18b931
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions api/test/utils/userAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { User } from 'modules/users/user.entity';
import { EntityManager } from 'typeorm';
import { TestApplication } from './application-manager';
import { faker } from '@faker-js/faker';
import { Permission } from '../../src/modules/authorization/permissions/permissions.entity';
import { PERMISSIONS } from '../../src/modules/authorization/permissions/permissions.enum';

export type TestUser = { jwtToken: string; user: User; password: string };

Expand All @@ -25,6 +27,8 @@ export async function setupTestUser(

const password = extraDataPassword ?? faker.internet.password();

await setUpRolesAndPermissions(entityManager);

const user = await userRepository.save({
...E2E_CONFIG.users.signUp,
salt,
Expand All @@ -40,3 +44,23 @@ export async function setupTestUser(

return { jwtToken: response.body.accessToken, user, password };
}

async function setUpRolesAndPermissions(
entityManager: EntityManager,
): Promise<any> {
const permissions: Permission[] = Object.values(PERMISSIONS).map(
(permission: PERMISSIONS) =>
({
action: permission,
} as Permission),
);

const roles: Role[] = Object.values(ROLES).map(
(role: ROLES) =>
({
name: role,
} as Role),
);
await entityManager.getRepository(Permission).save(permissions);
await entityManager.getRepository(Role).save(roles);
}

0 comments on commit f18b931

Please sign in to comment.