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

125 lines
3.5 KiB
JavaScript
Raw Normal View History

2018-09-19 05:41:07 +00:00
const app = require(`${servicesDir}/claim/server/server`);
2018-09-19 11:18:23 +00:00
describe('Update Claim', () => {
2018-09-19 05:41:07 +00:00
let newDate = new Date();
let newInstance;
let original = {
ticketFk: 3,
clientFk: 101,
ticketCreated: newDate,
workerFk: 18,
claimStateFk: 2,
isChargedToMana: true,
responsibility: 4,
observation: 'observation'
};
beforeAll(async() => {
newInstance = await app.models.Claim.create(original);
});
afterAll(async() => {
await app.models.Claim.destroyById(newInstance.id);
});
it('should throw error if isSaleAssistant is false and try to modify a forbidden field', async() => {
let params = {
id: newInstance.id,
ticketFk: 3,
clientFk: 101,
ticketCreated: newDate,
workerFk: 18,
isChargedToMana: false,
responsibility: 3,
observation: 'another'
};
let ctx = {
req: {
accessToken: {
userId: 18
}
}
};
await app.models.Claim.updateClaim(ctx, params)
.catch(e => {
error = e;
});
expect(error.message).toEqual(`You don't have enough privileges to change that field`);
});
it('should throw error if isSaleAssistant is false and try to modify a valid field but a forbidden stated', async() => {
let params = {
id: newInstance.id,
ticketFk: 3,
clientFk: 101,
ticketCreated: newDate,
workerFk: 18,
claimStateFk: 4,
observation: 'another'
};
let ctx = {
req: {
accessToken: {
userId: 18
}
}
};
await app.models.Claim.updateClaim(ctx, params)
.catch(e => {
error = e;
});
expect(error.message).toEqual(`You don't have enough privileges to change that field`);
});
it('should change field observation', async() => {
let params = {
id: newInstance.id,
ticketCreated: newDate,
observation: 'another3'
};
let ctx = {
req: {
accessToken: {
userId: 18
}
}
};
await app.models.Claim.updateClaim(ctx, params);
let claimUpdated = await app.models.Claim.findById(newInstance.id);
expect(claimUpdated.observation).toEqual(params.observation);
});
it('should change sensible fields as salesAssistant', async() => {
let params = {
id: newInstance.id,
ticketFk: 3,
clientFk: 101,
ticketCreated: newDate,
workerFk: 18,
claimStateFk: 3,
isChargedToMana: true,
responsibility: 3,
observation: 'another'
};
let ctx = {
req: {
accessToken: {
userId: 21
}
}
};
await app.models.Claim.updateClaim(ctx, params);
let claimUpdated = await app.models.Claim.findById(newInstance.id);
expect(claimUpdated.observation).toEqual(params.observation);
expect(claimUpdated.claimStateFk).toEqual(params.claimStateFk);
expect(claimUpdated.responsibility).toEqual(params.responsibility);
expect(claimUpdated.isChargedToMana).toEqual(params.isChargedToMana);
});
});