diff --git a/grails-app/controllers/au/org/ala/biocollect/merit/SiteController.groovy b/grails-app/controllers/au/org/ala/biocollect/merit/SiteController.groovy index de1c37ea8..abdbb96e2 100644 --- a/grails-app/controllers/au/org/ala/biocollect/merit/SiteController.groovy +++ b/grails-app/controllers/au/org/ala/biocollect/merit/SiteController.groovy @@ -24,7 +24,7 @@ import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT @SSO class SiteController { - + private static APPLICATION_JSON = 'application/json' def siteService, projectService, projectActivityService, activityService, metadataService, userService, searchService, importService, webService @@ -400,10 +400,10 @@ class SiteController { if (!error) { progress.finished = true - render([message: 'success', progress: progress]) as JSON + render(text: [message: 'success', progress: progress] as JSON, contentType: APPLICATION_JSON) } else { progress.finished = false - render([message: 'error', progress: progress, error: error]) as JSON + render(text: [message: 'error', progress: progress, error: error] as JSON, contentType: APPLICATION_JSON) } } diff --git a/package-lock.json b/package-lock.json index 3e47a17b2..f81513520 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "6.0", "devDependencies": { "@metahub/karma-jasmine-jquery": "^2.0.1", - "chromedriver": "^123.0.3", + "chromedriver": "^125.0.3", "jasmine-core": "^3.5.0", "jasmine-jquery": "^2.0.0", "jquery": "^3.4.1", @@ -689,9 +689,9 @@ } }, "node_modules/chromedriver": { - "version": "123.0.3", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-123.0.3.tgz", - "integrity": "sha512-35IeTqDLcVR0htF9nD/Lh+g24EG088WHVKXBXiFyWq+2lelnoM0B3tKTBiUEjLng0GnELI4QyQPFK7i97Fz1fQ==", + "version": "125.0.3", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-125.0.3.tgz", + "integrity": "sha512-Qzuk5Wian2o3EVGjtbz6V/jv+pT/AV9246HbG6kUljZXXjsKZLZxqJC+kHR3qEh/wdv4EJD0YwAOWV72v9hogw==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -4299,9 +4299,9 @@ } }, "chromedriver": { - "version": "123.0.3", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-123.0.3.tgz", - "integrity": "sha512-35IeTqDLcVR0htF9nD/Lh+g24EG088WHVKXBXiFyWq+2lelnoM0B3tKTBiUEjLng0GnELI4QyQPFK7i97Fz1fQ==", + "version": "125.0.3", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-125.0.3.tgz", + "integrity": "sha512-Qzuk5Wian2o3EVGjtbz6V/jv+pT/AV9246HbG6kUljZXXjsKZLZxqJC+kHR3qEh/wdv4EJD0YwAOWV72v9hogw==", "dev": true, "requires": { "@testim/chrome-version": "^1.1.4", diff --git a/package.json b/package.json index 1b726a969..6031eed9c 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "devDependencies": { "@metahub/karma-jasmine-jquery": "^2.0.1", - "chromedriver": "^123.0.3", + "chromedriver": "^125.0.3", "jasmine-core": "^3.5.0", "jasmine-jquery": "^2.0.0", "jquery": "^3.4.1", diff --git a/src/test/groovy/au/org/ala/biocollect/merit/SiteControllerSpec.groovy b/src/test/groovy/au/org/ala/biocollect/merit/SiteControllerSpec.groovy index 6c807d363..64201216e 100644 --- a/src/test/groovy/au/org/ala/biocollect/merit/SiteControllerSpec.groovy +++ b/src/test/groovy/au/org/ala/biocollect/merit/SiteControllerSpec.groovy @@ -71,4 +71,75 @@ class SiteControllerSpec extends Specification implements ControllerUnitTest> null + controller.createSitesFromShapefile() + + then: + response.json.message == 'success' + response.json.progress.total == 2 + response.json.progress.uploaded == 2 + response.json.progress.finished == true + } + + void "test createSitesFromShapefile - partial success"() { + given: + def siteData = [ + shapeFileId: 1, + projectId : 1, + sites : [ + [id: 1, externalId: "ext1", name: "Site 1", description: "Description 1"], + [id: 2, externalId: "ext2", name: "Site 2", description: "Description 2"] + ] + ] + request.JSON = siteData + + when: + siteService.createSiteFromUploadedShapefile(_, _, _, _, _, _, _) >>> [null, "Error creating site"] + controller.createSitesFromShapefile() + + then: + response.json.message == 'error' + response.json.progress.total == 2 + response.json.progress.uploaded == 1 + response.json.progress.finished == false + response.json.error == "Error creating site" + } + + void "test createSitesFromShapefile - exception"() { + given: + def siteData = [ + shapeFileId: 1, + projectId : 1, + sites : [ + [id: 1, externalId: "ext1", name: "Site 1", description: "Description 1"], + [id: 2, externalId: "ext2", name: "Site 2", description: "Description 2"] + ] + ] + request.JSON = siteData + + when: + siteService.createSiteFromUploadedShapefile(_, _, _, _, _, _, _) >> { throw new Exception("Unexpected error") } + controller.createSitesFromShapefile() + + then: + response.json.message == 'error' + response.json.progress.total == 2 + response.json.progress.uploaded == 0 + response.json.progress.finished == false + response.json.error == "Error uploading sites, please try again later" + } }