salix/modules/claim/back/methods/claim-state/specs/isEditable.spec.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-06-16 05:47:46 +00:00
const app = require('vn-loopback/server/server');
2023-02-07 14:40:03 +00:00
describe('claimstate isEditable()', () => {
const salesPersonId = 18;
const claimManagerId = 72;
2023-03-06 07:14:26 +00:00
it('should return false if the given state does not exist', async() => {
const tx = await app.models.Claim.beginTransaction({});
2020-06-16 05:47:46 +00:00
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: claimManagerId}}};
2023-02-07 14:40:03 +00:00
const result = await app.models.ClaimState.isEditable(ctx, 9999, options);
expect(result).toEqual(false);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
2020-06-16 05:47:46 +00:00
});
it('should not be able to edit a resolved claim for a salesPerson', async() => {
const tx = await app.models.Claim.beginTransaction({});
try {
const options = {transaction: tx};
2023-02-07 14:40:03 +00:00
const ctx = {req: {accessToken: {userId: salesPersonId}}};
const result = await app.models.ClaimState.isEditable(ctx, 3, options);
expect(result).toEqual(false);
2020-06-16 05:47:46 +00:00
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
2020-06-16 05:47:46 +00:00
});
it('should be able to edit a resolved claim for a claimManager', async() => {
const tx = await app.models.Claim.beginTransaction({});
2020-06-16 05:47:46 +00:00
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: claimManagerId}}};
2023-02-07 14:40:03 +00:00
const result = await app.models.ClaimState.isEditable(ctx, 3, options);
expect(result).toEqual(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
2020-06-16 05:47:46 +00:00
});
it('should be able to edit a claim for a claimManager', async() => {
const tx = await app.models.Claim.beginTransaction({});
try {
const options = {transaction: tx};
2023-02-07 14:40:03 +00:00
const ctx = {req: {accessToken: {userId: claimManagerId}}};
const result = await app.models.ClaimState.isEditable(ctx, 5, options);
expect(result).toEqual(true);
2020-06-16 05:47:46 +00:00
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
2020-06-16 05:47:46 +00:00
});
});