Skip to content

Commit

Permalink
Functional test for paratoo integration #2971
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Aug 30, 2023
1 parent beb14f3 commit 2f81cc6
Show file tree
Hide file tree
Showing 8 changed files with 1,651 additions and 7 deletions.
6 changes: 4 additions & 2 deletions grails-app/controllers/au/org/ala/merit/SiteController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ class SiteController {
def geojson(String id) {
Map site = siteService.get(id)
if (!site) {
respond status:HttpStatus.SC_NOT_FOUND
Map resp = [status:HttpStatus.SC_NOT_FOUND]
render resp as JSON
return
}
if (!isUserMemberOfSiteProjects(site)) {
respond status:HttpStatus.SC_UNAUTHORIZED
Map resp = [status:HttpStatus.SC_UNAUTHORIZED]
render resp as JSON
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package au.org.ala.fieldcapture

import au.org.ala.ws.service.WebService
import org.apache.http.entity.ContentType
import org.grails.testing.GrailsUnitTest
import org.apache.http.HttpStatus
import spock.lang.Stepwise
import pages.RlpProjectPage

@Stepwise
// We need GrailsUnitTest because the WebService class has a dependency on grailsApplication.config
// It slows startup down quite a bit though
class ParatooIntegrationSpec extends StubbedCasSpec implements GrailsUnitTest {

WebService webService

def setupSpec(){
useDataSet("dataset3")
}

def cleanupSpec() {
logout(browser)
}

def setup() {
webService = new WebService(grailsApplication: getGrailsApplication())
}


def "Add new data set in to project"() {

setup:
String token = tokenForUser('1')
Map mintCollectionIdPayload = [
projectId:'monitorProject',
protocol: [
id: 2, // Protocol 23 used to obtain representative data for this functional test
version: 1
],
surveyId: [
surveyType: 'soil-pit-characterisation-full',
time: '2023-08-28T00:34:13.100Z',
randNum: 46390249
]
]
Map collectionPayload = [
projectId:'monitorProject',
protocol: [
id: 2,
version: 1
],
userId: '1',
eventTime:'2023-08-28T00:28:15.272Z'
]

when:
String url = testConfig.ecodata.baseUrl+'paratoo/mintCollectionId'
Map headers = ["Authorization": "Bearer ${token}"]
Map resp = webService.post(url, mintCollectionIdPayload, null, ContentType.APPLICATION_JSON, false, false, headers)

String orgMintedIdentifier = resp.resp.orgMintedIdentifier

then:
resp.statusCode == HttpStatus.SC_OK

orgMintedIdentifier != null

when:
collectionPayload.mintedCollectionId = orgMintedIdentifier
url = testConfig.ecodata.baseUrl+'/paratoo/collection'
resp = webService.post(url, collectionPayload, null, ContentType.APPLICATION_JSON, false, false, headers)

then:
resp.statusCode == HttpStatus.SC_OK
resp.resp.success == true



}


def "Data from monitor will be used to create a data set summary in MERIT"() {
when: "We view the created data set in the project"
loginAsUser('1', browser)
to RlpProjectPage, "monitorProject"
openDataSetSummaryTab()

then: "The data set is displayed"
datasetDetails.dataSetSummaryCount() == 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class StubbedCasSpec extends FieldcaptureFunctionalTest {

def oidcLogin(Map userDetails, Browser browser) {
setupOidcAuthForUser(userDetails)
browser.go "${getConfig().baseUrl}login"
browser.go "${browser.getConfig().baseUrl}login"
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/integration-test/resources/data_common/insertData.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,23 @@ function loadActivityForms() {
"type":"EMSA",
"category":"Category 1",
"externalId": NumberInt(1),
"external":true,
"formVersion": NumberInt(1),
"publicationStatus":"published"
}, {
"name": "Protocol 2",
"type":"EMSA",
"category":"Category 2",
"externalId": NumberInt(2),

"external":true,
"formVersion": NumberInt(1),
"publicationStatus":"published"
}, {
"name": "Protocol 3",
"type":"EMSA",
"category":"Category 3",
"externalId": NumberInt(3),
"external":true,
"formVersion": NumberInt(1),
"publicationStatus":"published"

Expand Down
27 changes: 25 additions & 2 deletions src/integration-test/resources/dataset3/loadDataSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,13 +1475,36 @@ config.priorityPlaces = [
"Priority place 3"
];
config.excludeFinancialYearData = false;

config.supportsParatoo = true;
createProgram({programId: "outcomeMeriPlan", name: "Outcome MERI Plan", description: "", config: config});
createProject({projectId: "outcomeMeriPlanProject", name: "Outcome MERI Plan project", programId: "outcomeMeriPlan"});

db.userPermission.insert({
entityType: 'au.org.ala.ecodata.Project',
entityId: "outcomeMeriPlanProject",
userId: '1',
accessLevel: 'admin'
});
const monitorProject = {
projectId: "monitorProject",
name: "Testing monitor integration",
programId: "outcomeMeriPlan",
custom: {
details: {
baseline: {
rows: [
{
protocols:['Category 1', 'Category 2']
}
]
}
}
}
};

createProject(monitorProject);
db.userPermission.insert({
entityType: 'au.org.ala.ecodata.Project',
entityId: "monitorProject",
userId: '1',
accessLevel: 'admin'
});
108 changes: 108 additions & 0 deletions src/integration-test/resources/wiremock/mappings/monitorProtocol2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"request": {
"urlPath": "/monitor/protocols/2",
"method": "GET"
},
"response": {
"status": 200,
"headers": {
"content-Type": "application/json"
},
"jsonBody": {
"data": {
"id": 2,
"attributes": {
"identifier": "068d17e8-e042-ae42-1e42-d004fa2ef759",
"name": "Soil Site Observation and Pit Characterisation",
"module": "Soils",
"endpointPrefix": "/soil-pit-characterisation-fulls",
"version": 1,
"description": "",
"isWritable": true,
"workflow": [
{
"modelName": "plot-layout"
},
{
"modelName": "plot-visit"
},
{
"modelName": "soil-pit-characterisation-full",
"overrideDisplayName": "Soil Pit Location",
"usesCustomComponent": true
},
{
"modelName": "soil-landform-element",
"overrideDisplayName": "Land Form Element",
"usesCustomComponent": true
},
{
"modelName": "soil-land-surface-phenomena",
"overrideDisplayName": "Land Surface Phenomena & Soil Development",
"usesCustomComponent": true
},
{
"multiple": true,
"required": false,
"modelName": "microrelief-observation",
"defaultHidden": true,
"usesCustomComponent": true
},
{
"multiple": true,
"required": false,
"modelName": "erosion-observation",
"defaultHidden": true,
"usesCustomComponent": true
},
{
"multiple": true,
"required": false,
"modelName": "surface-coarse-fragments-observation",
"defaultHidden": true
},
{
"required": false,
"modelName": "rock-outcrop-observation",
"defaultHidden": true
},
{
"modelName": "soil-pit-observation"
},
{
"multiple": true,
"modelName": "soil-horizon-observation",
"usesCustomComponent": true,
"newInstanceForRelationOnAttributes": [
"mottles",
"coarse_fragments",
"structure",
"segregation",
"voids",
"pans",
"cutans",
"roots"
]
},
{
"modelName": "soil-classification",
"newInstanceForRelationOnAttributes": [
"asc"
]
},
{
"multiple": true,
"modelName": "soil-horizon-sample",
"usesCustomComponent": true
}
],
"isHidden": false,
"next_prot_suggestion": "068d17e8-e042-ae42-1e42-d0065d7ec2e4",
"createdAt": "2023-08-16T02:59:43.946Z",
"updatedAt": "2023-08-16T02:59:43.946Z"
}
},
"meta": {}
}
}
}
Loading

0 comments on commit 2f81cc6

Please sign in to comment.