diff --git a/test/public/eosReport/ecs-creation.test.js b/test/public/eosReport/ecs-creation.test.js index a8fda1006a..0bce18340a 100644 --- a/test/public/eosReport/ecs-creation.test.js +++ b/test/public/eosReport/ecs-creation.test.js @@ -34,6 +34,7 @@ const EorReasonRepository = require('../../../lib/database/repositories/EorReaso const { ShiftTypes } = require('../../../lib/domain/enums/ShiftTypes.js'); const { eosReportService } = require('../../../lib/server/services/eosReport/EosReportService.js'); const { SHIFT_DURATION } = require('../../../lib/server/services/shift/getShiftFromTimestamp.js'); +const { shiftService } = require('../../../lib/server/services/shift/ShiftService.js'); module.exports = () => { let page; @@ -60,13 +61,16 @@ module.exports = () => { }); it('Should successfully create an ECS EoS report when submitting the form and redirect to the corresponding log', async () => { + // The pending shift depends on the time of the day, so all the fixtures are derived from it + const pendingShift = await shiftService.getUserPendingShiftOrFail({ userId: 1 }); + for (const environment of customizedECSEosReport.typeSpecific.environments) { await createEnvironment({ ...environment, }); await createEnvironmentHistoryItem({ status: 'DONE', - timestamp: new Date(), + timestamp: new Date(pendingShift.start + 1000), timestampNano: 0, environmentId: environment.id, }); @@ -92,7 +96,7 @@ module.exports = () => { } // Create the expected previous EoS report - const past = new Date(Date.now() - SHIFT_DURATION); + const past = new Date(pendingShift.start - SHIFT_DURATION + 1000); const info = 'Important information for the next tester'; const request = { ...emptyECSEosReportRequest, diff --git a/test/public/eosReport/qc-pdp-creation.test.js b/test/public/eosReport/qc-pdp-creation.test.js index 4fb00517ea..4f764570fc 100644 --- a/test/public/eosReport/qc-pdp-creation.test.js +++ b/test/public/eosReport/qc-pdp-creation.test.js @@ -28,6 +28,7 @@ const { createRun } = require('../../../lib/server/services/run/createRun.js'); const EorReasonRepository = require('../../../lib/database/repositories/EorReasonRepository.js'); const { ShiftTypes } = require('../../../lib/domain/enums/ShiftTypes.js'); const { customizedQcPdpEosReport } = require('../../mocks/mock-qc-pdp-eos-report.js'); +const { shiftService } = require('../../../lib/server/services/shift/ShiftService.js'); const { updateRunDetector } = require('../../../lib/server/services/runDetector/updateRunDetector.js'); module.exports = () => { @@ -55,13 +56,16 @@ module.exports = () => { }); it('Should successfully create a QC/PDP EoS report when submitting the form and redirect to the corresponding log', async () => { + // The pending shift depends on the time of the day, so the runs must be created inside of it + const pendingShift = await shiftService.getUserPendingShiftOrFail({ userId: 1 }); + for (const runs of Object.values(customizedQcPdpEosReport.typeSpecific.runs)) { for (const run of runs) { const runId = await createRun( { ...run, - timeTrgStart: new Date(), - timeTrgEnd: new Date(), + timeTrgStart: new Date(pendingShift.start + 1000), + timeTrgEnd: new Date(pendingShift.start + 1000), }, { detectors: run.detectors }, ); diff --git a/test/public/eosReport/shift-leader-creation.test.js b/test/public/eosReport/shift-leader-creation.test.js index 81d7a07814..5729e41d02 100644 --- a/test/public/eosReport/shift-leader-creation.test.js +++ b/test/public/eosReport/shift-leader-creation.test.js @@ -55,13 +55,16 @@ module.exports = () => { }); it('Should successfully create a Shift Leader EoS report when submitting the form and redirect to the corresponding log', async () => { + // The pending shift depends on the time of the day, so the runs must be created inside of it + const currentShift = await shiftService.getUserPendingShiftOrFail({ userId: 1 }); + for (const runs of Object.values(customizedQcPdpEosReport.typeSpecific.runs)) { for (const run of runs) { await createRun( { ...run, - timeTrgStart: new Date(), - timeTrgEnd: new Date(), + timeTrgStart: new Date(currentShift.start + 1000), + timeTrgEnd: new Date(currentShift.start + 1000), }, { detectors: run.detectors }, ); @@ -77,7 +80,6 @@ module.exports = () => { await reloadPage(page); - const currentShift = await shiftService.getUserPendingShiftOrFail({ userId: 1 }); const magnetStart = formatShiftDate(currentShift.start, { time: true }); const { formatTimestampForDateTimeInput } = await import('../../../lib/public/utilities/formatting/dateTimeInputFormatters.mjs');