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

124 lines
4.1 KiB
JavaScript
Raw Permalink 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-09 09:34:32 +00:00
it('should fail to add a notification subscription if the worker doesnt have ACLs', 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 {
2023-05-09 09:34:32 +00:00
const options = {transaction: tx, accessToken: {userId: 9}};
await models.NotificationSubscription.create({notificationFk: 1, userFk: 62}, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
2023-01-24 09:11:16 +00:00
2023-05-09 09:34:32 +00:00
expect(error.message).toEqual('The notification subscription of this worker cant be modified');
});
it('should fail to add a notification subscription if the user isnt editing itself or subordinate', async() => {
const tx = await models.NotificationSubscription.beginTransaction({});
let error;
try {
const options = {transaction: tx, accessToken: {userId: 1}};
await models.NotificationSubscription.create({notificationFk: 1, userFk: 9}, options);
2023-01-24 09:11:16 +00:00
await tx.rollback();
} catch (e) {
2023-05-09 09:34:32 +00:00
await tx.rollback();
2023-05-02 07:51:04 +00:00
error = e;
2023-05-09 09:34:32 +00:00
}
expect(error.message).toEqual('The notification subscription of this worker cant be modified');
});
it('should fail to delete a notification subscription if the user isnt editing itself or subordinate', async() => {
const tx = await models.NotificationSubscription.beginTransaction({});
let error;
try {
const options = {transaction: tx, accessToken: {userId: 9}};
await models.NotificationSubscription.destroyAll({id: 2}, options);
2023-05-09 09:34:32 +00:00
await tx.rollback();
} catch (e) {
2023-01-24 09:11:16 +00:00
await tx.rollback();
2023-05-09 09:34:32 +00:00
error = e;
2023-01-24 09:11:16 +00:00
}
2023-05-09 09:34:32 +00:00
expect(error.message).toEqual('The notification subscription of this worker cant be modified');
2023-01-24 09:11:16 +00:00
});
2023-05-09 09:34:32 +00:00
it('should add a notification subscription if the user is editing itself', async() => {
2023-01-24 09:11:16 +00:00
const tx = await models.NotificationSubscription.beginTransaction({});
2023-05-09 09:34:32 +00:00
let error;
2023-01-18 11:16:47 +00:00
try {
2023-05-09 09:34:32 +00:00
const options = {transaction: tx, accessToken: {userId: 9}};
await models.NotificationSubscription.create({notificationFk: 2, userFk: 9}, options);
2023-01-24 09:11:16 +00:00
2023-05-09 09:34:32 +00:00
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
2023-01-24 09:11:16 +00:00
2023-05-09 09:34:32 +00:00
expect(error).toBeUndefined();
});
it('should delete a notification subscription if the user is editing itself', async() => {
const tx = await models.NotificationSubscription.beginTransaction({});
let error;
try {
const options = {transaction: tx, accessToken: {userId: 9}};
await models.NotificationSubscription.destroyAll({id: 6}, options);
2023-01-24 09:11:16 +00:00
await tx.rollback();
2023-01-18 11:16:47 +00:00
} catch (e) {
2023-01-24 09:11:16 +00:00
await tx.rollback();
2023-05-09 09:34:32 +00:00
error = e;
2023-01-18 11:16:47 +00:00
}
2023-05-09 09:34:32 +00:00
expect(error).toBeUndefined();
2023-01-24 09:11:16 +00:00
});
2023-05-09 09:34:32 +00:00
it('should add a notification subscription if the user is editing a subordinate', async() => {
2023-01-24 09:11:16 +00:00
const tx = await models.NotificationSubscription.beginTransaction({});
2023-05-09 09:34:32 +00:00
let error;
2023-01-24 09:11:16 +00:00
try {
2023-05-09 09:34:32 +00:00
const options = {transaction: tx, accessToken: {userId: 9}};
await models.NotificationSubscription.create({notificationFk: 1, userFk: 5}, options);
2023-01-18 11:16:47 +00:00
2023-05-09 09:34:32 +00:00
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
2023-01-24 09:11:16 +00:00
2023-05-09 09:34:32 +00:00
expect(error).toBeUndefined();
});
it('should delete a notification subscription if the user is editing a subordinate', async() => {
const tx = await models.NotificationSubscription.beginTransaction({});
let error;
try {
const options = {transaction: tx, accessToken: {userId: 19}};
await models.NotificationSubscription.destroyAll({id: 4}, options);
2023-01-24 09:11:16 +00:00
await tx.rollback();
} catch (e) {
await tx.rollback();
2023-05-09 09:34:32 +00:00
error = e;
2023-01-24 09:11:16 +00:00
}
2023-05-09 09:34:32 +00:00
expect(error).toBeUndefined();
2023-01-18 11:16:47 +00:00
});
});