399 lines
12 KiB
JavaScript
399 lines
12 KiB
JavaScript
|
const app = require('vn-loopback/server/server');
|
||
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||
|
|
||
|
fdescribe('worker workerTimeControl_check()', () => {
|
||
|
it('should throw an error if the worker does not belong to this department', async() => {
|
||
|
let stmts = [];
|
||
|
let stmt;
|
||
|
const workerId = 110;
|
||
|
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.');
|
||
|
});
|
||
|
|
||
|
it('should EL TRABAJDOR ESTA EN EL DEPARTAMENTO Y TABLET CORRECTO', async() => {
|
||
|
let stmts = [];
|
||
|
let stmt;
|
||
|
const workerId = 110;
|
||
|
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();
|
||
|
});
|
||
|
|
||
|
it('should throw an error if the worker NO HA CUMPLIDO EL DESCANSO DE 9h', async() => {
|
||
|
const workerIdBreak9Hours = 110;
|
||
|
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)
|
||
|
VALUES
|
||
|
(?,TIMESTAMPADD(HOUR,-17,NOW()),0,"in"),
|
||
|
(?,TIMESTAMPADD(SECOND,-32399,NOW()),0,"out")`, [
|
||
|
workerIdBreak9Hours,
|
||
|
workerIdBreak9Hours
|
||
|
]);
|
||
|
stmts.push(stmt);
|
||
|
|
||
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||
|
workerIdBreak9Hours,
|
||
|
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');
|
||
|
});
|
||
|
|
||
|
it('should throw an error if the worker HA CUMPLIDO EL DESCANSO de 9h', async() => {
|
||
|
const workerIdBreak9Hours = 110;
|
||
|
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")`, [
|
||
|
workerIdBreak9Hours,
|
||
|
workerIdBreak9Hours
|
||
|
]);
|
||
|
stmts.push(stmt);
|
||
|
|
||
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||
|
workerIdBreak9Hours,
|
||
|
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();
|
||
|
});
|
||
|
|
||
|
it('should throw an error if the worker NO HA CUMPLIDO EL DESCANSO DE 12h', async() => {
|
||
|
const workerIdBreak12Hours = 109;
|
||
|
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)
|
||
|
VALUES
|
||
|
(?,TIMESTAMPADD(HOUR,-20,NOW()),0,"in"),
|
||
|
(?,TIMESTAMPADD(SECOND,-43199,NOW()),0,"out")`, [
|
||
|
workerIdBreak12Hours,
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
stmts.push(stmt);
|
||
|
|
||
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||
|
workerIdBreak12Hours,
|
||
|
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');
|
||
|
});
|
||
|
|
||
|
it('should throw an error if the worker HA CUMPLIDO EL DESCANSO de 12h', async() => {
|
||
|
const workerIdBreak12Hours = 109;
|
||
|
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")`, [
|
||
|
workerIdBreak12Hours,
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
stmts.push(stmt);
|
||
|
|
||
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||
|
workerIdBreak12Hours,
|
||
|
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();
|
||
|
});
|
||
|
|
||
|
it('should throw an error if FICHADAS IMPARES', async() => {
|
||
|
const workerIdBreak12Hours = 109;
|
||
|
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")`, [
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
stmts.push(stmt);
|
||
|
|
||
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||
|
workerIdBreak12Hours,
|
||
|
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');
|
||
|
});
|
||
|
|
||
|
it('should throw an error if ESTA DE VACACIONES', async() => {
|
||
|
const workerIdBreak12Hours = 109;
|
||
|
const tabletId = 1;
|
||
|
let stmts = [];
|
||
|
let stmt;
|
||
|
let err;
|
||
|
|
||
|
stmts.push('START TRANSACTION');
|
||
|
|
||
|
stmt = new ParameterizedSQL(`INSERT INTO postgresql.calendar_employee(business_id,calendar_state_id,date)
|
||
|
VALUES
|
||
|
(?,1,CURDATE())`, [
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
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")`, [
|
||
|
workerIdBreak12Hours,
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
stmts.push(stmt);
|
||
|
|
||
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||
|
workerIdBreak12Hours,
|
||
|
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');
|
||
|
});
|
||
|
|
||
|
it('should throw an error if EL CONTRATO NO ESTA EN VIGOR', async() => {
|
||
|
const workerIdBreak12Hours = 109;
|
||
|
const tabletId = 1;
|
||
|
let stmts = [];
|
||
|
let stmt;
|
||
|
let err;
|
||
|
|
||
|
stmts.push('START TRANSACTION');
|
||
|
|
||
|
stmt = new ParameterizedSQL(`UPDATE postgresql.business SET date_end=DATE_ADD(CURDATE(), INTERVAL -1 DAY) WHERE business_id=?`, [
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
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")`, [
|
||
|
workerIdBreak12Hours,
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
stmts.push(stmt);
|
||
|
|
||
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||
|
workerIdBreak12Hours,
|
||
|
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');
|
||
|
});
|
||
|
|
||
|
it('should throw an error if NO TIENE DESCANSO SEMANAL', async() => {
|
||
|
const workerIdBreak12Hours = 109;
|
||
|
const tabletId = 1;
|
||
|
let stmts = [];
|
||
|
let stmt;
|
||
|
let err;
|
||
|
|
||
|
stmts.push('START TRANSACTION');
|
||
|
|
||
|
stmt = new ParameterizedSQL(`UPDATE postgresql.business SET date_end=DATE_ADD(CURDATE(), INTERVAL -1 DAY) WHERE business_id=?`, [
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
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")`, [
|
||
|
workerIdBreak12Hours,
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
stmts.push(stmt);
|
||
|
|
||
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||
|
workerIdBreak12Hours,
|
||
|
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');
|
||
|
});
|
||
|
|
||
|
it('should DESCANSO 32h', async() => {
|
||
|
const workerIdBreak12Hours = 109;
|
||
|
const tabletId = 1;
|
||
|
let stmts = [];
|
||
|
let stmt;
|
||
|
let err;
|
||
|
|
||
|
stmts.push('START TRANSACTION');
|
||
|
|
||
|
stmt = new ParameterizedSQL(`UPDATE postgresql.business SET date_end=DATE_ADD(CURDATE(), INTERVAL -1 DAY) WHERE business_id=?`, [
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
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")`, [
|
||
|
workerIdBreak12Hours,
|
||
|
workerIdBreak12Hours
|
||
|
]);
|
||
|
stmts.push(stmt);
|
||
|
|
||
|
stmt = new ParameterizedSQL('CALL vn.workerTimeControl_check(?, ?, NULL)', [
|
||
|
workerIdBreak12Hours,
|
||
|
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');
|
||
|
});
|
||
|
});
|