2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2019-04-05 05:52:08 +00:00
|
|
|
|
|
|
|
describe('claimBeginning', () => {
|
2018-10-10 07:59:42 +00:00
|
|
|
let ticket;
|
2018-10-03 13:46:57 +00:00
|
|
|
let refundTicketObservations;
|
|
|
|
let refundTicketSales;
|
|
|
|
let salesInsertedInClaimEnd;
|
|
|
|
|
2019-03-01 10:50:26 +00:00
|
|
|
afterAll(async() => {
|
2018-10-03 13:46:57 +00:00
|
|
|
let promises = [];
|
2018-10-10 07:59:42 +00:00
|
|
|
promises.push(app.models.Ticket.destroyById(ticket.id));
|
2018-10-03 13:46:57 +00:00
|
|
|
|
2018-10-10 07:59:42 +00:00
|
|
|
promises.push(app.models.Ticket.rawSql(`DELETE FROM vn.orderTicket WHERE ticketFk ='${ticket.id}';`));
|
2018-10-03 13:46:57 +00:00
|
|
|
|
|
|
|
await Promise.all(promises);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('importToNewRefundTicket()', () => {
|
2019-03-01 10:50:26 +00:00
|
|
|
it('should create a new ticket with negative sales, save an observation, update the state and insert the negative sales into claimEnd', async() => {
|
2018-10-03 13:46:57 +00:00
|
|
|
let ctxOfSalesAssistant = {req: {accessToken: {userId: 21}}};
|
|
|
|
let claimId = 1;
|
2018-10-10 07:59:42 +00:00
|
|
|
ticket = await app.models.ClaimBeginning.importToNewRefundTicket(ctxOfSalesAssistant, claimId);
|
|
|
|
|
|
|
|
await app.models.Ticket.findById(ticket.id);
|
|
|
|
|
|
|
|
refundTicketSales = await app.models.Sale.find({where: {ticketFk: ticket.id}});
|
|
|
|
refundTicketObservations = await app.models.TicketObservation.find({where: {ticketFk: ticket.id}});
|
|
|
|
let refundTicketState = await app.models.TicketState.findById(ticket.id);
|
2018-10-03 13:46:57 +00:00
|
|
|
salesInsertedInClaimEnd = await app.models.ClaimEnd.find({where: {claimFk: claimId}});
|
|
|
|
|
|
|
|
expect(refundTicketSales.length).toEqual(2);
|
|
|
|
expect(refundTicketSales[0].quantity).toEqual(-5);
|
|
|
|
expect(refundTicketSales[1].quantity).toEqual(-4);
|
|
|
|
expect(refundTicketObservations[0].description).toEqual('Reclama ticket: 11');
|
|
|
|
expect(refundTicketState.stateFk).toEqual(16);
|
|
|
|
expect(salesInsertedInClaimEnd[0].saleFk).toEqual(refundTicketSales[0].id);
|
|
|
|
expect(salesInsertedInClaimEnd[1].saleFk).toEqual(refundTicketSales[1].id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|