fix(test): use static dates
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-04-05 07:46:49 +02:00
parent c904bf0bdf
commit d616367714
14 changed files with 50 additions and 55 deletions

View File

@ -1,3 +1,4 @@
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
baseTime.setHours(8, 0, 0, 0);
jasmine.clock().mockDate(baseTime);

View File

@ -35,7 +35,7 @@ RETURNS DATE
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIME('00:00:00');
RETURN TIME('08:00:00');
ELSE
RETURN CURTIME();
END IF;
@ -49,7 +49,7 @@ RETURNS DATE
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIMESTAMP('2022-01-19 00:00:00');
RETURN TIMESTAMP('2022-01-19 08:00:00');
ELSE
RETURN NOW();
END IF;

View File

@ -41,7 +41,7 @@ RETURNS DATE
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIME('00:00:00');
RETURN TIME('08:00:00');
ELSE
RETURN CURTIME();
END IF;
@ -55,7 +55,7 @@ RETURNS DATE
DETERMINISTIC
BEGIN
IF(SELECT vn.getEnvironment() = 'test') THEN
RETURN TIMESTAMP('2022-01-19 00:00:00');
RETURN TIMESTAMP('2022-01-19 08:00:00');
ELSE
RETURN NOW();
END IF;
@ -607,19 +607,19 @@ INSERT INTO `vn`.`invoiceOutExpence`(`id`, `invoiceOutFk`, `amount`, `expenceFk`
INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `agencyModeFk`, `travelingDays`, `price`, `bonus`, `itemMaxSize`)
VALUES
(1, 'Zone pickup A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100),
(2, 'Zone pickup B', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100),
(3, 'Zone 247 A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100),
(4, 'Zone 247 B', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100),
(5, 'Zone expensive A', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100),
(6, 'Zone expensive B', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100),
(7, 'Zone refund', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 23, 0, 0, 0, 100),
(8, 'Zone others', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 10, 0, 0, 0, 100),
(9, 'Zone superMan', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 2, 0, 0, 0, 100),
(10, 'Zone teleportation', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 3, 0, 0, 0, 100),
(11, 'Zone pickup C', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100),
(12, 'Zone entanglement', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 4, 0, 0, 0, 100),
(13, 'Zone quantum break', CONCAT(CURRENT_DATE(), ' ', TIME('23:59')), 5, 0, 0, 0, 100);
(1, 'Zone pickup A', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100),
(2, 'Zone pickup B', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100),
(3, 'Zone 247 A', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100),
(4, 'Zone 247 B', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 7, 1, 2, 0, 100),
(5, 'Zone expensive A', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100),
(6, 'Zone expensive B', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 8, 1, 1000, 0, 100),
(7, 'Zone refund', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 23, 0, 0, 0, 100),
(8, 'Zone others', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 10, 0, 0, 0, 100),
(9, 'Zone superMan', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 2, 0, 0, 0, 100),
(10, 'Zone teleportation', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 3, 0, 0, 0, 100),
(11, 'Zone pickup C', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 1, 0, 0, 0, 100),
(12, 'Zone entanglement', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 4, 0, 0, 0, 100),
(13, 'Zone quantum break', CONCAT(vn.VN_CURDATE(), ' ', TIME('23:59')), 5, 0, 0, 0, 100);
INSERT INTO `vn`.`zoneWarehouse` (`id`, `zoneFk`, `warehouseFk`)
VALUES
@ -1381,9 +1381,9 @@ INSERT INTO `vn`.`supplierContact`(`id`, `supplierFk`, `phone`, `mobile`, `email
INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_refresh`, `expires`, `created`, `connection_id`)
VALUES
(1, 2, 'available', CONCAT_WS('/',1,vn.VN_CURDATE()), CURRENT_TIMESTAMP(), DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL 15 MINUTE), vn.VN_CURDATE(), NULL),
(2, 4, 'last_buy', CONCAT_WS('/',1,vn.VN_CURDATE()), CURRENT_TIMESTAMP(), DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL 15 MINUTE), vn.VN_CURDATE(), NULL),
(3, 8, 'visible', CONCAT_WS('/',1,vn.VN_CURDATE()), CURRENT_TIMESTAMP(), DATE_ADD(CURRENT_TIMESTAMP(),INTERVAL 15 MINUTE), vn.VN_CURDATE(), NULL);
(1, 2, 'available', CONCAT_WS('/',1,vn.VN_CURDATE()), vn.VN_NOW(), DATE_ADD(vn.VN_NOW(),INTERVAL 15 MINUTE), vn.VN_CURDATE(), NULL),
(2, 4, 'last_buy', CONCAT_WS('/',1,vn.VN_CURDATE()), vn.VN_NOW(), DATE_ADD(vn.VN_NOW(),INTERVAL 15 MINUTE), vn.VN_CURDATE(), NULL),
(3, 8, 'visible', CONCAT_WS('/',1,vn.VN_CURDATE()), vn.VN_NOW(), DATE_ADD(vn.VN_NOW(),INTERVAL 15 MINUTE), vn.VN_CURDATE(), NULL);
INSERT INTO `vn`.`ticketWeekly`(`ticketFk`, `weekDay`)
VALUES

View File

