refs #4797 fix back test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-05-02 09:51:04 +02:00
parent c2de5c5ff4
commit 70c46efe27
1 changed files with 9 additions and 14 deletions

View File

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