salix/modules/worker/back/methods/worker-time-control/specs/getMailStates.spec.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-03-08 11:16:53 +00:00
const models = require('vn-loopback/server/server').models;
describe('workerTimeControl getMailStates()', () => {
const developerId = 9;
const developerBossId = 120;
const employeeId = 1;
2023-03-08 11:16:53 +00:00
let ctx;
let tx;
let opts;
2023-03-08 11:16:53 +00:00
beforeEach(async() => {
ctx = {req: {accessToken: {userId: developerBossId}}, args: {month: 12, year: 2000}};
tx = await models.WorkerTimeControl.beginTransaction({});
opts = {transaction: tx};
});
2023-03-08 11:16:53 +00:00
afterEach(async() => await tx.rollback());
2023-03-08 11:16:53 +00:00
it('should get the states of a month about time control mail', async() => {
const response = await models.WorkerTimeControl.getMailStates(ctx, developerId, opts);
2023-03-08 11:16:53 +00:00
expect(response[0].state).toEqual('REVISE');
expect(response[1].state).toEqual('SENDED');
expect(response[2].state).toEqual('CONFIRMED');
});
it('should throw an error if they are not subordinates', async() => {
ctx.req.accessToken.userId = employeeId;
try {
await models.WorkerTimeControl.getMailStates(ctx, developerId, opts);
2023-03-08 11:16:53 +00:00
} catch (e) {
expect(e.message).toEqual('You don\'t have enough privileges');
2023-03-08 11:16:53 +00:00
}
});
});