salix/back/models/specs/notificationSubscription.sp...

70 lines
2.7 KiB
JavaScript
Raw Normal View History

2023-01-24 09:11:16 +00:00
const models = require('vn-loopback/server/server').models;
2023-01-18 11:16:47 +00:00
describe('loopback model NotificationSubscription', () => {
2023-05-02 07:51:04 +00:00
it('should fail to delete a notification if the user is not editing itself or a subordinate', async() => {
2023-01-24 09:11:16 +00:00
const tx = await models.NotificationSubscription.beginTransaction({});
2023-05-02 07:51:04 +00:00
let error;
2023-01-18 11:16:47 +00:00
2023-01-24 09:11:16 +00:00
try {
const options = {transaction: tx};
const user = 9;
const notificationSubscriptionId = 2;
const ctx = {req: {accessToken: {userId: user}}};
const notification = await models.NotificationSubscription.findById(notificationSubscriptionId);
2023-05-02 07:51:04 +00:00
await models.NotificationSubscription.deleteNotification(ctx, notification.id, options);
2023-01-24 09:11:16 +00:00
expect(error.message).toContain('You dont have permission to modify this user');
await tx.rollback();
} catch (e) {
2023-05-02 07:51:04 +00:00
error = e;
2023-01-24 09:11:16 +00:00
await tx.rollback();
}
});
2023-05-02 07:51:04 +00:00
it('should delete a notification if the user is editing itself', async() => {
2023-01-24 09:11:16 +00:00
const tx = await models.NotificationSubscription.beginTransaction({});
2023-01-18 11:16:47 +00:00
try {
2023-01-24 09:11:16 +00:00
const options = {transaction: tx};
const user = 9;
2023-05-02 07:51:04 +00:00
const notificationSubscriptionId = 6;
2023-01-24 09:11:16 +00:00
const ctx = {req: {accessToken: {userId: user}}};
const notification = await models.NotificationSubscription.findById(notificationSubscriptionId);
await models.NotificationSubscription.deleteNotification(ctx, notification.id, options);
const deletedNotification = await models.NotificationSubscription.findById(notificationSubscriptionId);
expect(deletedNotification).toBeNull();
await tx.rollback();
2023-01-18 11:16:47 +00:00
} catch (e) {
2023-01-24 09:11:16 +00:00
await tx.rollback();
throw e;
2023-01-18 11:16:47 +00:00
}
2023-01-24 09:11:16 +00:00
});
2023-05-02 07:51:04 +00:00
it('should delete a notification if the user is editing a subordinate', async() => {
2023-01-24 09:11:16 +00:00
const tx = await models.NotificationSubscription.beginTransaction({});
try {
const options = {transaction: tx};
2023-05-02 07:51:04 +00:00
const user = 19;
const notificationSubscriptionId = 4;
2023-01-24 09:11:16 +00:00
const ctx = {req: {accessToken: {userId: user}}};
const notification = await models.NotificationSubscription.findById(notificationSubscriptionId);
2023-01-18 11:16:47 +00:00
2023-01-24 09:11:16 +00:00
await models.NotificationSubscription.deleteNotification(ctx, notification.id, options);
const deletedNotification = await models.NotificationSubscription.findById(notificationSubscriptionId);
expect(deletedNotification).toBeNull();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
2023-01-18 11:16:47 +00:00
});
});