2021-10-07 07:57:07 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2019-08-08 06:33:27 +00:00
|
|
|
|
|
|
|
describe('ticket editableStates()', () => {
|
2020-03-26 11:00:07 +00:00
|
|
|
const filter = {where: {name: {like: '%%'}}};
|
2019-08-12 10:31:31 +00:00
|
|
|
it('should return the expected state for the given role', async() => {
|
2021-10-07 07:57:07 +00:00
|
|
|
const tx = await models.State.beginTransaction({});
|
2020-03-26 11:00:07 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2019-08-08 06:33:27 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-08-08 06:33:27 +00:00
|
|
|
});
|
|
|
|
|
2023-05-18 07:30:21 +00:00
|
|
|
it(`should return again the expected state by a specific role`, async() => {
|
2021-10-07 07:57:07 +00:00
|
|
|
const tx = await models.State.beginTransaction({});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
2023-05-18 07:30:21 +00:00
|
|
|
const employeeRole = 1;
|
|
|
|
const ctx = {req: {accessToken: {userId: employeeRole}}};
|
2021-10-07 07:57:07 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2019-08-08 06:33:27 +00:00
|
|
|
});
|
|
|
|
|
2023-05-18 07:30:21 +00:00
|
|
|
it(`should return the expected state matching with the name`, async() => {
|
2021-10-07 07:57:07 +00:00
|
|
|
const tx = await models.State.beginTransaction({});
|
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
const employeeRole = 1;
|
|
|
|
const ctx = {req: {accessToken: {userId: employeeRole}}};
|
2023-05-18 07:30:21 +00:00
|
|
|
const filter = {where: {name: {like: '%Previa OK%'}}};
|
2021-10-07 07:57:07 +00:00
|
|
|
|
2023-05-18 07:30:21 +00:00
|
|
|
const [editableStates] = await models.State.editableStates(ctx, filter, options);
|
2021-10-07 07:57:07 +00:00
|
|
|
|
2023-05-18 07:30:21 +00:00
|
|
|
expect(editableStates.name).toBe('Previa OK');
|
2019-08-08 06:33:27 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2019-08-08 06:33:27 +00:00
|
|
|
});
|
|
|
|
});
|