232201_dev_to_test #59
|
@ -5,6 +5,7 @@ import WorkerNotificationsManager from 'src/pages/Worker/Card/WorkerNotification
|
||||||
describe('WorkerNotificationsManager', () => {
|
describe('WorkerNotificationsManager', () => {
|
||||||
let vm;
|
let vm;
|
||||||
const entityId = 1110;
|
const entityId = 1110;
|
||||||
|
const roleFk = 1;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
vm = createWrapper(WorkerNotificationsManager, {
|
vm = createWrapper(WorkerNotificationsManager, {
|
||||||
|
@ -19,22 +20,103 @@ describe('WorkerNotificationsManager', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('fetch()', () => {
|
describe('fetch()', () => {
|
||||||
it('should fetch the data', async () => {
|
it('should fetch notification subscriptions and role mappings', async () => {
|
||||||
const subscriptions = [
|
vi.spyOn(axios, 'get')
|
||||||
|
.mockResolvedValueOnce({
|
||||||
|
data: [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
notification: {
|
notification: {
|
||||||
name: 'Mock name',
|
name: 'Name 1',
|
||||||
description: 'Mock description',
|
description: 'Description 1',
|
||||||
},
|
},
|
||||||
notificationFk: 1,
|
notificationFk: 1,
|
||||||
},
|
},
|
||||||
];
|
],
|
||||||
vi.spyOn(axios, 'get').mockResolvedValue({ data: subscriptions });
|
})
|
||||||
|
.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();
|
await vm.fetch();
|
||||||
expect(axios.get).toHaveBeenCalledTimes(3)
|
|
||||||
expect(vm.notifications.length).toEqual(1);
|
expect(axios.get).toHaveBeenCalledWith(`NotificationSubscriptions`, {
|
||||||
expect(vm.notifications[0].active).toBeTruthy();
|
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,
|
||||||
|
notificationFk: 1,
|
||||||
|
name: 'Name 1',
|
||||||
|
description: 'Description 1',
|
||||||
|
active: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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).toBeNull();
|
||||||
expect(vm.notifications[0].id).toBeFalsy();
|
expect(vm.notifications[0].id).toBeFalsy();
|
||||||
|
|
||||||
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({ type: 'positive' })
|
expect.objectContaining({ type: 'positive' })
|
||||||
);
|
);
|
||||||
|
@ -72,10 +153,8 @@ describe('WorkerNotificationsManager', () => {
|
||||||
notificationFk: 1,
|
notificationFk: 1,
|
||||||
userFk: entityId,
|
userFk: entityId,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(vm.notifications[0].id).toBe(1);
|
expect(vm.notifications[0].id).toBe(1);
|
||||||
expect(vm.notifications[0].active).toBeTruthy();
|
expect(vm.notifications[0].active).toBeTruthy();
|
||||||
|
|
||||||
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
||||||
expect.objectContaining({ type: 'positive' })
|
expect.objectContaining({ type: 'positive' })
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue