2020-03-02 07:18:41 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
|
|
|
2020-09-22 11:59:00 +00:00
|
|
|
// #2261 xdescribe dbtest workerTimeControl_check()
|
2020-05-19 12:42:32 +00:00
|
|
|
xdescribe('worker workerTimeControl_check()', () => {
|
2020-03-06 10:47:14 +00:00
|
|
|
it(`should throw an error if the worker can't sign on that tablet`, async() => {
|
2020-03-02 07:18:41 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1110;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 2;
|
|
|
|
let err;
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
try {
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
|
|
|
workerId,
|
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err.sqlMessage).toEqual('No perteneces a este departamento.');
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should check that the worker can sign on that tablet', async() => {
|
2020-03-02 07:18:41 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1110;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let err;
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
try {
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
|
|
|
workerId,
|
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).not.toBeDefined();
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should throw an error if the worker with a special category has not finished the 9h break', async() => {
|
|
|
|
// dayBreak to 9h in postgresql.professional_category
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1110;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
let sql;
|
|
|
|
let error;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
2020-03-05 09:50:07 +00:00
|
|
|
VALUES
|
2020-03-02 07:18:41 +00:00
|
|
|
(?,TIMESTAMPADD(HOUR,-17,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(SECOND,-32399,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-02 07:18:41 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
await app.models.Worker.rawSql('ROLLBACK');
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error.sqlMessage).toEqual('Descansos 9 h');
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should check f the worker with a special category has finished the 9h break', async() => {
|
|
|
|
// dayBreak to 9h in postgresql.professional_category
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1110;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
let err;
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
|
|
|
VALUES
|
|
|
|
(?,TIMESTAMPADD(HOUR,-17,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(SECOND,-32401,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-02 07:18:41 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
await app.models.Worker.rawSql('ROLLBACK');
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).not.toBeDefined();
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should throw an error if the worker has not finished the 12h break', async() => {
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1109;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
let sql;
|
|
|
|
let error;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
2020-03-05 09:50:07 +00:00
|
|
|
VALUES
|
2020-03-02 07:18:41 +00:00
|
|
|
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(SECOND,-43199,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-02 07:18:41 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
await app.models.Worker.rawSql('ROLLBACK');
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error.sqlMessage).toEqual('Descansos 12 h');
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should throw an error if the worker has finished the 12h break', async() => {
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1109;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
let err;
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
|
|
|
VALUES
|
|
|
|
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(SECOND,-43201,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-02 07:18:41 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
await app.models.Worker.rawSql('ROLLBACK');
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err).not.toBeDefined();
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should throw an error if the worker has odd entry records', async() => {
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1109;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
let err;
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
|
|
|
VALUES
|
|
|
|
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-02 07:18:41 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
await app.models.Worker.rawSql('ROLLBACK');
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err.sqlMessage).toEqual('Dias con fichadas impares');
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should throw an error if the worker try to sign on a holiday day', async() => {
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1109;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
let err;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2022-09-19 07:45:28 +00:00
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO postgresql.calendar_employee(businessFk,calendar_state_id,date)
|
2020-03-02 07:18:41 +00:00
|
|
|
VALUES
|
|
|
|
(?,1,CURDATE())`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
|
|
|
VALUES
|
|
|
|
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-02 07:18:41 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
await app.models.Worker.rawSql('ROLLBACK');
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err.sqlMessage).toEqual('Holidays');
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should throw an error if the worker try to sign with your contract ended', async() => {
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1109;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
let err;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2022-09-19 07:45:28 +00:00
|
|
|
stmt = new ParameterizedSQL(`UPDATE vn.business SET ended = DATE_ADD(CURDATE(), INTERVAL -1 DAY) WHERE id = ?`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
|
|
|
VALUES
|
|
|
|
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-02 07:18:41 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
await app.models.Worker.rawSql('ROLLBACK');
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(err.sqlMessage).toEqual('No hay un contrato en vigor');
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should throw an error if the worker has not finished the 36h weekly break', async() => {
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1109;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
2020-03-05 13:06:55 +00:00
|
|
|
stmts.push('SET @warn := NULL');
|
|
|
|
|
2020-03-02 07:18:41 +00:00
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2020-03-05 09:50:07 +00:00
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
|
|
|
VALUES
|
|
|
|
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-16,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-48,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-40,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-72,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-64,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-96,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-88,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-120,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-112,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-144,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-136,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-168,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-160,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-192,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-184,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
2020-03-05 09:50:07 +00:00
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-05 09:50:07 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
let warningMessageIndex = stmts.push('SELECT @warn AS warning') - 1;
|
2020-03-05 13:06:55 +00:00
|
|
|
stmts.push('ROLLBACK');
|
2020-03-05 09:50:07 +00:00
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Worker.rawStmt(sql);
|
|
|
|
|
|
|
|
expect(result[warningMessageIndex][0].warning).toEqual('Descansos 36 h');
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should check if the worker has finished the 36h weekly break', async() => {
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1109;
|
2020-03-05 09:50:07 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
2020-03-05 13:06:55 +00:00
|
|
|
stmts.push('SET @warn := NULL');
|
|
|
|
|
2020-03-05 09:50:07 +00:00
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2020-03-02 07:18:41 +00:00
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
|
|
|
VALUES
|
2020-03-05 09:50:07 +00:00
|
|
|
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-16,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-48,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-40,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-72,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-64,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-96,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-88,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-02 07:18:41 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
2020-03-05 09:50:07 +00:00
|
|
|
let warningMessageIndex = stmts.push('SELECT @warn AS warning') - 1;
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Worker.rawStmt(sql);
|
|
|
|
|
|
|
|
expect(result[warningMessageIndex][0].warning).toBe(null);
|
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should throw an error if the worker has not finished the 72h biweekly break', async() => {
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1109;
|
2020-03-05 09:50:07 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
let err;
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
|
|
|
VALUES
|
|
|
|
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-16,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-48,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-40,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-72,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-64,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-96,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-88,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-120,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-112,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-144,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-136,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-168,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-160,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-192,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-184,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-216,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-208,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-240,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-232,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-264,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-256,NOW()),0,"out"),
|
2020-03-05 14:01:03 +00:00
|
|
|
(?,TIMESTAMPADD(HOUR,-289,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-280,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-05 09:50:07 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-05 09:50:07 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
stmts.push('SELECT @warn AS warning') - 1;
|
|
|
|
|
2020-03-02 07:18:41 +00:00
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
await app.models.Worker.rawSql('ROLLBACK');
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
|
2020-03-05 09:50:07 +00:00
|
|
|
expect(err.sqlMessage).toEqual('Descansos 72 h');
|
2020-03-02 07:18:41 +00:00
|
|
|
});
|
|
|
|
|
2020-03-06 10:47:14 +00:00
|
|
|
it('should check if the worker has finished the 72h biweekly break', async() => {
|
2021-06-23 11:24:23 +00:00
|
|
|
const workerId = 1109;
|
2020-03-02 07:18:41 +00:00
|
|
|
const tabletId = 1;
|
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
let err;
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL(`INSERT INTO vn.workerTimeControl(userFk,timed,manual,direction)
|
|
|
|
VALUES
|
2020-03-05 09:50:07 +00:00
|
|
|
(?,TIMESTAMPADD(HOUR,-24,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-16,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-48,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-40,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-72,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-64,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-96,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-88,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-120,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-112,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-144,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-136,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-168,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-160,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-192,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-184,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-216,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-208,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-240,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-232,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-264,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-256,NOW()),0,"out"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-288,NOW()),0,"in"),
|
|
|
|
(?,TIMESTAMPADD(HOUR,-280,NOW()),0,"out")`, [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId,
|
|
|
|
workerId
|
2020-03-02 07:18:41 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
2020-03-06 10:47:14 +00:00
|
|
|
workerId,
|
2020-03-02 07:18:41 +00:00
|
|
|
tabletId
|
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
2020-03-05 09:50:07 +00:00
|
|
|
stmts.push('SELECT @warn AS warning') - 1;
|
|
|
|
|
2020-03-02 07:18:41 +00:00
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.models.Worker.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
await app.models.Worker.rawSql('ROLLBACK');
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
|
2020-03-05 09:50:07 +00:00
|
|
|
expect(err).not.toBeDefined();
|
2020-03-02 07:18:41 +00:00
|
|
|
});
|
|
|
|
});
|