refs #4797 fix unit test

This commit is contained in:
Alexandre Riera 2023-05-09 11:45:15 +02:00
parent 82e805eebf
commit fd456ec559
2 changed files with 18 additions and 160 deletions

View File

@ -26,84 +26,10 @@ const notifications = ref([]);
async function fetch() { async function fetch() {
try { try {
await axios await axios
.get(`NotificationSubscriptions`, { .get(`NotificationSubscriptions/${entityId.value}/getList`)
params: {
filter: {
include: [
{
relation: 'notification',
},
],
where: {
userFk: entityId.value,
},
},
},
})
.then(async (res) => { .then(async (res) => {
if (res.data) { if (res.data) {
res.data.forEach((subscription) => { notifications.value = res.data;
notifications.value.push({
id: subscription.id,
notificationFk: subscription.notificationFk,
name: subscription.notification.name,
description: subscription.notification.description,
active: true,
});
});
}
});
await axios
.get(`RoleMappings`, {
params: {
filter: {
fields: ['roleId'],
where: {
principalId: entityId.value,
},
},
},
})
.then(async (res) => {
if (res.data) {
await axios
.get(`NotificationAcls`, {
params: {
filter: {
include: [
{
relation: 'notification',
},
],
where: {
roleFk: {
inq: res.data.map((role) => {
return role.roleId;
}),
},
},
},
},
})
.then(async (res) => {
if (res.data) {
res.data.forEach((acl) => {
const activeNotif = notifications.value.find(
(notif) =>
notif.notificationFk === acl.notificationFk
);
if (!activeNotif) {
notifications.value.push({
id: null,
notificationFk: acl.notificationFk,
name: acl.notification.name,
description: acl.notification.description,
active: false,
});
}
});
}
});
} }
}); });
} catch (e) { } catch (e) {
@ -112,14 +38,19 @@ async function fetch() {
} }
async function disableNotification(notification) { async function disableNotification(notification) {
await axios.delete(`NotificationSubscriptions/${notification.id}`).then(() => { await axios
notification.id = null; .delete(`NotificationSubscriptions/${notification.id}`)
notification.active = false; .catch(() => (notification.active = true))
quasar.notify({ .then((res) => {
type: 'positive', if (res.data) {
message: t('worker.notificationsManager.unsubscribed'), notification.id = null;
notification.active = false;
quasar.notify({
type: 'positive',
message: t('worker.notificationsManager.unsubscribed'),
});
}
}); });
});
} }
async function toggleNotification(notification) { async function toggleNotification(notification) {

View File

@ -5,7 +5,6 @@ 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, {
@ -26,81 +25,16 @@ describe('WorkerNotificationsManager', () => {
data: [ data: [
{ {
id: 1, id: 1,
notification: { name: 'Name 1',
name: 'Name 1', description: 'Description 1',
description: 'Description 1',
},
notificationFk: 1, notificationFk: 1,
}, active: true
],
})
.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).toHaveBeenCalledWith(`NotificationSubscriptions`, { expect(axios.get).toHaveBeenCalledWith(`NotificationSubscriptions/${entityId}/getList`);
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([ expect(vm.notifications).toEqual([
{ {
id: 1, id: 1,
@ -109,13 +43,6 @@ describe('WorkerNotificationsManager', () => {
description: 'Description 1', description: 'Description 1',
active: true, active: true,
}, },
{
id: null,
notificationFk: 2,
name: 'Name 2',
description: 'Description 2',
active: false,
},
]); ]);
}); });
}); });