forked from verdnatura/salix-front
feat: refs #6598 add more tests
This commit is contained in:
parent
94bf6ff381
commit
12811692eb
|
@ -1,4 +1,4 @@
|
||||||
import { vi, describe, expect, it, beforeAll, afterEach, beforeEach } from 'vitest';
|
import { vi, describe, expect, it, beforeAll, afterAll } from 'vitest';
|
||||||
import { axios, flushPromises } from 'app/test/vitest/helper';
|
import { axios, flushPromises } from 'app/test/vitest/helper';
|
||||||
import { useAcl } from 'src/composables/useAcl';
|
import { useAcl } from 'src/composables/useAcl';
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ describe('useAcl', () => {
|
||||||
permission: 'ALLOW',
|
permission: 'ALLOW',
|
||||||
principalType: 'ROLE',
|
principalType: 'ROLE',
|
||||||
principalId: 'employee',
|
principalId: 'employee',
|
||||||
id: 3,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: 'Worker',
|
model: 'Worker',
|
||||||
|
@ -21,37 +20,69 @@ describe('useAcl', () => {
|
||||||
permission: 'ALLOW',
|
permission: 'ALLOW',
|
||||||
principalType: 'ROLE',
|
principalType: 'ROLE',
|
||||||
principalId: 'employee',
|
principalId: 'employee',
|
||||||
id: 13,
|
},
|
||||||
|
{
|
||||||
|
model: 'Url',
|
||||||
|
property: 'getByUser',
|
||||||
|
accessType: 'READ',
|
||||||
|
permission: 'ALLOW',
|
||||||
|
principalType: 'ROLE',
|
||||||
|
principalId: '$everyone',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: 'TpvTransaction',
|
||||||
|
property: 'start',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
permission: 'ALLOW',
|
||||||
|
principalType: 'ROLE',
|
||||||
|
principalId: '$authenticated',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const expectedAcls = {
|
|
||||||
Address: { '*': { '*': true } },
|
beforeAll(async () => {
|
||||||
Worker: { holidays: { READ: true } },
|
|
||||||
};
|
|
||||||
beforeAll(() => {
|
|
||||||
vi.spyOn(axios, 'get').mockResolvedValue({ data: mockAcls });
|
vi.spyOn(axios, 'get').mockResolvedValue({ data: mockAcls });
|
||||||
vi.spyOn(acl.state, 'setAcls');
|
await acl.fetch();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => await acl.fetch());
|
afterAll(async () => await flushPromises());
|
||||||
|
|
||||||
afterEach(async () => {
|
|
||||||
await flushPromises();
|
|
||||||
acl.state.setAcls([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('fetch', () => {
|
|
||||||
it('should call setUser and setRoles of the state with the expected data', async () => {
|
|
||||||
expect(acl.state.setAcls).toHaveBeenCalledWith(expectedAcls);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('hasAny', () => {
|
describe('hasAny', () => {
|
||||||
it('should return true if a role matched', async () =>
|
it('should return false if no roles matched', async () => {
|
||||||
expect(acl.hasAny('Address', '*', 'WRITE')).toBeTruthy());
|
expect(acl.hasAny('Worker', 'updateAttributes', 'WRITE')).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
it('should return false if no roles matched', async () => {
|
it('should return false if no roles matched', async () => {
|
||||||
expect(acl.hasAny('Worker', '*', 'WRITE')).toBeFalsy();
|
expect(acl.hasAny('Worker', 'holidays', 'READ')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('*', () => {
|
||||||
|
it('should return true if an acl matched', async () => {
|
||||||
|
expect(acl.hasAny('Address', '*', 'WRITE')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if no acls matched', async () => {
|
||||||
|
expect(acl.hasAny('Worker', '*', 'READ')).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('$authenticated', () => {
|
||||||
|
it('should return false if no acls matched', async () => {
|
||||||
|
expect(acl.hasAny('Url', 'getByUser', '*')).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if an acl matched', async () => {
|
||||||
|
expect(acl.hasAny('Url', 'getByUser', 'READ')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('$everyone', () => {
|
||||||
|
it('should return false if no acls matched', async () => {
|
||||||
|
expect(acl.hasAny('TpvTransaction', 'start', 'READ')).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if an acl matched', async () => {
|
||||||
|
expect(acl.hasAny('TpvTransaction', 'start', 'WRITE')).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue