refs #4797 unit test refactored
gitea/salix-front/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-05-02 14:01:41 +02:00
parent d4cc8830d8
commit 82e805eebf
1 changed files with 94 additions and 15 deletions

View File

@ -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' })
);