diff --git a/lib/database/seeders/20200713103855-runs.js b/lib/database/seeders/20200713103855-runs.js index 4a63975a52..1eeda8e0a8 100644 --- a/lib/database/seeders/20200713103855-runs.js +++ b/lib/database/seeders/20200713103855-runs.js @@ -2690,9 +2690,10 @@ module.exports = { { id: 107, run_number: 107, + first_tf_timestamp: '2019-08-08 12:59:00', time_o2_start: '2019-08-08 13:00:00', time_o2_end: '2019-08-09 14:00:00', - last_tf_timestamp: '2019-08-09 13:00:00', + last_tf_timestamp: '2019-08-09 14:01:00', run_type_id: 12, run_quality: 'good', n_detectors: 15, diff --git a/lib/database/seeders/20221006084006-run-detectors.js b/lib/database/seeders/20221006084006-run-detectors.js index 76adf87966..4362081b03 100644 --- a/lib/database/seeders/20221006084006-run-detectors.js +++ b/lib/database/seeders/20221006084006-run-detectors.js @@ -624,6 +624,81 @@ module.exports = { detector_id: 16, quality: 'good', }, + { + run_number: 107, + detector_id: 17, + quality: 'good', + }, + { + run_number: 107, + detector_id: 1, + quality: 'good', + }, + { + run_number: 107, + detector_id: 18, + quality: 'good', + }, + { + run_number: 107, + detector_id: 2, + quality: 'good', + }, + { + run_number: 107, + detector_id: 19, + quality: 'good', + }, + { + run_number: 107, + detector_id: 6, + quality: 'good', + }, + { + run_number: 107, + detector_id: 4, + quality: 'good', + }, + { + run_number: 107, + detector_id: 8, + quality: 'good', + }, + { + run_number: 107, + detector_id: 9, + quality: 'good', + }, + { + run_number: 107, + detector_id: 10, + quality: 'good', + }, + { + run_number: 107, + detector_id: 11, + quality: 'good', + }, + { + run_number: 107, + detector_id: 12, + quality: 'good', + }, + { + run_number: 107, + detector_id: 13, + quality: 'good', + }, + { + run_number: 107, + detector_id: 14, + quality: 'good', + }, + { + run_number: 107, + detector_id: 16, + quality: 'good', + }, ], { transaction }, ), diff --git a/lib/server/controllers/gRPC/GRPCFlpRoleController.js b/lib/server/controllers/gRPC/GRPCFlpRoleController.js index bbb735f94e..bcbce92d67 100644 --- a/lib/server/controllers/gRPC/GRPCFlpRoleController.js +++ b/lib/server/controllers/gRPC/GRPCFlpRoleController.js @@ -31,7 +31,7 @@ class GRPCFlpRoleController { try { createdFlps.push(await this.flpRoleService.create({ name, hostname, runNumber })); } catch (e) { - // TODO log into infologger + // TODO [O2B-967] log into infologger } } return { flps: createdFlps }; diff --git a/lib/server/services/qualityControlFlag/QcFlagService.js b/lib/server/services/qualityControlFlag/QcFlagService.js index 11de154656..4481618791 100644 --- a/lib/server/services/qualityControlFlag/QcFlagService.js +++ b/lib/server/services/qualityControlFlag/QcFlagService.js @@ -168,7 +168,7 @@ class QcFlagService { let upperBound = timeTrgEnd?.getTime() ?? timeO2End?.getTime() ?? null; if (lastTfTimestamp) { - upperBound = upperBound ? Math.max(lastTfTimestamp?.getTime(), upperBound) : lastTfTimestamp.getTime(); + upperBound = upperBound ? Math.max(lastTfTimestamp.getTime(), upperBound) : lastTfTimestamp.getTime(); } const from = timestamps.from ?? lowerBound ?? null; @@ -887,7 +887,7 @@ class QcFlagService { const run = await RunRepository.findOne({ subQuery: false, - attributes: ['timeTrgStart', 'timeTrgEnd'], + attributes: ['timeO2Start', 'timeTrgStart', 'firstTfTimestamp', 'lastTfTimestamp', 'timeTrgEnd', 'timeO2End'], where: { runNumber }, include: runInclude, }); diff --git a/lib/server/services/run/RunService.js b/lib/server/services/run/RunService.js index 118cefcb27..d39d69e36a 100644 --- a/lib/server/services/run/RunService.js +++ b/lib/server/services/run/RunService.js @@ -114,7 +114,7 @@ const logRunDetectorQualityChange = async (runNumber, runDetectors, transaction, transaction, ); if (error) { - // TODO log the failed log creation + // TODO [O2B-967] log the failed log creation } }; @@ -162,7 +162,7 @@ const logEorReasonChange = async (runNumber, userName, eorReasons, transaction) ); if (error) { - // TODO log the failed log creation + // TODO [O2B-967] log the failed log creation } }; diff --git a/test/lib/server/services/qualityControlFlag/QcFlagService.test.js b/test/lib/server/services/qualityControlFlag/QcFlagService.test.js index 92d32903d2..f26dbed243 100644 --- a/test/lib/server/services/qualityControlFlag/QcFlagService.test.js +++ b/test/lib/server/services/qualityControlFlag/QcFlagService.test.js @@ -914,6 +914,66 @@ module.exports = () => { ); }); + it('should fail to create quality control flag because qc flag `from` timestamp is smaller than run.firstTfTimestamp', async () => { + const period = { + from: new Date('2019-08-08 11:36:40').getTime(), + to: new Date('2019-08-09 05:40:00').getTime(), + }; + + const runFirstTfTimestamp = new Date('2019-08-08 12:59:00').getTime(); + const runLastTfTimestamp = new Date('2019-08-09 14:01:00').getTime(); + + const qcFlag = { + ...period, + comment: 'VERY INTERESTING REMARK', + flagTypeId: 2, + }; + + const scope = { + runNumber: 107, + simulationPassIdentifier: { id: 1 }, + detectorIdentifier: { detectorId: 1 }, + }; + + const relations = { user: { roles: ['admin'], externalUserId: 456 } }; + + await assert.rejects( + () => qcFlagService.create([qcFlag], scope, relations), + // eslint-disable-next-line max-len + new BadParameterError(`Given QC flag period (${period.from}, ${period.to}) is out of run (${runFirstTfTimestamp}, ${runLastTfTimestamp}) period`), + ); + }); + + it('should fail to create quality control flag because qc flag `to` timestamp is greater than run.lastTfTimestamp', async () => { + const period = { + from: new Date('2019-08-08 13:17:19').getTime(), + to: new Date('2019-08-09 15:49:01').getTime(), + }; + + const runFirstTfTimestamp = new Date('2019-08-08 12:59:00').getTime(); + const runLastTfTimestamp = new Date('2019-08-09 14:01:00').getTime(); + + const qcFlag = { + ...period, + comment: 'VERY INTERESTING REMARK', + flagTypeId: 2, + }; + + const scope = { + runNumber: 107, + simulationPassIdentifier: { id: 1 }, + detectorIdentifier: { detectorId: 1 }, + }; + + const relations = { user: { roles: ['admin'], externalUserId: 456 } }; + + await assert.rejects( + () => qcFlagService.create([qcFlag], scope, relations), + // eslint-disable-next-line max-len + new BadParameterError(`Given QC flag period (${period.from}, ${period.to}) is out of run (${runFirstTfTimestamp}, ${runLastTfTimestamp}) period`), + ); + }); + it('should fail to create quality control flag because qc flag `from` timestamp is greater than `to` timestamp', async () => { const qcFlag = { from: new Date('2019-08-09 04:16:40').getTime(), // Failing property