Skip to content

Commit

Permalink
Add custom participant attribute API backwards compatibilty test
Browse files Browse the repository at this point in the history
Currently, there was no coverage for adding custom participant attributes to protocols in the backwards compatibility tests. The test resource also serves as an example on how such a JSON request looks like.
  • Loading branch information
Whathecode committed Dec 10, 2023
1 parent 1d0d2df commit c03ecea
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dk.cachet.carp.protocols.application

import dk.cachet.carp.common.application.UUID
import dk.cachet.carp.common.application.data.input.CarpInputDataTypes
import dk.cachet.carp.common.application.data.input.InputDataType
import dk.cachet.carp.common.application.data.input.elements.Text
import dk.cachet.carp.common.application.triggers.TaskControl
import dk.cachet.carp.common.application.users.ExpectedParticipantData
import dk.cachet.carp.common.application.users.ParticipantAttribute
Expand Down Expand Up @@ -34,6 +36,22 @@ interface ProtocolServiceTest
assertEquals( snapshot, retrieved )
}

@Test
fun add_protocol_with_expected_participant_data_succeeds() = runTest {
val service = createService()
val protocol = createEmptyProtocol()

val sex = ParticipantAttribute.DefaultParticipantAttribute(CarpInputDataTypes.SEX)
protocol.addExpectedParticipantData(ExpectedParticipantData(sex))
val customInput = ParticipantAttribute.CustomParticipantAttribute(Text("Social Security Number"))
protocol.addExpectedParticipantData(ExpectedParticipantData(customInput))
val snapshot = protocol.getSnapshot()

service.add( snapshot )
val retrieved = service.getBy( protocol.id )
assertEquals( snapshot, retrieved )
}

@Test
fun add_fails_when_protocol_already_exists() = runTest {
val service = createService()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[
{
"outcome": "Succeeded",
"request": {
"__type": "dk.cachet.carp.protocols.infrastructure.ProtocolServiceRequest.Add",
"apiVersion": "1.1",
"protocol": {
"id": "b2e7a95f-1cf2-4f25-9671-d3cd5eeaae1c",
"createdOn": "2023-12-10T18:30:52.775778700Z",
"version": 0,
"ownerId": "27879e75-ccc1-4866-9ab3-4ece1b735052",
"name": "Test protocol",
"description": "Test description",
"expectedParticipantData": [
{
"attribute": {
"__type": "dk.cachet.carp.common.application.users.ParticipantAttribute.DefaultParticipantAttribute",
"inputDataType": "dk.cachet.carp.input.sex"
}
},
{
"attribute": {
"__type": "dk.cachet.carp.common.application.users.ParticipantAttribute.CustomParticipantAttribute",
"input": {
"__type": "dk.cachet.carp.common.application.data.input.elements.Text",
"prompt": "Social Security Number"
},
"inputDataType": "dk.cachet.carp.input.custom.6dc4b930d73c45cd8c7017f9fd823fe6"
}
}
]
}
},
"precedingEvents": [
],
"publishedEvents": [
],
"response": {
}
},
{
"outcome": "Succeeded",
"request": {
"__type": "dk.cachet.carp.protocols.infrastructure.ProtocolServiceRequest.GetBy",
"apiVersion": "1.1",
"protocolId": "b2e7a95f-1cf2-4f25-9671-d3cd5eeaae1c"
},
"precedingEvents": [
],
"publishedEvents": [
],
"response": {
"id": "b2e7a95f-1cf2-4f25-9671-d3cd5eeaae1c",
"createdOn": "2023-12-10T18:30:52.775778700Z",
"version": 0,
"ownerId": "27879e75-ccc1-4866-9ab3-4ece1b735052",
"name": "Test protocol",
"description": "Test description",
"expectedParticipantData": [
{
"attribute": {
"__type": "dk.cachet.carp.common.application.users.ParticipantAttribute.DefaultParticipantAttribute",
"inputDataType": "dk.cachet.carp.input.sex"
}
},
{
"attribute": {
"__type": "dk.cachet.carp.common.application.users.ParticipantAttribute.CustomParticipantAttribute",
"input": {
"__type": "dk.cachet.carp.common.application.data.input.elements.Text",
"prompt": "Social Security Number"
},
"inputDataType": "dk.cachet.carp.input.custom.6dc4b930d73c45cd8c7017f9fd823fe6"
}
}
]
}
}
]

0 comments on commit c03ecea

Please sign in to comment.