const app = require(`${servicesDir}/claim/server/server`); describe('Claim Create', () => { let newDate = new Date(); let createdClaimFk; afterAll(async () => { await app.models.Claim.destroyById(createdClaimFk); }); let newClaim = { ticketFk: 2, clientFk: 101, ticketCreated: newDate, workerFk: 18 }; let newSale = [{ id: 3, instance: 0, quantity: 10 }]; let params = {claim: newClaim, sales: newSale}; it('should create a new claim', async () => { let claim = await app.models.Claim.createFromSales(params); expect(claim.ticketFk).toEqual(newClaim.ticketFk); expect(claim.clientFk).toEqual(newClaim.clientFk); expect(claim.ticketCreated).toEqual(newClaim.ticketCreated); expect(claim.workerFk).toEqual(newClaim.workerFk); let claimBeginning = await app.models.ClaimBeginning.findOne({where: {claimFk: claim.id}}); expect(claimBeginning.saleFk).toEqual(newSale[0].id); expect(claimBeginning.quantity).toEqual(newSale[0].quantity); createdClaimFk = claim.id; }); it('should not be able to create a claim if exists that sale', async () => { let error; await app.models.Claim.createFromSales(params) .catch(e => { error = e; }); expect(error.toString()).toContain(`A claim with that sale already exists`); }); });