This commit is contained in:
parent
21b7050cfd
commit
0db3bc5e26
|
@ -1,120 +0,0 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
|
||||||
|
|
||||||
describe('workerTimeControl sendMail()', () => {
|
|
||||||
const workerId = 18;
|
|
||||||
const activeCtx = {
|
|
||||||
getLocale: () => {
|
|
||||||
return 'en';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const ctx = {req: activeCtx, args: {}};
|
|
||||||
|
|
||||||
it('should fill time control of a worker without records in Journey and with rest', 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);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fill time control of a worker without records in Journey and without rest', 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 worker with records in Journey and with rest', async() => {
|
|
||||||
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', ?);`;
|
|
||||||
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);
|
|
||||||
|
|
||||||
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 worker with records in Journey and without rest', async() => {
|
|
||||||
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, '12:30:00', '14: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);
|
|
||||||
|
|
||||||
expect(`${workerTimeControl[0].timed.getHours()}:${workerTimeControl[0].timed.getMinutes()}`).toEqual('12:30');
|
|
||||||
expect(workerTimeControl[1].timed.getHours()).toEqual(14);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
@ -120,6 +120,13 @@ describe('Component vnWorkerTimeControl', () => {
|
||||||
|
|
||||||
describe('save() ', () => {
|
describe('save() ', () => {
|
||||||
it(`should make a query an then call to the fetchHours() method`, () => {
|
it(`should make a query an then call to the fetchHours() method`, () => {
|
||||||
|
const today = Date.vnNew();
|
||||||
|
|
||||||
|
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
||||||
|
jest.spyOn(controller, 'getMailStates').mockReturnThis();
|
||||||
|
|
||||||
|
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||||
|
controller.date = today;
|
||||||
controller.fetchHours = jest.fn();
|
controller.fetchHours = jest.fn();
|
||||||
controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'};
|
controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'};
|
||||||
controller.$.editEntry = {
|
controller.$.editEntry = {
|
||||||
|
@ -240,7 +247,9 @@ describe('Component vnWorkerTimeControl', () => {
|
||||||
describe('resendEmail() ', () => {
|
describe('resendEmail() ', () => {
|
||||||
it(`should make a query an then call showSuccess method`, () => {
|
it(`should make a query an then call showSuccess method`, () => {
|
||||||
const today = Date.vnNew();
|
const today = Date.vnNew();
|
||||||
|
|
||||||
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
||||||
|
jest.spyOn(controller, 'getMailStates').mockReturnThis();
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
||||||
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||||
|
|
Loading…
Reference in New Issue