This commit is contained in:
parent
d4cc8830d8
commit
82e805eebf
|
@ -5,6 +5,7 @@ import WorkerNotificationsManager from 'src/pages/Worker/Card/WorkerNotification
|
|||
describe('WorkerNotificationsManager', () => {
|
||||
let vm;
|
||||
const entityId = 1110;
|
||||
const roleFk = 1;
|
||||
|
||||
beforeAll(() => {
|
||||
vm = createWrapper(WorkerNotificationsManager, {
|
||||
|
@ -19,22 +20,103 @@ describe('WorkerNotificationsManager', () => {
|
|||
});
|
||||
|
||||
describe('fetch()', () => {
|
||||
it('should fetch the data', async () => {
|
||||
const subscriptions = [
|
||||
it('should fetch notification subscriptions and role mappings', async () => {
|
||||
vi.spyOn(axios, 'get')
|
||||
.mockResolvedValueOnce({
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
notification: {
|
||||
name: 'Name 1',
|
||||
description: 'Description 1',
|
||||
},
|
||||
notificationFk: 1,
|
||||
},
|
||||
],
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
data: [
|
||||
{
|
||||
roleId: roleFk,
|
||||
},
|
||||
],
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
data: [
|
||||
{
|
||||
notification: {
|
||||
name: 'Name 1',
|
||||
description: 'Description 1',
|
||||
},
|
||||
notificationFk: 1,
|
||||
},
|
||||
{
|
||||
notification: {
|
||||
name: 'Name 2',
|
||||
description: 'Description 2',
|
||||
},
|
||||
notificationFk: 2,
|
||||
},
|
||||
],
|
||||
});
|
||||
await vm.fetch();
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith(`NotificationSubscriptions`, {
|
||||
params: {
|
||||
filter: {
|
||||
include: [
|
||||
{
|
||||
relation: 'notification',
|
||||
},
|
||||
],
|
||||
where: {
|
||||
userFk: entityId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(axios.get).toHaveBeenCalledWith(`RoleMappings`, {
|
||||
params: {
|
||||
filter: {
|
||||
fields: ['roleId'],
|
||||
where: {
|
||||
principalId: entityId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(axios.get).toHaveBeenCalledWith(`NotificationAcls`, {
|
||||
params: {
|
||||
filter: {
|
||||
include: [
|
||||
{
|
||||
relation: 'notification',
|
||||
},
|
||||
],
|
||||
where: {
|
||||
roleFk: {
|
||||
inq: [roleFk],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(vm.notifications).toEqual([
|
||||
{
|
||||
id: 1,
|
||||
notification: {
|
||||
name: 'Mock name',
|
||||
description: 'Mock description',
|
||||
},
|
||||
notificationFk: 1,
|
||||
name: 'Name 1',
|
||||
description: 'Description 1',
|
||||
active: true,
|
||||
},
|
||||
];
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({ data: subscriptions });
|
||||
await vm.fetch();
|
||||
expect(axios.get).toHaveBeenCalledTimes(3)
|
||||
expect(vm.notifications.length).toEqual(1);
|
||||
expect(vm.notifications[0].active).toBeTruthy();
|
||||
{
|
||||
id: null,
|
||||
notificationFk: 2,
|
||||
name: 'Name 2',
|
||||
description: 'Description 2',
|
||||
active: false,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -52,7 +134,6 @@ describe('WorkerNotificationsManager', () => {
|
|||
);
|
||||
expect(vm.notifications[0].id).toBeNull();
|
||||
expect(vm.notifications[0].id).toBeFalsy();
|
||||
|
||||
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ type: 'positive' })
|
||||
);
|
||||
|
@ -72,10 +153,8 @@ describe('WorkerNotificationsManager', () => {
|
|||
notificationFk: 1,
|
||||
userFk: entityId,
|
||||
});
|
||||
|
||||
expect(vm.notifications[0].id).toBe(1);
|
||||
expect(vm.notifications[0].active).toBeTruthy();
|
||||
|
||||
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ type: 'positive' })
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue