#678 Tests importToNewRefundTicket

This commit is contained in:
Carlos Jimenez 2018-10-03 15:46:57 +02:00
parent c1893be92a
commit 57b9f8b359
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
const app = require(`${servicesDir}/claim/server/server`);
describe('claimBeginning', () => {
let ticketId;
let refundTicketObservations;
let refundTicketSales;
let salesInsertedInClaimEnd;
afterAll(async() => {
let promises = [];
promises.push(app.models.Ticket.destroyById(ticketId));
promises.push(app.models.Ticket.rawSql(`DELETE FROM vn.orderTicket WHERE ticketFk ='${ticketId}';`));
await Promise.all(promises);
});
describe('importToNewRefundTicket()', () => {
it('should create a new ticket with negative sales, save an observation, update the state and insert the negative sales into claimEnd', async() => {
let ctxOfSalesAssistant = {req: {accessToken: {userId: 21}}};
let claimId = 1;
ticketId = await app.models.ClaimBeginning.importToNewRefundTicket(ctxOfSalesAssistant, claimId);
await app.models.Ticket.findById(ticketId);
refundTicketSales = await app.models.Sale.find({where: {ticketFk: ticketId}});
refundTicketObservations = await app.models.TicketObservation.find({where: {ticketFk: ticketId}});
let refundTicketState = await app.models.TicketState.findById(ticketId);
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);
});
});
});