2023-03-08 11:16:53 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
|
|
|
describe('workerTimeControl getMailStates()', () => {
|
2024-06-13 11:43:28 +00:00
|
|
|
const developerId = 9;
|
|
|
|
const developerBossId = 120;
|
|
|
|
const employeeId = 1;
|
2023-03-08 11:16:53 +00:00
|
|
|
|
2024-06-13 11:43:28 +00:00
|
|
|
let ctx;
|
|
|
|
let tx;
|
|
|
|
let opts;
|
2023-03-08 11:16:53 +00:00
|
|
|
|
2024-06-13 11:43:28 +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
|
|
|
|
2024-06-13 11:43:28 +00:00
|
|
|
afterEach(async() => await tx.rollback());
|
2023-03-08 11:16:53 +00:00
|
|
|
|
2024-06-13 11:43:28 +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
|
|
|
|
2024-06-13 11:43:28 +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) {
|
2024-06-13 11:43:28 +00:00
|
|
|
expect(e.message).toEqual('You don\'t have enough privileges');
|
2023-03-08 11:16:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|