From 0f7ed5bbfa9c3e0ccff4397d90d85852fb74753a Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 3 Mar 2020 15:14:28 +0100 Subject: [PATCH] get worked hours unit test --- .../back/methods/worker/mySubordinates.js | 1 - .../methods/worker/specs/getWorkedHours.spec.js | 17 +++++++++++++++++ .../worker/back/methods/worker/timeControl.js | 1 - 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 modules/worker/back/methods/worker/specs/getWorkedHours.spec.js diff --git a/modules/worker/back/methods/worker/mySubordinates.js b/modules/worker/back/methods/worker/mySubordinates.js index bf1cd1be8..cf45d3a9d 100644 --- a/modules/worker/back/methods/worker/mySubordinates.js +++ b/modules/worker/back/methods/worker/mySubordinates.js @@ -35,7 +35,6 @@ module.exports = Self => { let sql = ParameterizedSQL.join(stmts, ';'); let result = await conn.executeStmt(sql); - return result[1]; }; }; diff --git a/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js b/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js new file mode 100644 index 000000000..148b8467e --- /dev/null +++ b/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js @@ -0,0 +1,17 @@ +const app = require('vn-loopback/server/server'); + +describe('Worker getWorkedHours()', () => { + it(`should return the expected hours and the worked hours of a given date`, async() => { + const workerID = 106; + let started = new Date(); + started.setHours(0, 0, 0, 0); + + let ended = new Date(); + ended.setHours(0, 0, 0, 0); + + const [result] = await app.models.Worker.getWorkedHours(workerID, started, ended); + + expect(result.expectedHours).toEqual(28800); // 8:00 hours seconds + expect(result.workedHours).toEqual(29400); // 8:10 hours in seconds + }); +}); diff --git a/modules/worker/back/methods/worker/timeControl.js b/modules/worker/back/methods/worker/timeControl.js index bc88197fe..9479ff0a1 100644 --- a/modules/worker/back/methods/worker/timeControl.js +++ b/modules/worker/back/methods/worker/timeControl.js @@ -44,7 +44,6 @@ module.exports = Self => { let sql = ParameterizedSQL.join(stmts, ';'); let result = await conn.executeStmt(sql); - return result[0]; }; };