2022-07-25 06:25:10 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
2022-07-25 06:25:46 +00:00
|
|
|
describe('Notification Clean()', () => {
|
2022-07-25 06:25:10 +00:00
|
|
|
it('should delete old rows with error', async() => {
|
|
|
|
const userId = 9;
|
|
|
|
const status = 'error';
|
|
|
|
const tx = await models.NotificationQueue.beginTransaction({});
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
const notification = await models.Notification.findOne({}, options);
|
|
|
|
const notificationConfig = await models.NotificationConfig.findOne({});
|
|
|
|
|
2023-01-16 14:18:24 +00:00
|
|
|
const cleanDate = Date.vnNew();
|
2022-07-25 06:25:10 +00:00
|
|
|
cleanDate.setDate(cleanDate.getDate() - (notificationConfig.cleanDays + 1));
|
|
|
|
|
|
|
|
let before;
|
|
|
|
let after;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const notificationDelete = await models.NotificationQueue.create({
|
|
|
|
notificationFk: notification.name,
|
|
|
|
authorFk: userId,
|
|
|
|
status: status,
|
|
|
|
created: cleanDate
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
before = await models.NotificationQueue.findById(notificationDelete.id, null, options);
|
|
|
|
|
|
|
|
await models.Notification.clean(options);
|
|
|
|
|
|
|
|
after = await models.NotificationQueue.findById(notificationDelete.id, null, options);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(before.notificationFk).toEqual(notification.name);
|
|
|
|
expect(after).toBe(null);
|
|
|
|
});
|
|
|
|
});
|