From 07f885fea8f1d2bce9f92acfc9fb7cac2251e863 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 2 Feb 2023 18:08:34 +0900 Subject: [PATCH] refactor --- packages/backend/test/unit/RoleService.ts | 30 +++++++++-------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/backend/test/unit/RoleService.ts b/packages/backend/test/unit/RoleService.ts index fdfafdb839..c4011593be 100644 --- a/packages/backend/test/unit/RoleService.ts +++ b/packages/backend/test/unit/RoleService.ts @@ -50,6 +50,15 @@ describe('RoleService', () => { .then(x => rolesRepository.findOneByOrFail(x.identifiers[0])); } + async function assign(roleId: Role['id'], userId: User['id']) { + await roleAssignmentsRepository.insert({ + id: genAid(new Date()), + createdAt: new Date(), + roleId, + userId, + }); + } + beforeEach(async () => { app = await Test.createTestingModule({ imports: [ @@ -131,12 +140,7 @@ describe('RoleService', () => { }, }, }); - await roleAssignmentsRepository.insert({ - id: 'a', - createdAt: new Date(), - roleId: role.id, - userId: user.id, - }); + await assign(role.id, user.id); metaService.fetch.mockResolvedValue({ policies: { canManageCustomEmojis: false, @@ -170,18 +174,8 @@ describe('RoleService', () => { }, }, }); - await roleAssignmentsRepository.insert({ - id: genAid(new Date()), - createdAt: new Date(), - roleId: role1.id, - userId: user.id, - }); - await roleAssignmentsRepository.insert({ - id: genAid(new Date()), - createdAt: new Date(), - roleId: role2.id, - userId: user.id, - }); + await assign(role1.id, user.id); + await assign(role2.id, user.id); metaService.fetch.mockResolvedValue({ policies: { driveCapacityMb: 50,