@ -95,6 +95,7 @@ describe('client summary()', () => {
it('should return a summary object without containing active recoveries', async() => {
const clientId = 1101;
const tx = await models.Client.beginTransaction({});
jasmine.clock().uninstall();
try {
const options = {transaction: tx};
@ -108,6 +109,9 @@ describe('client summary()', () => {
await tx.rollback();
throw e;
}
jasmine.clock().install();
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});
it('should return a summary object containing active recoveries', async() => {
@ -120,7 +124,6 @@ describe('client summary()', () => {
const result = await models.Client.summary(clientId, options);
expect(result.recovery.id).toEqual(3);
await tx.rollback();
} catch (e) {
await tx.rollback();

View File

@ -123,10 +123,9 @@ module.exports = Self => {
return clientModel.findOne(filter, options);
}
async function getRecoveries(recoveryModel, clientId, options) {
const today = new Date();
const filter = {
where: {
and: [{clientFk: clientId}, {or: [{finished: null}, {finished: {gt: today.getTime()}}]}]
and: [{clientFk: clientId}, {or: [{finished: null}, {finished: {gt: Date.now()}}]}]
},
limit: 1
};

View File

@ -73,7 +73,7 @@ module.exports = Self => {
},
]
}, myOptions);
console.log(tickets);
return tickets;
};
};

View File

@ -10,7 +10,7 @@ describe('route getSuggestedTickets()', () => {
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});

View File

@ -8,17 +8,10 @@ describe('route insertTicket()', () => {
accessToken: {userId: deliveryId},
};
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
jasmine.clock().mockDate(baseTime);
});
beforeAll(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
jasmine.clock().uninstall();
});
it('should add the ticket to a route', async() => {

View File

@ -7,7 +7,7 @@ describe('route unlink()', () => {
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});

View File

@ -8,7 +8,7 @@ describe('ticket getPossibleStowaways()', () => {
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});

View File

@ -7,7 +7,7 @@ describe('Worker absences()', () => {
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});

View File

@ -1,11 +1,11 @@
const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('workerTimeControl filter()', () => {
it('should return 1 result filtering by id', async() => {
let ctx = {req: {accessToken: {userId: 1106}}, args: {workerFk: 1106}};
const firstHour = new Date('2022-01-19');
const ctx = {req: {accessToken: {userId: 1106}}, args: {workerFk: 1106}};
const firstHour = new Date();
firstHour.setHours(7, 0, 0, 0);
const lastHour = new Date('2022-01-19');
const lastHour = new Date();
lastHour.setDate(lastHour.getDate() + 1);
lastHour.setHours(15, 0, 0, 0);
@ -14,16 +14,16 @@ describe('workerTimeControl filter()', () => {
timed: {between: [firstHour, lastHour]}
}
};
let result = await app.models.WorkerTimeControl.filter(ctx, filter);
const result = await models.WorkerTimeControl.filter(ctx, filter);
expect(result.length).toEqual(4);
});
it('should return a privilege error for a non subordinate worker', async() => {
let ctx = {req: {accessToken: {userId: 1107}}, args: {workerFk: 1106}};
const firstHour = new Date('2022-01-19');
const ctx = {req: {accessToken: {userId: 1107}}, args: {workerFk: 1106}};
const firstHour = new Date();
firstHour.setHours(7, 0, 0, 0);
const lastHour = new Date('2022-01-19');
const lastHour = new Date();
lastHour.setDate(lastHour.getDate() + 1);
lastHour.setHours(15, 0, 0, 0);
@ -34,7 +34,7 @@ describe('workerTimeControl filter()', () => {
};
let error;
await app.models.WorkerTimeControl.filter(ctx, filter).catch(e => {
await models.WorkerTimeControl.filter(ctx, filter).catch(e => {
error = e;
}).finally(() => {
expect(error.message).toEqual(`You don't have enough privileges`);

View File

@ -8,22 +8,15 @@ describe('workerTimeControl add/delete timeEntry()', () => {
const employeeId = 1;
const salesPersonId = 1106;
const salesBossId = 19;
let activeCtx = {
const activeCtx = {
accessToken: {userId: 50},
};
let ctx = {req: activeCtx};
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
jasmine.clock().mockDate(baseTime);
});
const ctx = {req: activeCtx};
beforeAll(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
jasmine.clock().uninstall();
});
it('should fail to add a time entry if the target user is not a subordinate', async() => {
@ -85,11 +78,13 @@ describe('workerTimeControl add/delete timeEntry()', () => {
});
it('should fail to add a time entry if the target user has absent that day', async() => {
jasmine.clock().uninstall();
activeCtx.accessToken.userId = salesBossId;
const workerId = salesPersonId;
let error;
let calendar = await app.models.Calendar.findById(3);
const calendar = await app.models.Calendar.findById(3);
try {
ctx.args = {timed: new Date(calendar.dated), direction: 'in'};
@ -99,6 +94,10 @@ describe('workerTimeControl add/delete timeEntry()', () => {
}
expect(error.message).toBe(`The worker has a marked absence that day`);
jasmine.clock().install();
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});
it('should try but fail to delete his own time entry', async() => {

View File

@ -15,7 +15,7 @@ describe('Worker holidays()', () => {
afterAll(() => {
jasmine.clock().install();
const baseTime = new Date(2022, 0, 19);
const baseTime = new Date('January 19, 2022 08:00:00');
jasmine.clock().mockDate(baseTime);
});