diff --git a/src/api/route-services/experiment.js b/src/api/route-services/experiment.js index c9a0297f8..57f05ae89 100644 --- a/src/api/route-services/experiment.js +++ b/src/api/route-services/experiment.js @@ -246,7 +246,7 @@ class ExperimentService { return prettyData; } - async savePipelineHandle(experimentId, handle) { + async saveHandle(experimentId, handle, service) { const dynamodb = createDynamoDbInstance(); let key = { experimentId }; @@ -257,7 +257,7 @@ class ExperimentService { const params = { TableName: this.experimentsTableName, Key: key, - UpdateExpression: 'set meta.pipeline = :x', + UpdateExpression: `set meta.${service} = :x`, ExpressionAttributeValues: data, }; @@ -266,6 +266,14 @@ class ExperimentService { const prettyData = convertToJsObject(result.Attributes); return prettyData; } + + async saveQCHandle(experimentId, handle) { + return this.saveHandle(experimentId, handle, 'pipeline'); + } + + async saveGem2sHandle(experimentId, handle) { + return this.saveHandle(experimentId, handle, 'gem2s'); + } } module.exports = ExperimentService; diff --git a/src/api/routes/gem2s.js b/src/api/routes/gem2s.js index 65a82eea1..4e18d5695 100644 --- a/src/api/routes/gem2s.js +++ b/src/api/routes/gem2s.js @@ -5,6 +5,7 @@ const getBackendStatus = require('../general-services/backend-status'); const pipelineResponse = require('../route-services/pipeline-response'); const parseSNSMessage = require('../../utils/parse-sns-message'); const logger = require('../../utils/logging'); + const { expressAuthorizationMiddleware } = require('../../utils/authMiddlewares'); module.exports = { @@ -23,7 +24,7 @@ module.exports = { createGem2SPipeline(req.params.experimentId) .then((data) => { const experimentService = new ExperimentService(); - experimentService.savePipelineHandle(req.params.experimentId, data) + experimentService.saveGem2sHandle(req.params.experimentId, data) .then(() => res.json(data)); }) .catch(next); diff --git a/src/api/routes/pipelines.js b/src/api/routes/pipelines.js index 0fb0eb8a4..961e2eb72 100644 --- a/src/api/routes/pipelines.js +++ b/src/api/routes/pipelines.js @@ -17,14 +17,13 @@ module.exports = { }, ], 'pipelines#create': [ - expressAuthorizationMiddleware, (req, res, next) => { const { processingConfig } = req.body; createQCPipeline(req.params.experimentId, processingConfig || []) .then((data) => { const experimentService = new ExperimentService(); - experimentService.savePipelineHandle(req.params.experimentId, data) + experimentService.saveQCHandle(req.params.experimentId, data) .then(() => res.json(data)); }) .catch(next); diff --git a/tests/api/route-services/experiment.test.js b/tests/api/route-services/experiment.test.js index 66950015e..e83253807 100644 --- a/tests/api/route-services/experiment.test.js +++ b/tests/api/route-services/experiment.test.js @@ -236,7 +236,7 @@ describe('tests for the experiment service', () => { const updateItemSpy = mockDynamoUpdateItem(); const dynamoTestData = AWS.DynamoDB.Converter.marshall({ ':x': jsTestData }); - (new ExperimentService()).savePipelineHandle('12345', jsTestData) + (new ExperimentService()).saveQCHandle('12345', jsTestData) .then(() => { expect(updateItemSpy).toHaveBeenCalledWith( { @@ -249,4 +249,27 @@ describe('tests for the experiment service', () => { }) .then(() => done()); }); + + it('Set gem2s Handle works', async (done) => { + const jsTestData = { + stateMachineArn: 'STATE-MACHINE-ID', + executionArn: 'EXECUTION-ID', + }; + + const updateItemSpy = mockDynamoUpdateItem(); + const dynamoTestData = AWS.DynamoDB.Converter.marshall({ ':x': jsTestData }); + + (new ExperimentService()).saveGem2sHandle('12345', jsTestData) + .then(() => { + expect(updateItemSpy).toHaveBeenCalledWith( + { + TableName: 'experiments-test', + Key: { experimentId: { S: '12345' } }, + UpdateExpression: 'set meta.gem2s = :x', + ExpressionAttributeValues: dynamoTestData, + }, + ); + }) + .then(() => done()); + }); });