From 6858de83a3969a071f91f72f85b9e169275f2861 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 4 Nov 2022 14:55:47 +0100 Subject: [PATCH] feat: backTest --- .../specs/sendMail.spec.js | 120 +++++++++++++++++- 1 file changed, 117 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js b/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js index 4411fa576..f05432ba2 100644 --- a/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js @@ -13,23 +13,137 @@ fdescribe('workerTimeControl sendMail()', () => { }; - it('should...', async() => { + beforeAll(function() { + originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; + jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; + }); + + it('should fill time control of a worker...', async() => { const tx = await models.WorkerTimeControl.beginTransaction({}); try { const options = {transaction: tx}; + await models.WorkerTimeControl.sendMail(ctx, options); + const workerTimeControl = await models.WorkerTimeControl.find({ where: {userFk: workerId} }, options); - console.log(workerTimeControl); + + expect(workerTimeControl[0].timed.getHours()).toEqual(8); + expect(workerTimeControl[1].timed.getHours()).toEqual(9); + expect(`${workerTimeControl[2].timed.getHours()}:${workerTimeControl[2].timed.getMinutes()}`).toEqual('9:20'); + expect(workerTimeControl[3].timed.getHours()).toEqual(16); + await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } + }); - expect(result[1]).toEqual('text/plain'); + it('should fill time control of a worker2...', async() => { + const workdayOf20Hours = 3; + const tx = await models.WorkerTimeControl.beginTransaction({}); + + try { + const options = {transaction: tx}; + query = `UPDATE business b + SET b.calendarTypeFk = ? + WHERE b.workerFk = ?; `; + await models.WorkerTimeControl.rawSql(query, [workdayOf20Hours, workerId], options); + + await models.WorkerTimeControl.sendMail(ctx, options); + + const workerTimeControl = await models.WorkerTimeControl.find({ + where: {userFk: workerId} + }, options); + + expect(workerTimeControl[0].timed.getHours()).toEqual(8); + expect(workerTimeControl[1].timed.getHours()).toEqual(12); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should fill time control of a worker3...', async() => { + const workdayOf20Hours = 3; + const tx = await models.WorkerTimeControl.beginTransaction({}); + + try { + const options = {transaction: tx}; + query = `INSERT INTO postgresql.journey(journey_id, day_id, start, end, business_id) + VALUES + (1, 1, '09:00:00', '13:00:00', ?), + (2, 1, '14:00:00', '19:00:00', ?), + (3, 2, '12:30:00', '19:00:00', ?);`; + await models.WorkerTimeControl.rawSql(query, [workerId, workerId, workerId], options); + + await models.WorkerTimeControl.sendMail(ctx, options); + + const workerTimeControl = await models.WorkerTimeControl.find({ + where: {userFk: workerId} + }, options); + console.log(workerTimeControl); + + expect(workerTimeControl[0].timed.getHours()).toEqual(9); + expect(workerTimeControl[2].timed.getHours()).toEqual(10); + expect(`${workerTimeControl[3].timed.getHours()}:${workerTimeControl[3].timed.getMinutes()}`).toEqual('10:20'); + expect(workerTimeControl[1].timed.getHours()).toEqual(13); + expect(workerTimeControl[4].timed.getHours()).toEqual(14); + expect(workerTimeControl[5].timed.getHours()).toEqual(19); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should fill time control of a worker4...', async() => { + const workdayOf20Hours = 3; + const tx = await models.WorkerTimeControl.beginTransaction({}); + + try { + const options = {transaction: tx}; + query = `UPDATE business b + SET b.calendarTypeFk = ? + WHERE b.workerFk = ?; `; + await models.WorkerTimeControl.rawSql(query, [workdayOf20Hours, workerId], options); + + query = `INSERT INTO postgresql.journey(journey_id, day_id, start, end, business_id) + VALUES + (1, 1, '09:00:00', '13:00:00', ?), + (2, 1, '14:00:00', '19:00:00', ?), + (3, 2, '12:30:00', '19:00:00', ?);`; + await models.WorkerTimeControl.rawSql(query, [workerId, workerId, workerId], options); + + await models.WorkerTimeControl.sendMail(ctx, options); + + const workerTimeControl = await models.WorkerTimeControl.find({ + where: {userFk: workerId} + }, options); + console.log(workerTimeControl); + + expect(workerTimeControl[0].timed.getHours()).toEqual(9); + expect(workerTimeControl[2].timed.getHours()).toEqual(10); + expect(`${workerTimeControl[3].timed.getHours()}:${workerTimeControl[3].timed.getMinutes()}`).toEqual('10:20'); + expect(workerTimeControl[1].timed.getHours()).toEqual(13); + expect(workerTimeControl[4].timed.getHours()).toEqual(14); + expect(workerTimeControl[5].timed.getHours()).toEqual(19); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + afterAll(function() { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; }); });