From 72825aef8dacddc558569f15fe17c84908d8ba03 Mon Sep 17 00:00:00 2001 From: temi Date: Tue, 14 Nov 2023 19:16:19 +1100 Subject: [PATCH 1/3] #3004 - added organisation download - generalised download code - refactored code --- ...anagementUnitReport.js => entityReport.js} | 16 +++---- .../ala/merit/ManagementUnitController.groovy | 35 --------------- .../au/org/ala/merit/ReportController.groovy | 44 ++++++++++++++++--- .../ala/merit/ManagementUnitService.groovy | 21 --------- .../au/org/ala/merit/ReportService.groovy | 22 ++++++++++ grails-app/views/admin/adminReports.gsp | 44 +++++++++++++++---- .../au/org/ala/fieldcapture/AdminSpec.groovy | 22 ++++++++++ .../groovy/pages/AdminReportsPage.groovy | 22 ++++++++-- .../merit/ManagementUnitControllerSpec.groovy | 19 +------- .../merit/ManagementUnitServiceSpec.groovy | 13 ------ .../org/ala/merit/ReportControllerSpec.groovy | 32 ++++++++++++++ .../au/org/ala/merit/ReportServiceSpec.groovy | 16 ++++++- src/test/js/spec/AdminReportSpec.js | 12 ++--- 13 files changed, 199 insertions(+), 119 deletions(-) rename grails-app/assets/javascripts/{managementUnitReport.js => entityReport.js} (70%) create mode 100644 src/test/groovy/au/org/ala/merit/ReportControllerSpec.groovy diff --git a/grails-app/assets/javascripts/managementUnitReport.js b/grails-app/assets/javascripts/entityReport.js similarity index 70% rename from grails-app/assets/javascripts/managementUnitReport.js rename to grails-app/assets/javascripts/entityReport.js index 02c9cc771..fc35053da 100644 --- a/grails-app/assets/javascripts/managementUnitReport.js +++ b/grails-app/assets/javascripts/entityReport.js @@ -1,4 +1,4 @@ -function ManagementUnitReportSelectorViewModel(options) { +function EntityReportSelectorViewModel(options) { var self = this; var config = _.defaults(options); @@ -8,20 +8,20 @@ function ManagementUnitReportSelectorViewModel(options) { self.fromDate = ko.observable(d).extend({simpleDate:false}); self.toDate = ko.observable(now).extend({simpleDate:false}); - self.muReportDownload = function () { + self.entityReportDownload = function () { var summaryFlag = false; - return generateMuReport(summaryFlag) + return generateEntityReport(summaryFlag) }; - self.muReportDownloadSummary = function() { + self.entityReportDownloadSummary = function() { var summaryFlag = true; - generateMuReport(summaryFlag); + generateEntityReport(summaryFlag); }; - function generateMuReport(summaryFlag) { + function generateEntityReport(summaryFlag) { var json = {fromDate:self.fromDate(), toDate:self.toDate(), summaryFlag: summaryFlag} return $.ajax({ - url: config.generateMUReportInPeriodUrl, + url: config.generateEntityReportInPeriodUrl, type: 'GET', data: json, dataType:'json', @@ -33,7 +33,7 @@ function ManagementUnitReportSelectorViewModel(options) { var details = data['details'] var message = data['message'] var detailsIcon = ' ' - var detailsPanel = '
Try this link, if you cannot get an email confirmation
' + var detailsPanel = '
Try this link, if you cannot get an email confirmation
' bootbox.alert(message + detailsIcon + detailsPanel) } }).fail(function() { diff --git a/grails-app/controllers/au/org/ala/merit/ManagementUnitController.groovy b/grails-app/controllers/au/org/ala/merit/ManagementUnitController.groovy index e89512097..966297fd3 100644 --- a/grails-app/controllers/au/org/ala/merit/ManagementUnitController.groovy +++ b/grails-app/controllers/au/org/ala/merit/ManagementUnitController.groovy @@ -9,8 +9,6 @@ import grails.converters.JSON import grails.core.GrailsApplication import grails.web.mapping.LinkGenerator import org.apache.http.HttpStatus -import java.text.ParseException - /** * Processes requests relating to MUs */ @@ -352,39 +350,6 @@ class ManagementUnitController { render featureCollection as JSON } - @PreAuthorise(accessLevel='siteReadOnly') - def generateReportsInPeriod(){ - - String startDate = params.fromDate - String endDate = params.toDate - - try{ - - def user = userService.getUser() - def extras =[:] - extras.summaryFlag = params.summaryFlag - - String email = user.userName - extras.put("systemEmail", grailsApplication.config.getProperty('fieldcapture.system.email.address')) - extras.put("senderEmail", grailsApplication.config.getProperty('fieldcapture.system.email.address')) - extras.put("email", email) - - String reportDownloadBaseUrl= grailsLinkGenerator.link(controller:'download',action:'get', absolute: true) - extras.put("reportDownloadBaseUrl", reportDownloadBaseUrl) - - def resp = managementUnitService.generateReports(startDate, endDate,extras) - render resp as JSON - - }catch (ParseException e){ - def message = [message: 'Error: You need to provide startDate and endDate in the format of yyyy-MM-dd '] - response.setContentType("application/json") - render message as JSON - }catch(Exception e){ - def message = [message: 'Fatal: '+ e.message] - render message as JSON - } - } - /** * Star or unstar a management unit for a user * Action is determined by the URI endpoint, either: /add | /remove diff --git a/grails-app/controllers/au/org/ala/merit/ReportController.groovy b/grails-app/controllers/au/org/ala/merit/ReportController.groovy index 7427238ad..28615bdc2 100644 --- a/grails-app/controllers/au/org/ala/merit/ReportController.groovy +++ b/grails-app/controllers/au/org/ala/merit/ReportController.groovy @@ -1,17 +1,16 @@ package au.org.ala.merit -import au.ala.org.ws.security.RequireApiKey -import au.org.ala.merit.command.MeriPlanReportCommand -import au.org.ala.merit.command.ProjectSummaryReportCommand + import au.org.ala.merit.command.Reef2050PlanActionReportCommand import au.org.ala.merit.command.Reef2050PlanActionReportSummaryCommand import grails.converters.JSON -import org.apache.http.HttpStatus import org.joda.time.DateTime import org.joda.time.Interval import org.joda.time.Period -import static au.org.ala.merit.DashboardTagLib.* +import java.text.ParseException + +import static au.org.ala.merit.DashboardTagLib.estimateHeight class ReportController { @@ -518,4 +517,39 @@ class ReportController { render view: '/report/_reportingHistory', model: [reportingHistory: reportingHistory] } + @PreAuthorise(accessLevel='siteReadOnly') + def generateReportsInPeriod(){ + + String startDate = params.fromDate + String endDate = params.toDate + + try{ + + def user = userService.getUser() + def extras =[:] + extras.summaryFlag = params.summaryFlag + + String email = user.userName + extras.put("hubId", SettingService.hubConfig?.hubId) + extras.put("entity", params.entity) + extras.put("systemEmail", grailsApplication.config.getProperty('fieldcapture.system.email.address')) + extras.put("senderEmail", grailsApplication.config.getProperty('fieldcapture.system.email.address')) + extras.put("email", email) + + String reportDownloadBaseUrl= grailsLinkGenerator.link(controller:'download',action:'get', absolute: true) + extras.put("reportDownloadBaseUrl", reportDownloadBaseUrl) + + def resp = reportService.generateReports(startDate, endDate,extras) + render resp as JSON + + }catch (ParseException e){ + def message = [message: 'Error: You need to provide startDate and endDate in the format of yyyy-MM-dd '] + response.setContentType("application/json") + render message as JSON + }catch(Exception e){ + def message = [message: 'Fatal: '+ e.message] + render message as JSON + } + } + } diff --git a/grails-app/services/au/org/ala/merit/ManagementUnitService.groovy b/grails-app/services/au/org/ala/merit/ManagementUnitService.groovy index 6491b9bcc..bb2a0cfca 100644 --- a/grails-app/services/au/org/ala/merit/ManagementUnitService.groovy +++ b/grails-app/services/au/org/ala/merit/ManagementUnitService.groovy @@ -8,7 +8,6 @@ import grails.core.GrailsApplication import grails.plugin.cache.Cacheable import groovy.util.logging.Slf4j import org.grails.web.json.JSONArray -import org.joda.time.DateTimeZone @Slf4j class ManagementUnitService { @@ -263,24 +262,4 @@ class ManagementUnitService { String url = "${grailsApplication.config.getProperty('ecodata.baseUrl')}" + "managementunit/"+id+"/report" webService.getJson(url) } - /** - * Download [all] management unit reports in a given period - * @param startDate - * @param endDate - * @param emails for sending email to user - * @return - */ - def generateReports(String startDate, String endDate, Map extras = null){ - - // The end date is the last day of the period (e.g. 2020-06-30) but reports will end at midnight of the next day (e.g. 2020-07-01T00:00:00) - // so add a day or two to achieve this. - - String isoStartDate = DateUtils.format(DateUtils.parse(startDate).plusDays(1).withZone(DateTimeZone.UTC)) - String isoEndDate = DateUtils.format(DateUtils.parse(endDate).plusDays(1).withZone(DateTimeZone.UTC)) - - String url = "${grailsApplication.config.getProperty('ecodata.baseUrl')}" + "managementunit/generateReportsInPeriod?startDate=${isoStartDate}&endDate=${isoEndDate}" - url += '&' + extras.collect { k,v -> "$k=$v" }.join('&') - def resp = webService.getJson(url) - return resp - } } diff --git a/grails-app/services/au/org/ala/merit/ReportService.groovy b/grails-app/services/au/org/ala/merit/ReportService.groovy index 0a06c4274..c7e12e002 100644 --- a/grails-app/services/au/org/ala/merit/ReportService.groovy +++ b/grails-app/services/au/org/ala/merit/ReportService.groovy @@ -9,6 +9,7 @@ import grails.plugin.cache.Cacheable import groovy.util.logging.Slf4j import org.apache.commons.io.FilenameUtils import org.joda.time.DateTime +import org.joda.time.DateTimeZone import org.joda.time.Period @Slf4j @@ -981,4 +982,25 @@ class ReportService { history } + /** + * Download [all] management unit reports in a given period + * @param startDate + * @param endDate + * @param emails for sending email to user + * @return + */ + def generateReports(String startDate, String endDate, Map extras = null){ + + // The end date is the last day of the period (e.g. 2020-06-30) but reports will end at midnight of the next day (e.g. 2020-07-01T00:00:00) + // so add a day or two to achieve this. + + String isoStartDate = DateUtils.format(DateUtils.parse(startDate).plusDays(1).withZone(DateTimeZone.UTC)) + String isoEndDate = DateUtils.format(DateUtils.parse(endDate).plusDays(1).withZone(DateTimeZone.UTC)) + + String url = "${grailsApplication.config.getProperty('ecodata.baseUrl')}" + "report/generateReportsInPeriod?startDate=${isoStartDate}&endDate=${isoEndDate}" + url += '&' + extras.collect { k,v -> "$k=$v" }.join('&') + def resp = webService.getJson(url) + return resp + } + } diff --git a/grails-app/views/admin/adminReports.gsp b/grails-app/views/admin/adminReports.gsp index 1b695fc26..9d7e721bb 100644 --- a/grails-app/views/admin/adminReports.gsp +++ b/grails-app/views/admin/adminReports.gsp @@ -31,18 +31,39 @@
- +
- +
- Management Unit - Activities - Core Reports - Status + Management Unit - Activities + Core Reports - Status + + +

