Skip to content

Commit

Permalink
Merge pull request #1047 from NHSDigital/SPINEDEM-3725-add-additional…
Browse files Browse the repository at this point in the history
…-datafields

Spinedem 3725 add additional gp reg data fields tests
  • Loading branch information
agelledi authored Sep 17, 2024
2 parents 8168674 + b8753aa commit a40bd4c
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 8 deletions.
4 changes: 4 additions & 0 deletions karate-tests/src/test/java/helpers/FakerWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public static String givenName() {
return faker.name().firstName();
}

public static String cityName() {
return faker.address().city();
}

}
2 changes: 1 addition & 1 deletion karate-tests/src/test/java/patients/TestParallel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void testDevParallel() {
.outputJunitXml(true)
.tags("~@sandbox-only", "~@smoke-only")
.karateEnv("veit07")
.parallel(5);
.parallel(3);
assertTrue(results.getFailCount() == 0, results.getErrorMessages());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@sandbox

Feature: Patch patient - Add and remove data

This feature tests adding data to a patient and then remove it.
We have extensive integration tests for the patch operations in TestBase scripts
in the spineii repo, so we aren't going for exhaustive testing here, but rather
illustrative tests that explain how to add and remove properties.
This feature tests adding data to a patient and then remove it.
We have extensive integration tests for the patch operations in TestBase scripts
in the spineii repo, so we aren't going for exhaustive testing here, but rather
illustrative tests that explain how to add and remove properties.

Background:
* def utils = call read('classpath:helpers/utils.feature')
Expand All @@ -22,6 +22,7 @@ Feature: Patch patient - Add and remove data
* def originalEtag = karate.response.header('etag')
* copy originalNameArray = response.name

@sandbox
Scenario: Add and remove patient data
* match response.name == "#[1]"

Expand Down Expand Up @@ -184,3 +185,59 @@ Feature: Patch patient - Add and remove data
* status 200
* match response.name[0].suffix == '#notpresent'
* match parseInt(response.meta.versionId) == originalVersion + 1


Scenario: Healthcare worker can add and remove place of birth details(city and district)
* def placeOfBirthNhsNumber = '5900077810'
* configure headers = call read('classpath:auth/auth-headers.js')
* path 'Patient', placeOfBirthNhsNumber
* method get
* status 200
* def originalVersion = parseInt(response.meta.versionId)

#add place of birth details

* configure headers = call read('classpath:auth/auth-headers.js')
* header Content-Type = "application/json-patch+json"
* header If-Match = karate.response.header('etag')
* path 'Patient', placeOfBirthNhsNumber
* def requestBody = read('classpath:patients/requestDetails/add/placeOfBirth.json')
* def placeOBirthUrl = requestBody.patches[0].value.url
* request requestBody
* method patch
* status 200
* def idAftPod = response.meta.versionId
* def pobDetails = response.extension.find(x => x.url == placeOBirthUrl)
# Test fails if the patient's place of birth details are not present in the record

* if (pobDetails == null) {karate.fail('No value found for place of Birth, stopping the test.')}
* def pobIndex = response.extension.findIndex(x => x.url == placeOBirthUrl)
* def pobPath = "/extension/" + pobIndex

# remove place of birth details

* configure headers = call read('classpath:auth/auth-headers.js')
* header Content-Type = "application/json-patch+json"
* header If-Match = karate.response.header('etag')
* path 'Patient', placeOfBirthNhsNumber
* request
"""
{
"patches": [
{
"op": "test",
"path": "#(pobPath)",
"value": "#(pobDetails)"
},
{
"op": "remove",
"path": "#(pobPath)"
}
]
}
"""
* method patch
* status 200
* match parseInt(response.meta.versionId) == parseInt(idAftPod)+ 1
* match response.extension[1] == '#notpresent'

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@sandbox

Feature: Patch patient - Replace data

Background:
* def utils = call read('classpath:helpers/utils.feature')
* def faker = Java.type('helpers.FakerWrapper')
* def accessToken = karate.callSingle('classpath:auth/auth-redirect.feature').accessToken
* url baseURL

@sandbox
Scenario: Replace attribute of an object
# To replace the attribute of an object, you need to provide the id of the object you want to replace
# in a preceding operation. (This is simlar to, but different from removing an object - we call
Expand Down Expand Up @@ -37,6 +39,7 @@ Feature: Patch patient - Replace data
* match response.name[0].given[0] == newGivenName
* match parseInt(response.meta.versionId) == originalVersion + 1

@sandbox
Scenario Outline: Replace the <property> property
# Unlike replacing a property that is an object, there's no need to make a
# preceding test operation
Expand All @@ -63,4 +66,164 @@ Feature: Patch patient - Replace data
Examples:
| nhsNumber | property | options! |
| 5900059243 | gender | ['male', 'female', 'unknown'] |
| 5900043320 | birthDate | ["1985-10-26", "1955-11-05"] |
| 5900043320 | birthDate | ["1985-10-26", "1955-11-05"] |

Scenario: Healthcare worker can add, update and remove patient's emergency contact details
* def nhsNumber = '5900079066'
* configure headers = call read('classpath:auth/auth-headers.js')
* path 'Patient', nhsNumber
* method get
* status 200
* def originalVersion = parseInt(response.meta.versionId)

# add emergency contact details
* configure headers = call read('classpath:auth/auth-headers.js')
* header Content-Type = "application/json-patch+json"
* header If-Match = karate.response.header('etag')
* path 'Patient', nhsNumber
* request read('classpath:patients/requestDetails/add/emergencyContact.json')
* method patch
* status 200
* def versionIdAftAdd = response.meta.versionId
* def contactDetails = response.contact
* match response contains {contact: '#notnull' }
* def relationshipDetails = contactDetails[0].relationship
* def contactId = contactDetails[0].id
* def indexToUpdate = response.contact.findIndex(x => x.id == contactId)
* def contactPathToUpdateAndRemove = "/contact/" + indexToUpdate

# update emergency contact
* configure headers = call read('classpath:auth/auth-headers.js')
* header Content-Type = "application/json-patch+json"
* header If-Match = karate.response.header('etag')
* def newMobileNumber = faker.phoneNumber()
* path 'Patient', nhsNumber
* request
"""
{
"patches":[
{"op":"replace",
"path":"#(contactPathToUpdateAndRemove)",
"value":{
"id": "#(contactId)",
"relationship":"#(relationshipDetails)",
"telecom":[
{"system":"phone",
"value":"#(newMobileNumber)"}
]}}]}
"""
* method patch
* status 200
* def updatedContact = response.contact.find(x => x.id == contactId)
* def telecomValue = updatedContact.telecom[0].value
* def versionIdAftUpdate = response.meta.versionId
* match parseInt(versionIdAftUpdate) == parseInt(versionIdAftAdd) + 1
* match telecomValue == newMobileNumber


# remove emergency contact details
* configure headers = call read('classpath:auth/auth-headers.js')
* header Content-Type = "application/json-patch+json"
* header If-Match = karate.response.header('etag')
* path 'Patient', nhsNumber

* def patchRequest =
"""
{
"patches": [
{
"op": "test",
"path": "#(contactPathToUpdateAndRemove)",
"value":"#(updatedContact)"
},
{
"op": "remove",
"path": "#(contactPathToUpdateAndRemove)"
}
]
}
"""
* request patchRequest
* method patch
* status 200
* def versionIdAftRemove = response.meta.versionId
* match parseInt(versionIdAftRemove) == parseInt(versionIdAftUpdate) + 1
Scenario: Healthcare worker can update communication language-interpreter details
* def nhsNumber = '5900071413'
* configure headers = call read('classpath:auth/auth-headers.js')
* path 'Patient', nhsNumber
* method get
* status 200
* def originalVersion = parseInt(response.meta.versionId)
* def commExtensionUrl = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-NHSCommunication"
* def commLanguageDtls = response.extension.find(x => x.url == commExtensionUrl)
# Test fails if the patient's communication details are present in the record

* if (commLanguageDtls == null) {karate.fail('No value found for communication Language, stopping the test.')}
* def interpreterDls = commLanguageDtls[1]
* def commLanguageindex = response.extension.findIndex(x => x.url == commExtensionUrl)
* def interpreterPath = "/extension/" + commLanguageindex + "/extension/1"
* def interpreter = response.extension[commLanguageindex].extension[1].valueBoolean
* def oppositeInterpreter = karate.eval('function getOppositeBoolean(value) { return !value; } getOppositeBoolean(' + karate.toString(interpreter) + ')')

# update comminication language interpreter required details
* configure headers = call read('classpath:auth/auth-headers.js')
* header Content-Type = "application/json-patch+json"
* header If-Match = karate.response.header('etag')
* path 'Patient', nhsNumber
* request
"""
{
"patches":[
{"op":"replace",
"path":"#(interpreterPath)",
"value": {
"url": "interpreterRequired",
"valueBoolean": "#(oppositeInterpreter)"
}
}]}
"""
* method patch
* status 200
* match parseInt(response.meta.versionId) == originalVersion + 1

Scenario: Send empty field on the update - interpreterRequired url is empty
* def nhsNumber = '5900076067'
* configure headers = call read('classpath:auth/auth-headers.js')
* path 'Patient', nhsNumber
* method get
* status 200
* def originalVersion = parseInt(response.meta.versionId)
* def commExtensionUrl = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-NHSCommunication"
* def commLanguageDtls = response.extension.find(x => x.url == commExtensionUrl)
# Test fails if the patient's communication language details are present in the record

* if (commLanguageDtls == null) {karate.fail('No value found for NHS communication, stopping the test.')}
* def interpreterDls = commLanguageDtls[1]
* def commLanguageindex = response.extension.findIndex(x => x.url == commExtensionUrl)
* def interpreterPath = "/extension/" + commLanguageindex + "/extension/1"
* def interpreter = response.extension[commLanguageindex].extension[1].valueBoolean
* def oppositeInterpreter = karate.eval('function getOppositeBoolean(value) { return !value; } getOppositeBoolean(' + karate.toString(interpreter) + ')')

# Empty value on the patch
* configure headers = call read('classpath:auth/auth-headers.js')
* header Content-Type = "application/json-patch+json"
* header If-Match = karate.response.header('etag')
* path 'Patient', nhsNumber
* request
"""
{
"patches":[
{"op":"replace",
"path":"#(interpreterPath)",
"value": {
"url": " ",
"valueBoolean": "#(oppositeInterpreter)"
}
}]}
"""
* method patch
* status 400
* def display = 'Patient cannot perform this action'
* def diagnostics = "Invalid update with error - interpreterRequired cannot be removed"
* match response == read('classpath:mocks/stubs/errorResponses/INVALID_UPDATE.json')
Loading

0 comments on commit a40bd4c

Please sign in to comment.