salix/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.spe...

45 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-01-24 08:08:28 +00:00
const app = require('vn-loopback/server/server');
2020-10-08 14:00:19 +00:00
const LoopBackContext = require('loopback-context');
const models = app.models;
2019-11-18 11:32:50 +00:00
describe('claimBeginning', () => {
const claimManagerId = 72;
2020-10-08 14:00:19 +00:00
const activeCtx = {
accessToken: {userId: claimManagerId},
2024-05-28 10:19:54 +00:00
__: value => value
2020-10-08 14:00:19 +00:00
};
const ctx = {req: activeCtx};
2018-10-03 13:46:57 +00:00
describe('importToNewRefundTicket()', () => {
it('should create a new ticket with negative sales and insert the negative sales into claimEnd', async() => {
2020-10-08 14:00:19 +00:00
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
2018-10-03 13:46:57 +00:00
let claimId = 1;
2018-10-10 07:59:42 +00:00
const tx = await models.Entry.beginTransaction({});
try {
const options = {transaction: tx};
const ticket = await models.ClaimBeginning.importToNewRefundTicket(ctx, claimId, options);
const refundTicketSales = await models.Sale.find({
where: {ticketFk: ticket.id}
}, options);
const salesInsertedInClaimEnd = await models.ClaimEnd.find({
where: {claimFk: claimId}
}, options);
expect(refundTicketSales.length).toEqual(1);
expect(refundTicketSales[0].quantity).toEqual(-5);
expect(salesInsertedInClaimEnd[0].saleFk).toEqual(refundTicketSales[0].id);
2018-10-03 13:46:57 +00:00
await tx.rollback();
} catch (e) {
await tx.rollback();
2021-03-22 09:20:04 +00:00
throw e;
}
2018-10-03 13:46:57 +00:00
});
});
});