Skip to content

Commit

Permalink
Merge branch 'develop' into web-browser-device-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
xelahalo committed Mar 12, 2024
2 parents 1443b1b + bdf4186 commit 57d30cc
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
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.SelectOne
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 +37,28 @@ 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 ssn = Text("Social Security Number" )
val customText = ParticipantAttribute.CustomParticipantAttribute( ssn )
protocol.addExpectedParticipantData( ExpectedParticipantData( customText ) )

val os = SelectOne( "Favorite OS", setOf( "Windows", "Linux", "Mac" ) )
val customSelectOne = ParticipantAttribute.CustomParticipantAttribute( os )
protocol.addExpectedParticipantData( ExpectedParticipantData( customSelectOne ) )

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,109 @@
[
{
"outcome": "Succeeded",
"request": {
"__type": "dk.cachet.carp.protocols.infrastructure.ProtocolServiceRequest.Add",
"apiVersion": "1.1",
"protocol": {
"id": "0d57f923-955e-4693-a606-cca9651aab4a",
"createdOn": "2023-12-10T18:51:39.511538600Z",
"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.a1eda4bcd0d84ca0ba446cabfa4e84c8"
}
},
{
"attribute": {
"__type": "dk.cachet.carp.common.application.users.ParticipantAttribute.CustomParticipantAttribute",
"input": {
"__type": "dk.cachet.carp.common.application.data.input.elements.SelectOne",
"prompt": "Favorite OS",
"options": [
"Windows",
"Linux",
"Mac"
]
},
"inputDataType": "dk.cachet.carp.input.custom.4ee5a0cc0ce5462b94baee4e59415f9b"
}
}
]
}
},
"precedingEvents": [
],
"publishedEvents": [
],
"response": {
}
},
{
"outcome": "Succeeded",
"request": {
"__type": "dk.cachet.carp.protocols.infrastructure.ProtocolServiceRequest.GetBy",
"apiVersion": "1.1",
"protocolId": "0d57f923-955e-4693-a606-cca9651aab4a"
},
"precedingEvents": [
],
"publishedEvents": [
],
"response": {
"id": "0d57f923-955e-4693-a606-cca9651aab4a",
"createdOn": "2023-12-10T18:51:39.511538600Z",
"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.a1eda4bcd0d84ca0ba446cabfa4e84c8"
}
},
{
"attribute": {
"__type": "dk.cachet.carp.common.application.users.ParticipantAttribute.CustomParticipantAttribute",
"input": {
"__type": "dk.cachet.carp.common.application.data.input.elements.SelectOne",
"prompt": "Favorite OS",
"options": [
"Windows",
"Linux",
"Mac"
]
},
"inputDataType": "dk.cachet.carp.input.custom.4ee5a0cc0ce5462b94baee4e59415f9b"
}
}
]
}
}
]

0 comments on commit 57d30cc

Please sign in to comment.