const models = require('vn-loopback/server/server').models; describe('loopback model NotificationSubscription', () => { it('Should fail to delete a notification if the user is not editing itself or a subordinate', async() => { const tx = await models.NotificationSubscription.beginTransaction({}); try { const options = {transaction: tx}; const user = 9; const notificationSubscriptionId = 2; const ctx = {req: {accessToken: {userId: user}}}; const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); let error; try { await models.NotificationSubscription.deleteNotification(ctx, notification.id, options); } catch (e) { error = e; } expect(error.message).toContain('You dont have permission to modify this user'); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } }); it('Should delete a notification if the user is editing itself', async() => { const tx = await models.NotificationSubscription.beginTransaction({}); try { const options = {transaction: tx}; const user = 9; const notificationSubscriptionId = 4; 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(); } catch (e) { await tx.rollback(); throw e; } }); it('Should delete a notification if the user is editing a subordinate', async() => { const tx = await models.NotificationSubscription.beginTransaction({}); try { const options = {transaction: tx}; const user = 9; const notificationSubscriptionId = 5; 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(); } catch (e) { await tx.rollback(); throw e; } }); });