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');
|
2021-03-19 18:20:19 +00:00
|
|
|
const models = app.models;
|
2019-11-18 11:32:50 +00:00
|
|
|
|
|
|
|
describe('claimBeginning', () => {
|
2020-10-26 11:16:57 +00:00
|
|
|
const claimManagerId = 72;
|
2020-10-08 14:00:19 +00:00
|
|
|
const activeCtx = {
|
2020-10-26 11:16:57 +00:00
|
|
|
accessToken: {userId: claimManagerId},
|
2020-10-08 14:00:19 +00:00
|
|
|
};
|
|
|
|
const ctx = {req: activeCtx};
|
|
|
|
|
2018-10-03 13:46:57 +00:00
|
|
|
describe('importToNewRefundTicket()', () => {
|
2019-09-04 11:39:01 +00:00
|
|
|
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
|
|
|
|
2021-03-19 18:20:19 +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
|
|
|
|
2021-03-19 18:20:19 +00:00
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
}
|
2018-10-03 13:46:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|