Organisation report download:

+
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ Organisation - Activities + Core Reports - Status
@@ -92,7 +113,7 @@ - + diff --git a/src/integration-test/groovy/au/org/ala/fieldcapture/AdminSpec.groovy b/src/integration-test/groovy/au/org/ala/fieldcapture/AdminSpec.groovy index b3f7e3157..303fd76fb 100644 --- a/src/integration-test/groovy/au/org/ala/fieldcapture/AdminSpec.groovy +++ b/src/integration-test/groovy/au/org/ala/fieldcapture/AdminSpec.groovy @@ -109,6 +109,28 @@ class AdminSpec extends StubbedCasSpec { messages[0].getSubject() == "Your download is ready" } + when:"I clicked the Organisation Activities Report button" + downloadOrgReport(fromDate, toDate) + okBootbox() + + then: + waitFor 20, { + MimeMessage[] messages = greenMail.getReceivedMessages() + messages?.length == 1 + messages[0].getSubject() == "Your download is ready" + } + + when:"I clicked the Organisation Report Status button" + downloadOrgReportSummary(fromDate, toDate) + okBootbox() + + then: + waitFor 20, { + MimeMessage[] messages = greenMail.getReceivedMessages() + messages?.length == 2 + messages[0].getSubject() == "Your download is ready" + } + } diff --git a/src/integration-test/groovy/pages/AdminReportsPage.groovy b/src/integration-test/groovy/pages/AdminReportsPage.groovy index 56ce57596..6016bce7c 100644 --- a/src/integration-test/groovy/pages/AdminReportsPage.groovy +++ b/src/integration-test/groovy/pages/AdminReportsPage.groovy @@ -12,10 +12,14 @@ class AdminReportsPage extends Page { period {$('select#reportPeriodOfManagementUnit',0)} downloadReportBtn(required:false) {$('a#muReportDownload')} downloadReportSummaryBtn(required:false) {$('a#muReportDownloadSummary')} + orgDownloadReportBtn(required:false) {$('a#muReportDownload')} + orgDownloadReportSummaryBtn(required:false) {$('a#muReportDownloadSummary')} showDownloadDetailsIcon(required:false) { $('i.showDownloadDetailsIcon')} - muReportDownloadLink(required:false) {$('a#muReportDownloadLink')} - startDate{$("#fromDate")} - endDate{$("#toDate")} + muReportDownloadLink(required:false) {$('a#entityReportDownloadLink')} + startDate{$("#muFromDate")} + endDate{$("#muToDate")} + orgStartDate{$("#orgFromDate")} + orgEndDate{$("#orgToDate")} reportFormats { $('#reportFormats')} viewReportBtn(required:false) {$('#viewReportBtn')} @@ -37,6 +41,18 @@ class AdminReportsPage extends Page { downloadReportSummaryBtn.click() } + def downloadOrgReport(String fromDate, String toDate) { + orgStartDate = fromDate + orgEndDate = toDate + orgDownloadReportBtn.click() + } + + def downloadOrgReportSummary(String fromDate, String toDate) { + orgStartDate = fromDate + orgEndDate = toDate + orgDownloadReportSummaryBtn.click() + } + def generateReef2050Pdf() { reportFormats = "pdf" viewReportBtn.click() diff --git a/src/test/groovy/au/org/ala/merit/ManagementUnitControllerSpec.groovy b/src/test/groovy/au/org/ala/merit/ManagementUnitControllerSpec.groovy index 1820efdc6..2092ce925 100644 --- a/src/test/groovy/au/org/ala/merit/ManagementUnitControllerSpec.groovy +++ b/src/test/groovy/au/org/ala/merit/ManagementUnitControllerSpec.groovy @@ -1,11 +1,10 @@ package au.org.ala.merit import au.org.ala.merit.command.SaveReportDataCommand -import au.org.ala.merit.hub.HubSettings import au.org.ala.merit.util.ProjectGroupingHelper +import grails.testing.web.controllers.ControllerUnitTest import org.apache.http.HttpStatus import spock.lang.Specification -import grails.testing.web.controllers.ControllerUnitTest class ManagementUnitControllerSpec extends Specification implements ControllerUnitTest{ @@ -444,22 +443,6 @@ class ManagementUnitControllerSpec extends Specification implements ControllerUn return program } - def "The controller delegates to the managementUnitService to produce reports"() { - setup: - String fromDate = '01-07-2020' - String toDate = '31-12-2020' - - when: - params.fromDate = fromDate - params.toDate = toDate - controller.generateReportsInPeriod() - - then: - 1 * userService.getUser() >> [userName:'test@test.com'] - 1 * managementUnitService.generateReports(fromDate, toDate, _) >> [status:HttpStatus.SC_OK] - response.json == [status:HttpStatus.SC_OK] - } - def "User adds star to the management unit "() { setup: String managementUnitId = 'p1' diff --git a/src/test/groovy/au/org/ala/merit/ManagementUnitServiceSpec.groovy b/src/test/groovy/au/org/ala/merit/ManagementUnitServiceSpec.groovy index 8fa2fb6e0..a5753f699 100644 --- a/src/test/groovy/au/org/ala/merit/ManagementUnitServiceSpec.groovy +++ b/src/test/groovy/au/org/ala/merit/ManagementUnitServiceSpec.groovy @@ -175,19 +175,6 @@ class ManagementUnitServiceSpec extends Specification implements ServiceUnitTest 0 * reportService.findReportsForManagementUnit(muId) } - def "The server delegates to the ecodata to produce reports"() { - setup: - String startDate = '2020-07-01' - String endDate = '2020-12-31' - Map extras = [test:'test'] - - when: - service.generateReports(startDate, endDate, extras) - - then: - 1 * webService.getJson({it.endsWith('/managementunit/generateReportsInPeriod?startDate=2020-07-02T00:00:00Z&endDate=2021-01-01T00:00:00Z&test=test')}) - } - def "Users with the MERIT siteReadOnly role can retrieve management unit reports and documents"() { setup: String muId = 'mu1' diff --git a/src/test/groovy/au/org/ala/merit/ReportControllerSpec.groovy b/src/test/groovy/au/org/ala/merit/ReportControllerSpec.groovy new file mode 100644 index 000000000..b9ff3ee60 --- /dev/null +++ b/src/test/groovy/au/org/ala/merit/ReportControllerSpec.groovy @@ -0,0 +1,32 @@ +package au.org.ala.merit + +import grails.testing.web.controllers.ControllerUnitTest +import org.apache.http.HttpStatus +import spock.lang.Specification + +class ReportControllerSpec extends Specification implements ControllerUnitTest { + ReportService reportService = Mock(ReportService) + UserService userService = Mock(UserService) + + def setup() { + controller.reportService = reportService + controller.userService = userService + } + + def "The controller delegates to the reportService to produce reports"() { + setup: + String fromDate = '01-07-2020' + String toDate = '31-12-2020' + + when: + params.fromDate = fromDate + params.toDate = toDate + controller.generateReportsInPeriod() + + then: + 1 * userService.getUser() >> [userName:'test@test.com'] + 1 * reportService.generateReports(fromDate, toDate, _) >> [status: HttpStatus.SC_OK] + response.json == [status:HttpStatus.SC_OK] + } + +} diff --git a/src/test/groovy/au/org/ala/merit/ReportServiceSpec.groovy b/src/test/groovy/au/org/ala/merit/ReportServiceSpec.groovy index 552f21e2c..88adb8168 100644 --- a/src/test/groovy/au/org/ala/merit/ReportServiceSpec.groovy +++ b/src/test/groovy/au/org/ala/merit/ReportServiceSpec.groovy @@ -2,13 +2,11 @@ package au.org.ala.merit import au.org.ala.merit.config.EmailTemplate import au.org.ala.merit.config.ProgramConfig -import au.org.ala.merit.PublicationStatus import au.org.ala.merit.config.ReportConfig import au.org.ala.merit.reports.ReportOwner import au.org.ala.web.AuthService import grails.testing.services.ServiceUnitTest import spock.lang.Specification - /** * See the API for {@link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions */ @@ -490,4 +488,18 @@ class ReportServiceSpec extends Specification implements ServiceUnitTest Date: Wed, 15 Nov 2023 11:00:41 +1100 Subject: [PATCH 2/3] #3004 - fixed broken test --- package-lock.json | 54 +++++++++---------- package.json | 2 +- .../org/ala/merit/AclInterceptorSpec.groovy | 6 +-- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/package-lock.json b/package-lock.json index 98388b17c..48e5a324f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@metahub/karma-jasmine-jquery": "^2.0.1", - "chromedriver": "117.0.3", + "chromedriver": "119.0.1", "jasmine-core": "^3.5.0", "jasmine-jquery": "^2.0.0", "jquery": "3.6.2", @@ -454,9 +454,9 @@ "dev": true }, "node_modules/@testim/chrome-version": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@testim/chrome-version/-/chrome-version-1.1.3.tgz", - "integrity": "sha512-g697J3WxV/Zytemz8aTuKjTGYtta9+02kva3C1xc7KXB8GdbfE1akGJIsZLyY/FSh2QrnE+fiB7vmWU3XNcb6A==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@testim/chrome-version/-/chrome-version-1.1.4.tgz", + "integrity": "sha512-kIhULpw9TrGYnHp/8VfdcneIcxKnLixmADtukQRtJUmsVlMg0niMkwV0xZmi8hqa57xqilIHjWFA0GKvEjVU5g==", "dev": true }, "node_modules/@types/cookie": { @@ -646,9 +646,9 @@ "dev": true }, "node_modules/axios": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", - "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "dev": true, "dependencies": { "follow-redirects": "^1.15.0", @@ -1060,19 +1060,19 @@ } }, "node_modules/chromedriver": { - "version": "117.0.3", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-117.0.3.tgz", - "integrity": "sha512-c2rk2eGK5zZFBJMdviUlAJfQEBuPNIKfal4+rTFVYAmrWbMPYAqPozB+rIkc1lDP/Ryw44lPiqKglrI01ILhTQ==", + "version": "119.0.1", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-119.0.1.tgz", + "integrity": "sha512-lpCFFLaXPpvElTaUOWKdP74pFb/sJhWtWqMjn7Ju1YriWn8dT5JBk84BGXMPvZQs70WfCYWecxdMmwfIu1Mupg==", "dev": true, "hasInstallScript": true, "dependencies": { - "@testim/chrome-version": "^1.1.3", - "axios": "^1.4.0", - "compare-versions": "^6.0.0", + "@testim/chrome-version": "^1.1.4", + "axios": "^1.6.0", + "compare-versions": "^6.1.0", "extract-zip": "^2.0.1", "https-proxy-agent": "^5.0.1", "proxy-from-env": "^1.1.0", - "tcp-port-used": "^1.0.1" + "tcp-port-used": "^1.0.2" }, "bin": { "chromedriver": "bin/chromedriver" @@ -4357,9 +4357,9 @@ "dev": true }, "@testim/chrome-version": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@testim/chrome-version/-/chrome-version-1.1.3.tgz", - "integrity": "sha512-g697J3WxV/Zytemz8aTuKjTGYtta9+02kva3C1xc7KXB8GdbfE1akGJIsZLyY/FSh2QrnE+fiB7vmWU3XNcb6A==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@testim/chrome-version/-/chrome-version-1.1.4.tgz", + "integrity": "sha512-kIhULpw9TrGYnHp/8VfdcneIcxKnLixmADtukQRtJUmsVlMg0niMkwV0xZmi8hqa57xqilIHjWFA0GKvEjVU5g==", "dev": true }, "@types/cookie": { @@ -4523,9 +4523,9 @@ "dev": true }, "axios": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", - "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "dev": true, "requires": { "follow-redirects": "^1.15.0", @@ -4858,18 +4858,18 @@ } }, "chromedriver": { - "version": "117.0.3", - "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-117.0.3.tgz", - "integrity": "sha512-c2rk2eGK5zZFBJMdviUlAJfQEBuPNIKfal4+rTFVYAmrWbMPYAqPozB+rIkc1lDP/Ryw44lPiqKglrI01ILhTQ==", + "version": "119.0.1", + "resolved": "https://registry.npmjs.org/chromedriver/-/chromedriver-119.0.1.tgz", + "integrity": "sha512-lpCFFLaXPpvElTaUOWKdP74pFb/sJhWtWqMjn7Ju1YriWn8dT5JBk84BGXMPvZQs70WfCYWecxdMmwfIu1Mupg==", "dev": true, "requires": { - "@testim/chrome-version": "^1.1.3", - "axios": "^1.4.0", - "compare-versions": "^6.0.0", + "@testim/chrome-version": "^1.1.4", + "axios": "^1.6.0", + "compare-versions": "^6.1.0", "extract-zip": "^2.0.1", "https-proxy-agent": "^5.0.1", "proxy-from-env": "^1.1.0", - "tcp-port-used": "^1.0.1" + "tcp-port-used": "^1.0.2" } }, "cipher-base": { diff --git a/package.json b/package.json index b84462bfa..97257ec0a 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@metahub/karma-jasmine-jquery": "^2.0.1", - "chromedriver": "117.0.3", + "chromedriver": "119.0.1", "jasmine-core": "^3.5.0", "jasmine-jquery": "^2.0.0", "jquery": "3.6.2", diff --git a/src/test/groovy/au/org/ala/merit/AclInterceptorSpec.groovy b/src/test/groovy/au/org/ala/merit/AclInterceptorSpec.groovy index fd49faf5b..652d2f918 100644 --- a/src/test/groovy/au/org/ala/merit/AclInterceptorSpec.groovy +++ b/src/test/groovy/au/org/ala/merit/AclInterceptorSpec.groovy @@ -1,10 +1,8 @@ package au.org.ala.merit - import grails.core.GrailsApplication import grails.core.GrailsClass import grails.testing.web.GrailsWebUnitTest -import grails.testing.web.interceptor.InterceptorUnitTest import grails.web.http.HttpHeaders import org.apache.http.HttpStatus import spock.lang.Specification @@ -148,7 +146,7 @@ class AclInterceptorSpec extends Specification implements GrailsWebUnitTest { GrailsApplication grailsApp = Mock(GrailsApplication) GrailsClass grailsClass = Mock(GrailsClass) aclInterceptor.grailsApplication = grailsApp - aclInterceptor.webRequest.controllerName = "ManagementUnitController" + aclInterceptor.webRequest.controllerName = "ReportController" aclInterceptor.webRequest.actionName = "generateReportsInPeriod" params.id = "p1" @@ -158,7 +156,7 @@ class AclInterceptorSpec extends Specification implements GrailsWebUnitTest { then: 1 * aclInterceptor.grailsApplication.getArtefactByLogicalPropertyName("Controller", _) >> grailsClass 1 * aclInterceptor.roleService.getAugmentedRoles() >> ["alaAdmin","siteAdmin","officer","siteReadOnly","readOnly"] - 1 * grailsClass.getClazz() >> ManagementUnitController.class + 1 * grailsClass.getClazz() >> ReportController.class 1 * aclInterceptor.userService.getCurrentUserId() >> "test" 1 * aclInterceptor.userService.userIsAlaOrFcAdmin() >> false 1 * aclInterceptor.userService.userHasReadOnlyAccess() >> false From a6efb51a4c57a4b0554cd3b6b31c4294406f18d5 Mon Sep 17 00:00:00 2001 From: temi Date: Wed, 15 Nov 2023 22:31:46 +1100 Subject: [PATCH 3/3] #3004 - added email to admin user - added functional tests data - updated functional test --- .../au/org/ala/fieldcapture/AdminSpec.groovy | 12 +++++----- .../ala/fieldcapture/StubbedCasSpec.groovy | 2 +- .../groovy/pages/AdminReportsPage.groovy | 4 ++-- .../resources/dataset3/loadDataSet.js | 22 ++++++++++++++++++- src/main/scripts/runFunctionalTests.sh | 2 +- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/integration-test/groovy/au/org/ala/fieldcapture/AdminSpec.groovy b/src/integration-test/groovy/au/org/ala/fieldcapture/AdminSpec.groovy index 303fd76fb..7329f2aca 100644 --- a/src/integration-test/groovy/au/org/ala/fieldcapture/AdminSpec.groovy +++ b/src/integration-test/groovy/au/org/ala/fieldcapture/AdminSpec.groovy @@ -72,7 +72,7 @@ class AdminSpec extends StubbedCasSpec { def "Admin Reports"() { setup: login([userId:'1', role:"ROLE_ADMIN", email:'fc-admin@nowhere.com', firstName: "ALA", lastName:'Admin'], browser) - String fromDate = "10/10/2020" + String fromDate = "10/01/2020" String toDate = "10/10/2021" when: @@ -106,7 +106,7 @@ class AdminSpec extends StubbedCasSpec { waitFor 20, { MimeMessage[] messages = greenMail.getReceivedMessages() messages?.length == 2 - messages[0].getSubject() == "Your download is ready" + messages[1].getSubject() == "Your download is ready" } when:"I clicked the Organisation Activities Report button" @@ -116,8 +116,8 @@ class AdminSpec extends StubbedCasSpec { then: waitFor 20, { MimeMessage[] messages = greenMail.getReceivedMessages() - messages?.length == 1 - messages[0].getSubject() == "Your download is ready" + messages?.length == 3 + messages[2].getSubject() == "Your download is ready" } when:"I clicked the Organisation Report Status button" @@ -127,8 +127,8 @@ class AdminSpec extends StubbedCasSpec { then: waitFor 20, { MimeMessage[] messages = greenMail.getReceivedMessages() - messages?.length == 2 - messages[0].getSubject() == "Your download is ready" + messages?.length == 4 + messages[3].getSubject() == "Your download is ready" } } diff --git a/src/integration-test/groovy/au/org/ala/fieldcapture/StubbedCasSpec.groovy b/src/integration-test/groovy/au/org/ala/fieldcapture/StubbedCasSpec.groovy index 84845b3bb..e525fcfc3 100644 --- a/src/integration-test/groovy/au/org/ala/fieldcapture/StubbedCasSpec.groovy +++ b/src/integration-test/groovy/au/org/ala/fieldcapture/StubbedCasSpec.groovy @@ -176,7 +176,7 @@ class StubbedCasSpec extends FieldcaptureFunctionalTest { } /** Convenience method to stub the login of a user with the CAS ROLE_ALA_ADMIN role */ def loginAsAlaAdmin(Browser browser) { - login([userId:ALA_ADMIN_USER_ID, role:"ROLE_ADMIN", email: 'ala_admin@nowhere.com', firstName:"ALA", lastName:"Administrator"], browser) + login([userId:ALA_ADMIN_USER_ID, role:"ROLE_ADMIN", userName: 'ala_admin@nowhere.com', email: 'ala_admin@nowhere.com', firstName:"ALA", lastName:"Administrator"], browser) } /** Convenience method to stub the login of a user no special roles */ def loginAsUser(String userId, Browser browser) { diff --git a/src/integration-test/groovy/pages/AdminReportsPage.groovy b/src/integration-test/groovy/pages/AdminReportsPage.groovy index 6016bce7c..82e4e05b1 100644 --- a/src/integration-test/groovy/pages/AdminReportsPage.groovy +++ b/src/integration-test/groovy/pages/AdminReportsPage.groovy @@ -12,8 +12,8 @@ class AdminReportsPage extends Page { period {$('select#reportPeriodOfManagementUnit',0)} downloadReportBtn(required:false) {$('a#muReportDownload')} downloadReportSummaryBtn(required:false) {$('a#muReportDownloadSummary')} - orgDownloadReportBtn(required:false) {$('a#muReportDownload')} - orgDownloadReportSummaryBtn(required:false) {$('a#muReportDownloadSummary')} + orgDownloadReportBtn(required:false) {$('a#orgReportDownload')} + orgDownloadReportSummaryBtn(required:false) {$('a#orgReportDownloadSummary')} showDownloadDetailsIcon(required:false) { $('i.showDownloadDetailsIcon')} muReportDownloadLink(required:false) {$('a#entityReportDownloadLink')} startDate{$("#muFromDate")} diff --git a/src/integration-test/resources/dataset3/loadDataSet.js b/src/integration-test/resources/dataset3/loadDataSet.js index 73e9cf333..5d06071e5 100644 --- a/src/integration-test/resources/dataset3/loadDataSet.js +++ b/src/integration-test/resources/dataset3/loadDataSet.js @@ -1514,4 +1514,24 @@ db.userPermission.insert({ entityId: "monitorProject", userId: '1', accessLevel: 'admin' -}); \ No newline at end of file +}); + +createOrganisation({ + name:'THE TRUSTEE FOR PSS FUND Test', + organisationId:'test_organisation', + status:'active', abn:'', + url:'http://www.ala.org.au', + acronym:'TSTORG', description:'THE TRUSTEE FOR PSS FUND Test' +}); +delete report1.projectId +var activityId = "activity2" +report1.organisationId = 'test_organisation'; +report1.activityId = activityId; +activity.activityId = activityId; +output.activityId = activityId; +outputSwan.activityId = activityId; + +db.report.insert(report1) +db.activity.insert(activity1) +db.output.insert(output); +db.output.insert(outputSwan) \ No newline at end of file diff --git a/src/main/scripts/runFunctionalTests.sh b/src/main/scripts/runFunctionalTests.sh index b52b2ea84..7ce9cd015 100755 --- a/src/main/scripts/runFunctionalTests.sh +++ b/src/main/scripts/runFunctionalTests.sh @@ -9,7 +9,7 @@ fi BRANCH=$3 if [ -z $BRANCH ]; then - BRANCH=feature/paratoo + BRANCH=feature/issue3004 fi ECODATA_LOCAL_DIR=$2