refs #4797 @1h requested changes
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
be44e16ffc
commit
c13bffcc57
|
@ -1,22 +1,74 @@
|
||||||
const app = require('vn-loopback/server/server');
|
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 user = 9;
|
const tx = await models.NotificationSubscription.beginTransaction({});
|
||||||
const notificationSubscriptionId = 2;
|
|
||||||
const ctx = {req: {accessToken: {userId: user}}};
|
|
||||||
const models = app.models;
|
|
||||||
const notification = await models.NotificationSubscription.findById(notificationSubscriptionId);
|
|
||||||
|
|
||||||
let error;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await models.NotificationSubscription.deleteNotification(ctx, notification.id);
|
const options = {transaction: tx};
|
||||||
} catch (e) {
|
const user = 9;
|
||||||
error = e;
|
const notificationSubscriptionId = 2;
|
||||||
}
|
const ctx = {req: {accessToken: {userId: user}}};
|
||||||
|
const notification = await models.NotificationSubscription.findById(notificationSubscriptionId);
|
||||||
|
|
||||||
expect(error.message).toContain('You dont have permission to modify this user');
|
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 = 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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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 = 6;
|
||||||
|
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;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
CREATE OR REPLACE TABLE `util`.`notificationSubscription` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`notificationFk` int(11) NOT NULL,
|
||||||
|
`userFk` int(10) unsigned NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `notificationSubscription_ibfk_1` (`notificationFk`),
|
||||||
|
KEY `notificationSubscription_ibfk_2` (`userFk`),
|
||||||
|
CONSTRAINT `notificationSubscription_ibfk_1` FOREIGN KEY (`notificationFk`) REFERENCES `notification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `notificationSubscription_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
@ -2701,7 +2701,10 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 1109),
|
(1, 1109),
|
||||||
(1, 1110),
|
(1, 1110),
|
||||||
(3, 1109);
|
(3, 1109),
|
||||||
|
(1,9),
|
||||||
|
(1,3);
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
|
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
Loading…
Reference in New Issue