salix/services/loopback/common/methods/claim/specs/regularizeClaim.spec.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-10-08 05:31:55 +00:00
const app = require(`${servicesDir}/claim/server/server`);
describe('regularizeClaim()', () => {
const claimFk = 1;
const pendentState = 1;
const resolvedState = 3;
const trashDestination = 2;
const trashAddress = 12;
let claimEnds = [];
let trashTicket;
afterAll(async() => {
let claim = await app.models.Claim.findById(claimFk);
await claim.updateAttributes({claimStateFk: pendentState});
await app.models.Ticket.destroyById(trashTicket.id);
claimEnds.forEach(async line => {
await line.destroy();
});
});
it('should change claim state to resolved', async() => {
let ctx = {req: {accessToken: {userId: 18}}};
let params = {claimFk: claimFk};
claimEnds = await app.models.ClaimEnd.importTicketSales(ctx, {
claimFk: claimFk,
ticketFk: 1
});
claimEnds.forEach(async claimEnd => {
claimEnd.updateAttributes({claimDestinationFk: trashDestination});
});
let claimBefore = await app.models.Claim.findById(params.claimFk);
await app.models.Claim.regularizeClaim(ctx, params);
let claimAfter = await app.models.Claim.findById(params.claimFk);
trashTicket = await app.models.Ticket.findOne({where: {addressFk: 12}});
expect(trashTicket.addressFk).toEqual(trashAddress);
expect(claimBefore.claimStateFk).toEqual(pendentState);
expect(claimAfter.claimStateFk).toEqual(resolvedState);
});
});