test(notification_getList): fix
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-11-08 14:57:07 +01:00
parent 0de5bc5109
commit 204323ac69
2 changed files with 8 additions and 24 deletions

View File

@ -2,30 +2,12 @@ const models = require('vn-loopback/server/server').models;
describe('NotificationSubscription getList()', () => {
it('should return a list of available and active notifications of a user', async() => {
const userId = 1109;
const activeNotifications = await models.NotificationSubscription.find({
where: {userFk: userId}
});
const roles = await models.RoleMapping.find({
fields: ['roleId'],
where: {principalId: userId}
});
const availableNotifications = await models.NotificationAcl.find({
where: {
roleFk: {
inq: roles.map(role => {
return role.roleId;
}),
},
}
});
const userId = 9;
const {active, available} = await models.NotificationSubscription.getList(userId);
const notifications = await models.Notification.find({});
const totalAvailable = notifications.length - active.length;
const result = await models.NotificationSubscription.getList(userId);
expect(result.filter(notification => notification.active == true).length)
.toEqual(activeNotifications.length);
expect(result.filter(notification => notification.active == false).length)
.toEqual(availableNotifications.length - activeNotifications.length);
expect(active.length).toEqual(2);
expect(available.length).toEqual(totalAvailable);
});
});

View File

@ -2790,7 +2790,9 @@ INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
(1, 9),
(1, 1),
(2, 1),
(3, 9),
(4, 1),
(5, 9),
(6, 9);
INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`)