From a143e4ee526795b4278d47a3d3d0329f839ba2b9 Mon Sep 17 00:00:00 2001 From: chrisala Date: Tue, 7 May 2024 09:32:42 +1000 Subject: [PATCH] Addressed code review issue #934 --- .../ala/ecodata/DataSetSummaryController.groovy | 4 ++-- .../ecodata/DataSetSummaryControllerSpec.groovy | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/grails-app/controllers/au/org/ala/ecodata/DataSetSummaryController.groovy b/grails-app/controllers/au/org/ala/ecodata/DataSetSummaryController.groovy index 899399210..7a5d1a292 100644 --- a/grails-app/controllers/au/org/ala/ecodata/DataSetSummaryController.groovy +++ b/grails-app/controllers/au/org/ala/ecodata/DataSetSummaryController.groovy @@ -44,9 +44,9 @@ class DataSetSummaryController { return } - dataSets.each { Map dataSet -> + for (Map dataSet in dataSets) { if (dataSet.projectId && dataSet.projectId != projectId) { - render status: HttpStatus.SC_BAD_REQUEST, text: "projectId must match the data set projectId" + render status: HttpStatus.SC_BAD_REQUEST, text: "projectId must match the projectId in all supplied data sets" return } } diff --git a/src/test/groovy/au/org/ala/ecodata/DataSetSummaryControllerSpec.groovy b/src/test/groovy/au/org/ala/ecodata/DataSetSummaryControllerSpec.groovy index 9b9db1b28..d7dc36f56 100644 --- a/src/test/groovy/au/org/ala/ecodata/DataSetSummaryControllerSpec.groovy +++ b/src/test/groovy/au/org/ala/ecodata/DataSetSummaryControllerSpec.groovy @@ -72,4 +72,19 @@ class DataSetSummaryControllerSpec extends Specification implements ControllerUn 1 * projectService.updateDataSets(projectId, postBody.dataSets) >> [status:'ok'] response.json == ['status':'ok'] } + + void "If a projectId is present in a dataSet it much match the projectId parameter in bulkUpdate"() { + setup: + String projectId = 'p1' + Map postBody = [dataSets:[[dataSetId:'d1', name:'Data set 1', projectId:'p1'], [dataSetId:'d2', name:'Data set 2', projectId:'p2']]] + + when: + request.method = 'POST' + request.json = postBody + controller.bulkUpdate(projectId) + + then: + 0 * projectService.updateDataSets(_, _) + response.status == HttpStatus.SC_BAD_REQUEST + } }