-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #360 from hms-dbmi-cellenics/plots-and-tables-v2
[BIOMAGE-1880] - Plots and tables v2
- Loading branch information
Showing
14 changed files
with
472 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const mockGetPlotConfig = jest.fn(); | ||
const mockUpdatePlotConfig = jest.fn(); | ||
|
||
module.exports = { | ||
getPlotConfig: mockGetPlotConfig, | ||
updatePlotConfig: mockUpdatePlotConfig, | ||
}; |
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,34 @@ | ||
const getLogger = require('../../utils/getLogger'); | ||
const { OK } = require('../../utils/responses'); | ||
|
||
const Plot = require('../model/Plot'); | ||
|
||
const logger = getLogger('[Plot Controller] - '); | ||
|
||
const getPlotConfig = async (req, res) => { | ||
const { experimentId, plotUuid } = req.params; | ||
logger.log(`Getting plot config for plot ${plotUuid}`); | ||
|
||
const result = await new Plot().getConfig(experimentId, plotUuid); | ||
|
||
logger.log(`Finished getting config for plot ${plotUuid}`); | ||
res.json(result); | ||
}; | ||
|
||
const updatePlotConfig = async (req, res) => { | ||
const { experimentId, plotUuid } = req.params; | ||
const { config } = req.body; | ||
|
||
logger.log(`Updating config for plot ${plotUuid}`); | ||
|
||
await new Plot().updateConfig(experimentId, plotUuid, config); | ||
|
||
logger.log(`Finished updating config for plot ${plotUuid}`); | ||
|
||
res.send(OK()); | ||
}; | ||
|
||
module.exports = { | ||
getPlotConfig, | ||
updatePlotConfig, | ||
}; |
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,11 @@ | ||
const BasicModel = require('./BasicModel')(); | ||
|
||
const stub = { | ||
getConfig: jest.fn(), | ||
updateConfig: jest.fn(), | ||
...BasicModel, | ||
}; | ||
|
||
const Plot = jest.fn().mockImplementation(() => stub); | ||
|
||
module.exports = Plot; |
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,17 @@ | ||
const { | ||
getPlotConfig, | ||
updatePlotConfig, | ||
} = require('../controllers/plotController'); | ||
|
||
const { expressAuthorizationMiddleware } = require('../middlewares/authMiddlewares'); | ||
|
||
module.exports = { | ||
'plots#get': [ | ||
expressAuthorizationMiddleware, | ||
(req, res, next) => getPlotConfig(req, res).catch(next), | ||
], | ||
'plots#update': [ | ||
expressAuthorizationMiddleware, | ||
(req, res, next) => updatePlotConfig(req, res).catch(next), | ||
], | ||
}; |
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,8 @@ | ||
title: Plots and tables configuration | ||
type: object | ||
description: A file specifying the configuration for a given plot/table. | ||
properties: | ||
config: | ||
type: object | ||
required: | ||
- config |
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,10 @@ | ||
title: Plot Data | ||
type: object | ||
properties: | ||
plotData: | ||
anyOf: | ||
- type: array | ||
- type: object | ||
required: | ||
- plotData | ||
description: Object storing the data for one particular plot. |
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,69 @@ | ||
// Disable semantic check because linter doesn't recognize jest mocks | ||
// @ts-nocheck | ||
const plotController = require('../../../src/api.v2/controllers/plotController'); | ||
const Plot = require('../../../src/api.v2/model/Plot'); | ||
|
||
const { OK } = require('../../../src/utils/responses'); | ||
|
||
jest.mock('../../../src/api.v2/model/Plot'); | ||
|
||
const mockRes = { | ||
json: jest.fn(), | ||
send: jest.fn(), | ||
}; | ||
|
||
const mockExperimentId = 'experimentId'; | ||
const mockPlotUuid = 'plotUuid'; | ||
|
||
const plotInstance = new Plot(); | ||
|
||
describe('plotController', () => { | ||
beforeEach(async () => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('getting plot works correctly', async () => { | ||
const mockConfig = { | ||
experimentId: mockExperimentId, | ||
plotUuid: mockPlotUuid, | ||
plotType: 'SomePlotType', | ||
config: {}, | ||
}; | ||
|
||
plotInstance.getConfig.mockReturnValue(mockConfig); | ||
|
||
const mockReq = { | ||
params: { experimentId: mockExperimentId, plotUuid: mockPlotUuid }, | ||
}; | ||
|
||
await plotController.getPlotConfig(mockReq, mockRes); | ||
|
||
expect(plotInstance.getConfig).toHaveBeenCalledWith( | ||
mockExperimentId, mockPlotUuid, | ||
); | ||
|
||
expect(mockRes.json).toHaveBeenCalledWith(mockConfig); | ||
}); | ||
|
||
it('updating plot works correctly', async () => { | ||
const mockConfig = { | ||
experimentId: mockExperimentId, | ||
plotUuid: mockPlotUuid, | ||
plotType: 'SomePlotType', | ||
config: {}, | ||
}; | ||
|
||
const mockReq = { | ||
params: { experimentId: mockExperimentId, plotUuid: mockPlotUuid }, | ||
body: { config: mockConfig }, | ||
}; | ||
|
||
await plotController.updatePlotConfig(mockReq, mockRes); | ||
|
||
expect(plotInstance.updateConfig).toHaveBeenCalledWith( | ||
mockExperimentId, mockPlotUuid, mockConfig, | ||
); | ||
|
||
expect(mockRes.send).toHaveBeenCalledWith(OK()); | ||
}); | ||
}); |
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
Oops, something went wrong.