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');
|
2019-11-18 11:32:50 +00:00
|
|
|
|
|
|
|
describe('claimBeginning', () => {
|
2020-10-26 11:16:57 +00:00
|
|
|
const claimManagerId = 72;
|
2018-10-10 07:59:42 +00:00
|
|
|
let ticket;
|
2018-10-03 13:46:57 +00:00
|
|
|
let refundTicketSales;
|
|
|
|
let salesInsertedInClaimEnd;
|
|
|
|
|
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};
|
|
|
|
|
2020-10-15 16:57:27 +00:00
|
|
|
afterAll(async done => {
|
|
|
|
try {
|
|
|
|
await app.models.Ticket.destroyById(ticket.id);
|
|
|
|
await app.models.Ticket.rawSql(`DELETE FROM vn.orderTicket WHERE ticketFk ='${ticket.id}';`);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
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;
|
2020-10-08 14:00:19 +00:00
|
|
|
ticket = await app.models.ClaimBeginning.importToNewRefundTicket(ctx, claimId);
|
2018-10-10 07:59:42 +00:00
|
|
|
|
|
|
|
refundTicketSales = await app.models.Sale.find({where: {ticketFk: ticket.id}});
|
2018-10-03 13:46:57 +00:00
|
|
|
salesInsertedInClaimEnd = await app.models.ClaimEnd.find({where: {claimFk: claimId}});
|
|
|
|
|
2019-07-02 12:44:36 +00:00
|
|
|
expect(refundTicketSales.length).toEqual(1);
|
2018-10-03 13:46:57 +00:00
|
|
|
expect(refundTicketSales[0].quantity).toEqual(-5);
|
|
|
|
expect(salesInsertedInClaimEnd[0].saleFk).toEqual(refundTicketSales[0].id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|