78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
const app = require('vn-loopback/server/server');
|
|
|
|
describe('claimstate isEditable()', () => {
|
|
const salesPersonId = 18;
|
|
const claimManagerId = 72;
|
|
it('should return false if the given claim does not exist', async() => {
|
|
const tx = await app.models.Claim.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const ctx = {req: {accessToken: {userId: claimManagerId}}};
|
|
const result = await app.models.ClaimState.isEditable(ctx, 9999, options);
|
|
|
|
expect(result).toEqual(false);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
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};
|
|
|
|
const ctx = {req: {accessToken: {userId: salesPersonId}}};
|
|
const result = await app.models.ClaimState.isEditable(ctx, 3, options);
|
|
|
|
expect(result).toEqual(false);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it('should be able to edit a resolved claim for a claimManager', async() => {
|
|
const tx = await app.models.Claim.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const ctx = {req: {accessToken: {userId: claimManagerId}}};
|
|
const result = await app.models.ClaimState.isEditable(ctx, 3, options);
|
|
|
|
expect(result).toEqual(true);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it('should be able to edit a claim for a claimManager', async() => {
|
|
const tx = await app.models.Claim.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const ctx = {req: {accessToken: {userId: claimManagerId}}};
|
|
const result = await app.models.ClaimState.isEditable(ctx, 7, options);
|
|
|
|
expect(result).toEqual(true);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
});
|