This commit is contained in:
Kagami Sascha Rosylight 2023-02-11 21:28:55 +01:00
parent 032dc79210
commit 6651fd378a
1 changed files with 47 additions and 47 deletions

View File

@ -102,33 +102,33 @@ describe('RoleService', () => {
}); });
describe('getUserPolicies', () => { describe('getUserPolicies', () => {
test('instance default policies', async () => { test('instance default policies', async () => {
const user = await createUser(); const user = await createUser();
metaService.fetch.mockResolvedValue({ metaService.fetch.mockResolvedValue({
policies: { policies: {
canManageCustomEmojis: false, canManageCustomEmojis: false,
}, },
} as any); } as any);
const result = await roleService.getUserPolicies(user.id); const result = await roleService.getUserPolicies(user.id);
expect(result.canManageCustomEmojis).toBe(false); expect(result.canManageCustomEmojis).toBe(false);
}); });
test('instance default policies 2', async () => { test('instance default policies 2', async () => {
const user = await createUser(); const user = await createUser();
metaService.fetch.mockResolvedValue({ metaService.fetch.mockResolvedValue({
policies: { policies: {
canManageCustomEmojis: true, canManageCustomEmojis: true,
}, },
} as any); } as any);
const result = await roleService.getUserPolicies(user.id); const result = await roleService.getUserPolicies(user.id);
expect(result.canManageCustomEmojis).toBe(true); expect(result.canManageCustomEmojis).toBe(true);
}); });
test('with role', async () => { test('with role', async () => {
const user = await createUser(); const user = await createUser();
const role = await createRole({ const role = await createRole({
name: 'a', name: 'a',
@ -146,48 +146,48 @@ describe('RoleService', () => {
canManageCustomEmojis: false, canManageCustomEmojis: false,
}, },
} as any); } as any);
const result = await roleService.getUserPolicies(user.id); const result = await roleService.getUserPolicies(user.id);
expect(result.canManageCustomEmojis).toBe(true); expect(result.canManageCustomEmojis).toBe(true);
}); });
// test('priority', async () => { test('priority', async () => {
// const user = await createUser(); const user = await createUser();
// const role1 = await createRole({ const role1 = await createRole({
// name: 'role1', name: 'role1',
// policies: { policies: {
// driveCapacityMb: { driveCapacityMb: {
// useDefault: false, useDefault: false,
// priority: 0, priority: 0,
// value: 200, value: 200,
// }, },
// }, },
// }); });
// const role2 = await createRole({ const role2 = await createRole({
// name: 'role2', name: 'role2',
// policies: { policies: {
// driveCapacityMb: { driveCapacityMb: {
// useDefault: false, useDefault: false,
// priority: 1, priority: 1,
// value: 100, value: 100,
// }, },
// }, },
// }); });
// await assign(role1.id, user.id); await assign(role1.id, user.id);
// await assign(role2.id, user.id); await assign(role2.id, user.id);
// metaService.fetch.mockResolvedValue({ metaService.fetch.mockResolvedValue({
// policies: { policies: {
// driveCapacityMb: 50, driveCapacityMb: 50,
// }, },
// } as any); } as any);
const result = await roleService.getUserPolicies(user.id);
expect(result.driveCapacityMb).toBe(100);
});
// const result = await roleService.getUserPolicies(user.id); test('conditional role', async () => {
// expect(result.driveCapacityMb).toBe(100);
// });
test('conditional role', async () => {
const user1 = await createUser({ const user1 = await createUser({
createdAt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 365)), createdAt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 365)),
}); });
@ -222,7 +222,7 @@ describe('RoleService', () => {
canManageCustomEmojis: false, canManageCustomEmojis: false,
}, },
} as any); } as any);
const user1Policies = await roleService.getUserPolicies(user1.id); const user1Policies = await roleService.getUserPolicies(user1.id);
const user2Policies = await roleService.getUserPolicies(user2.id); const user2Policies = await roleService.getUserPolicies(user2.id);
expect(user1Policies.canManageCustomEmojis).toBe(false); expect(user1Policies.canManageCustomEmojis).toBe(false);