32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
|
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);
|
||
|
});
|
||
|
});
|