salix/modules/invoiceOut/back/methods/invoiceOut/specs/delete.spec.js

54 lines
1.7 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('invoiceOut delete()', () => {
const invoiceOutId = 2;
const userId = 1106;
const activeCtx = {
accessToken: {userId: userId},
};
it('should check that there is one ticket in the target invoiceOut', async() => {
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
try {
const invoiceOut = await models.InvoiceOut.findById(invoiceOutId, {}, options);
const tickets = await models.Ticket.find({where: {refFk: invoiceOut.ref}}, options);
expect(tickets.length).toEqual(1);
expect(tickets[0].id).toEqual(3);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it(`should delete the target invoiceOut then check the ticket doesn't have a refFk anymore`, async() => {
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
try {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
await models.InvoiceOut.delete(invoiceOutId, options);
const originalTicket = await models.Ticket.findById(3, {}, options);
const deletedInvoiceOut = await models.InvoiceOut.findById(invoiceOutId, {}, options);
expect(deletedInvoiceOut).toBeNull();
expect(originalTicket.refFk).toBeNull();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});