salix/back/methods/notification/specs/send.spec.js

66 lines
1.9 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
describe('Notification Send()', () => {
beforeAll(async() => {
await models.NotificationQueue.destroyAll();
await models.NotificationQueue.create(
[
{
id: 1,
params: '{"id": "1"}',
status: 'pending',
created: '2000-12-31T23:00:00.000Z',
notificationFk: 'print-email',
authorFk: 9
},
{
id: 2,
params: '{"id": "2"}',
status: 'pending',
created: '2000-12-31T23:00:00.000Z',
notificationFk: 'print-email',
authorFk: null
},
{
id: 3,
params: null,
status: 'pending',
created: '2000-12-31T23:00:00.000Z',
notificationFk: 'print-email',
authorFk: null
}
]
);
});
it('should send notification', async() => {
const statusPending = 'pending';
const tx = await models.NotificationQueue.beginTransaction({});
const options = {transaction: tx};
const filter = {
where: {
status: statusPending
}
};
let before;
let after;
try {
before = await models.NotificationQueue.find(filter, options);
await models.Notification.send(options);
after = await models.NotificationQueue.find(filter, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
expect(before.length).toEqual(3);
expect(after.length).toEqual(0);
});
});