2019-11-18 10:00:09 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
|
|
|
|
|
|
|
describe('workerTimeControl addTimeEntry()', () => {
|
2019-11-21 08:19:03 +00:00
|
|
|
let timeEntry;
|
|
|
|
let createdTimeEntry;
|
2019-11-18 10:00:09 +00:00
|
|
|
|
|
|
|
it('should fail to add a time entry if the target user is not a subordinate', async() => {
|
|
|
|
let error;
|
|
|
|
let ctx = {req: {accessToken: {userId: 1}}};
|
|
|
|
let data = {
|
|
|
|
workerFk: 2,
|
|
|
|
timed: new Date()
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.WorkerTimeControl.addTimeEntry(ctx, data);
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
expect(error.statusCode).toBe(400);
|
|
|
|
expect(error.message).toBe(`You don't have enough privileges`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail to add if the current and the target user are the same and is not team boss', async() => {
|
|
|
|
let error;
|
|
|
|
let ctx = {req: {accessToken: {userId: 1}}};
|
|
|
|
let data = {
|
|
|
|
workerFk: 1,
|
|
|
|
timed: new Date()
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.WorkerTimeControl.addTimeEntry(ctx, data);
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
expect(error.statusCode).toBe(400);
|
|
|
|
expect(error.message).toBe(`You don't have enough privileges`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add if the current user is team boss and the target user is a subordinate', async() => {
|
|
|
|
todayAtSix = new Date();
|
|
|
|
todayAtSix.setHours(18, 30, 0, 0);
|
|
|
|
|
|
|
|
let teamBossId = 13;
|
|
|
|
let ctx = {req: {accessToken: {userId: teamBossId}}};
|
|
|
|
let data = {
|
|
|
|
workerFk: teamBossId,
|
|
|
|
timed: todayAtSix
|
|
|
|
};
|
|
|
|
|
2019-11-21 08:19:03 +00:00
|
|
|
timeEntry = await app.models.WorkerTimeControl.addTimeEntry(ctx, data);
|
2019-11-18 10:00:09 +00:00
|
|
|
|
2019-11-21 08:19:03 +00:00
|
|
|
createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id);
|
2019-11-18 10:00:09 +00:00
|
|
|
|
|
|
|
expect(createdTimeEntry).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should try but fail to delete the created time entry for the team boss as team boss', async() => {
|
|
|
|
let error;
|
|
|
|
let teamBossId = 13;
|
|
|
|
let ctx = {req: {accessToken: {userId: teamBossId}}};
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id);
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
expect(error.statusCode).toBe(400);
|
|
|
|
expect(error.message).toBe(`You don't have enough privileges`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should delete the created time entry for the team boss as HHRR', async() => {
|
|
|
|
let HHRRId = 37;
|
|
|
|
let ctx = {req: {accessToken: {userId: HHRRId}}};
|
|
|
|
|
|
|
|
expect(createdTimeEntry).toBeDefined();
|
|
|
|
|
|
|
|
ctx.req.accessToken.userId = HHRRId;
|
2019-11-21 08:19:03 +00:00
|
|
|
await app.models.WorkerTimeControl.deleteTimeEntry(ctx, timeEntry.id);
|
2019-11-18 10:00:09 +00:00
|
|
|
|
2019-11-21 08:19:03 +00:00
|
|
|
createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id);
|
2019-11-18 10:00:09 +00:00
|
|
|
|
|
|
|
expect(createdTimeEntry).toBeNull();
|
|
|
|
});
|
|
|
|
});
|