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() {
try {
await axios
.get(`NotificationSubscriptions`, {
params: {
filter: {
include: [
{
relation: 'notification',
},
],
where: {
userFk: entityId.value,
},
},
},
})
.get(`NotificationSubscriptions/${entityId.value}/getList`)
.then(async (res) => {
if (res.data) {
res.data.forEach((subscription) => {
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,
});
}
});
}
});
notifications.value = res.data;
}
});
} catch (e) {
@ -112,14 +38,19 @@ async function fetch() {
}
async function disableNotification(notification) {
await axios.delete(`NotificationSubscriptions/${notification.id}`).then(() => {
notification.id = null;
notification.active = false;
quasar.notify({
type: 'positive',
message: t('worker.notificationsManager.unsubscribed'),
await axios
.delete(`NotificationSubscriptions/${notification.id}`)
.catch(() => (notification.active = true))
.then((res) => {
if (res.data) {
notification.id = null;
notification.active = false;
quasar.notify({
type: 'positive',
message: t('worker.notificationsManager.unsubscribed'),
});
}
});
});
}
async function toggleNotification(notification) {

View File

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