salix/back/methods/notification/specs/getList.spec.js

32 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-05-09 09:34:32 +00:00
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 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);
});
});