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..6734c2759 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,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 @@ -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() 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..23c98b2f0 --- /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,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" + } + } + ] + } + } +] \ No newline at end of file