diff --git a/carp.protocols.core/src/commonTest/kotlin/dk/cachet/carp/protocols/application/ProtocolServiceTest.kt b/carp.protocols.core/src/commonTest/kotlin/dk/cachet/carp/protocols/application/ProtocolServiceTest.kt index e8d7812e3..5f493b94e 100644 --- a/carp.protocols.core/src/commonTest/kotlin/dk/cachet/carp/protocols/application/ProtocolServiceTest.kt +++ b/carp.protocols.core/src/commonTest/kotlin/dk/cachet/carp/protocols/application/ProtocolServiceTest.kt @@ -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 @@ -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() diff --git a/carp.protocols.core/src/commonTest/resources/test-requests/ProtocolService/1.1/ProtocolServiceTest/add_protocol_with_expected_participant_data_succeeds.json b/carp.protocols.core/src/commonTest/resources/test-requests/ProtocolService/1.1/ProtocolServiceTest/add_protocol_with_expected_participant_data_succeeds.json new file mode 100644 index 000000000..a60d0cddf --- /dev/null +++ b/carp.protocols.core/src/commonTest/resources/test-requests/ProtocolService/1.1/ProtocolServiceTest/add_protocol_with_expected_participant_data_succeeds.json @@ -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" + } + } + ] + } + } +] \ No newline at end of file