From 2cc98226cac2e0a08332e1ce281ba8917c5b58fc Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 2 Feb 2023 18:06:23 +0900 Subject: [PATCH] improve RoleService test --- packages/backend/test/unit/RoleService.ts | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/packages/backend/test/unit/RoleService.ts b/packages/backend/test/unit/RoleService.ts index 8229bf78df..fdfafdb839 100644 --- a/packages/backend/test/unit/RoleService.ts +++ b/packages/backend/test/unit/RoleService.ts @@ -148,6 +148,51 @@ describe('RoleService', () => { expect(result.canManageCustomEmojis).toBe(true); }); + it('priority', async () => { + const user = await createUser(); + const role1 = await createRole({ + name: 'role1', + policies: { + driveCapacityMb: { + useDefault: false, + priority: 0, + value: 200, + }, + }, + }); + const role2 = await createRole({ + name: 'role2', + policies: { + driveCapacityMb: { + useDefault: false, + priority: 1, + value: 100, + }, + }, + }); + 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, + }); + metaService.fetch.mockResolvedValue({ + policies: { + driveCapacityMb: 50, + }, + } as any); + + const result = await roleService.getUserPolicies(user.id); + + expect(result.driveCapacityMb).toBe(100); + }); + it('conditional role', async () => { const user1 = await createUser({ createdAt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 365)),