refs #6274 tests created
This commit is contained in:
parent
25006a938b
commit
968dc65231
|
@ -43,13 +43,9 @@ module.exports = Self => {
|
||||||
const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE');
|
const isTeamBoss = await models.ACL.checkAccessAcl(ctx, 'Worker', 'isTeamBoss', 'WRITE');
|
||||||
const isHimself = userId == workerId;
|
const isHimself = userId == workerId;
|
||||||
|
|
||||||
if (!isSubordinate || (isSubordinate && isHimself && !isTeamBoss))
|
if (!isSubordinate || (isHimself && !isTeamBoss))
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
const response = await Self.clockIn(workerId, args.timed, args.direction, myOptions);
|
return await Self.clockIn(workerId, args.timed, args.direction, myOptions);
|
||||||
|
|
||||||
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, workerId, args.timed, myOptions);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@ module.exports = Self => {
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'workerFk',
|
arg: 'workerFk',
|
||||||
type: 'integer',
|
type: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,8 +25,8 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const query = `CALL vn.workerTimeControl_getClockIn(?, CURDATE())`;
|
const query = `CALL vn.workerTimeControl_getClockIn(?, ?)`;
|
||||||
const [result] = await Self.rawSql(query, [workerFk], myOptions);
|
const [result] = await Self.rawSql(query, [workerFk, Date.vnNew()], myOptions);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('resendWeeklyHourEmail', {
|
Self.remoteMethodCtx('resendWeeklyHourEmail', {
|
||||||
description: 'Adds a new hour registry',
|
description: 'Send the records for the week of the date provided',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('workerTimeControl clockIn()', () => {
|
||||||
|
const workerId = 9;
|
||||||
|
const inTime = '2001-01-01T00:00:00.000Z';
|
||||||
|
|
||||||
|
it('should correctly clock in', async() => {
|
||||||
|
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
await models.WorkerTimeControl.clockIn(workerId, inTime, 'in', options);
|
||||||
|
const isClockIn = await models.WorkerTimeControl.findOne({
|
||||||
|
where: {
|
||||||
|
userFk: workerId
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
expect(isClockIn).toBeDefined();
|
||||||
|
expect(isClockIn.direction).toBe('in');
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('workerTimeControl getClockIn()', () => {
|
||||||
|
it('should correctly get the timetable of a worker', async() => {
|
||||||
|
const response = await models.WorkerTimeControl.getClockIn(1106, {});
|
||||||
|
|
||||||
|
expect(response.length).toEqual(4);
|
||||||
|
const [inHrs, middleOutHrs, middleInHrs, outHrs] = response;
|
||||||
|
|
||||||
|
expect(inHrs['0daysAgo']).toEqual('07:00');
|
||||||
|
expect(middleOutHrs['0daysAgo']).toEqual('10:00');
|
||||||
|
expect(middleInHrs['0daysAgo']).toEqual('10:20');
|
||||||
|
expect(outHrs['0daysAgo']).toEqual('14:50');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('workerTimeControl login()', () => {
|
||||||
|
it('should correctly login', async() => {
|
||||||
|
const response = await models.WorkerTimeControl.login(9, {});
|
||||||
|
|
||||||
|
expect(response.name).toBe('developer');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw UserError if pin is not provided', async() => {
|
||||||
|
try {
|
||||||
|
await models.WorkerTimeControl.login();
|
||||||
|
} catch (error) {
|
||||||
|
expect(error).toBeInstanceOf(UserError);
|
||||||
|
expect(error.message).toBe('Indique el pin.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue