2018-09-11 10:49:31 +00:00
|
|
|
const app = require(`${servicesDir}/claim/server/server`);
|
|
|
|
|
2018-09-11 11:56:40 +00:00
|
|
|
describe('Claim Create', () => {
|
2018-09-11 10:49:31 +00:00
|
|
|
let newDate = new Date();
|
|
|
|
let createdClaimFk;
|
|
|
|
|
2018-11-06 07:56:06 +00:00
|
|
|
afterAll(async () => {
|
2018-09-11 10:49:31 +00:00
|
|
|
await app.models.Claim.destroyById(createdClaimFk);
|
|
|
|
});
|
|
|
|
|
|
|
|
let newClaim = {
|
|
|
|
ticketFk: 2,
|
|
|
|
clientFk: 101,
|
|
|
|
ticketCreated: newDate,
|
|
|
|
workerFk: 18
|
|
|
|
};
|
|
|
|
|
|
|
|
let newSale = [{
|
2018-09-11 11:56:40 +00:00
|
|
|
id: 3,
|
2018-09-11 10:49:31 +00:00
|
|
|
instance: 0,
|
|
|
|
quantity: 10
|
|
|
|
}];
|
|
|
|
|
|
|
|
let params = {claim: newClaim, sales: newSale};
|
|
|
|
|
2018-11-06 07:56:06 +00:00
|
|
|
it('should create a new claim', async () => {
|
2018-09-11 10:49:31 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2018-11-06 07:56:06 +00:00
|
|
|
it('should not be able to create a claim if exists that sale', async () => {
|
2018-09-11 10:49:31 +00:00
|
|
|
let error;
|
|
|
|
|
|
|
|
await app.models.Claim.createFromSales(params)
|
|
|
|
|
|
|
|
.catch(e => {
|
|
|
|
error = e;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(error.toString()).toContain(`A claim with that sale already exists`);
|
|
|
|
});
|
|
|
|
});
|