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;
|
2020-10-26 11:16:57 +00:00
|
|
|
const claimManagerId = 72;
|
2023-03-06 07:14:26 +00:00
|
|
|
it('should return false if the given state does not exist', async() => {
|
2021-07-05 10:00:49 +00:00
|
|
|
const tx = await app.models.Claim.beginTransaction({});
|
2020-06-16 05:47:46 +00:00
|
|
|
|
2021-07-05 10:00:49 +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);
|
2021-07-05 10:00:49 +00:00
|
|
|
|
|
|
|
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() => {
|
2021-07-05 10:00:49 +00:00
|
|
|
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);
|
2021-07-05 10:00:49 +00:00
|
|
|
|
|
|
|
expect(result).toEqual(false);
|
2020-06-16 05:47:46 +00:00
|
|
|
|
2021-07-05 10:00:49 +00:00
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2020-06-16 05:47:46 +00:00
|
|
|
});
|
|
|
|
|
2020-10-26 11:16:57 +00:00
|
|
|
it('should be able to edit a resolved claim for a claimManager', async() => {
|
2021-07-05 10:00:49 +00:00
|
|
|
const tx = await app.models.Claim.beginTransaction({});
|
2020-06-16 05:47:46 +00:00
|
|
|
|
2021-07-05 10:00:49 +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);
|
2021-07-05 10:00:49 +00:00
|
|
|
|
|
|
|
expect(result).toEqual(true);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2020-06-16 05:47:46 +00:00
|
|
|
});
|
|
|
|
|
2020-10-26 11:16:57 +00:00
|
|
|
it('should be able to edit a claim for a claimManager', async() => {
|
2021-07-05 10:00:49 +00:00
|
|
|
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}}};
|
2024-03-04 13:12:56 +00:00
|
|
|
const result = await app.models.ClaimState.isEditable(ctx, 5, options);
|
2021-07-05 10:00:49 +00:00
|
|
|
|
|
|
|
expect(result).toEqual(true);
|
2020-06-16 05:47:46 +00:00
|
|
|
|
2021-07-05 10:00:49 +00:00
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2020-06-16 05:47:46 +00:00
|
|
|
});
|
|
|
|
});
|