74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('ticket editableStates()', () => {
|
|
const filter = {where: {name: {like: '%%'}}};
|
|
it('should return the expected state for the given role', async() => {
|
|
const tx = await models.State.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const productionRole = 49;
|
|
const ctx = {req: {accessToken: {userId: productionRole}}};
|
|
|
|
const editableStates = await models.State.editableStates(ctx, filter, options);
|
|
|
|
const deliveredState = editableStates.some(state => state.code == 'DELIVERED');
|
|
|
|
expect(deliveredState).toBeTruthy();
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it(`should return the expected states by a specific role`, async() => {
|
|
const tx = await models.State.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const productionRole = 18;
|
|
const ctx = {req: {accessToken: {userId: productionRole}}};
|
|
|
|
const editableStates = await models.State.editableStates(ctx, filter, options);
|
|
|
|
const deliveredState = editableStates.some(state => state.code == 'DELIVERED');
|
|
|
|
const pickerDesignedState = editableStates.some(state => state.code == 'PICKER_DESIGNED');
|
|
|
|
expect(deliveredState).toBeFalsy();
|
|
expect(pickerDesignedState).toBeTruthy();
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it(`should return again the expected state by a specific role`, async() => {
|
|
const tx = await models.State.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const employeeRole = 1;
|
|
const ctx = {req: {accessToken: {userId: employeeRole}}};
|
|
|
|
const editableStates = await models.State.editableStates(ctx, filter, options);
|
|
|
|
const pickerDesignedState = editableStates.some(state => state.code == 'PICKER_DESIGNED');
|
|
|
|
expect(pickerDesignedState).toBeTruthy();
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
});
|