-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OGUI-1432] Add run controller for allowing retrieval of calibration …
…runs (#2169) * Fixes the runAdpter for summary information * Adds enum for run definitions * Small fixes in `RunService` * Adds tests to `RunService` and `RunController` * Adds controller for runs
- Loading branch information
Showing
17 changed files
with
302 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @license | ||
* Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
* All rights not expressly granted are reserved. | ||
* | ||
* This software is distributed under the terms of the GNU General Public | ||
* License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
/** | ||
* Run Definitions as per Bookkeeping's implementation: https://github.com/AliceO2Group/Bookkeeping/blob/main/docs/RUN_DEFINITIONS.md | ||
*/ | ||
const RUN_DEFINITIONS = Object.freeze({ | ||
CALIBRATION: 'CALIBRATION' | ||
}); | ||
|
||
exports.RUN_DEFINITIONS = RUN_DEFINITIONS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license | ||
* Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
* All rights not expressly granted are reserved. | ||
* | ||
* This software is distributed under the terms of the GNU General Public | ||
* License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
const {Log} = require('@aliceo2/web-ui'); | ||
const {updateExpressResponseFromNativeError} = require('./../errors/updateExpressResponseFromNativeError.js'); | ||
|
||
/** | ||
* Controller for dealing with all API requests on retrieving information on runs | ||
*/ | ||
class RunController { | ||
/** | ||
* Constructor for initializing controller of runs | ||
* @param {RunService} runService - service to use to build information on runs | ||
*/ | ||
constructor(runService) { | ||
this._logger = new Log(`${process.env.npm_config_log_label ?? 'cog'}/run-ctrl`); | ||
|
||
/** | ||
* @type {RunService} | ||
*/ | ||
this._runService = runService; | ||
} | ||
|
||
/** | ||
* API - GET endpoint for retrieving calibration runs | ||
* @param {Request} req - HTTP Request object | ||
* @param {Response} res - HTTP Response object | ||
* @returns {void} | ||
*/ | ||
async getCalibrationRunsHandler(_, res) { | ||
try { | ||
const response = await this._runService.retrieveCalibrationRunsGroupedByDetector(); | ||
res.status(200).json(response); | ||
} catch (error) { | ||
this._logger.debug(error); | ||
updateExpressResponseFromNativeError(res, error); | ||
} | ||
} | ||
} | ||
|
||
module.exports = {RunController}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @license | ||
* Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
* All rights not expressly granted are reserved. | ||
* | ||
* This software is distributed under the terms of the GNU General Public | ||
* License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
/* eslint-disable max-len */ | ||
|
||
const assert = require('assert'); | ||
const sinon = require('sinon'); | ||
|
||
const {RunController} = require('../../../lib/controllers/Run.controller.js'); | ||
|
||
describe(`'RunController' test suite`, () => { | ||
const res = { | ||
status: sinon.stub().returnsThis(), | ||
json: sinon.stub() | ||
} | ||
|
||
describe(`'getCalibrationRunsHandler' test suite`, async () => { | ||
it('should successfully return calibrations runs grouped by detector', async () => { | ||
const runs = { | ||
TPC: [ | ||
{runNumber: 1}, | ||
{runNumber: 2}, | ||
] | ||
}; | ||
const runController = new RunController({ | ||
retrieveCalibrationRunsGroupedByDetector: sinon.stub().resolves(runs) | ||
}); | ||
await runController.getCalibrationRunsHandler({}, res); | ||
assert.ok(res.status.calledWith(200)); | ||
assert.ok(res.json.calledWith(runs)); | ||
}); | ||
|
||
it('should return 500 response as there was a problem internally', async () => { | ||
const runController = new RunController({ | ||
retrieveCalibrationRunsGroupedByDetector: sinon.stub().rejects(new Error('Something went wrong')) | ||
}); | ||
await runController.getCalibrationRunsHandler({}, res); | ||
assert.ok(res.status.calledWith(500)); | ||
assert.ok(res.json.calledWith({message: 'Something went wrong'})); | ||
}); | ||
}); | ||
|
||
}); |
Oops, something went wrong.