-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow adding participants by username to recruitments
This includes a `RecruitmentService` API upgrade and a migration to convert `RecruitmentService.AddParticipant` requests into `RecruitmentService.AddParticipantByEmailAddress` requests.
- Loading branch information
1 parent
bb9ff20
commit 5d3ee7c
Showing
30 changed files
with
2,217 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 27 additions & 1 deletion
28
.../kotlin/dk/cachet/carp/studies/infrastructure/versioning/RecruitmentServiceApiMigrator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,40 @@ | ||
package dk.cachet.carp.studies.infrastructure.versioning | ||
|
||
import dk.cachet.carp.common.application.services.ApiVersion | ||
import dk.cachet.carp.common.infrastructure.versioning.ApiMigration | ||
import dk.cachet.carp.common.infrastructure.versioning.ApiResponse | ||
import dk.cachet.carp.common.infrastructure.versioning.ApplicationServiceApiMigrator | ||
import dk.cachet.carp.studies.application.RecruitmentService | ||
import dk.cachet.carp.studies.infrastructure.RecruitmentServiceInvoker | ||
import dk.cachet.carp.studies.infrastructure.RecruitmentServiceRequest | ||
import kotlinx.serialization.json.JsonObject | ||
|
||
|
||
const val recruitmentRequest = "dk.cachet.carp.studies.infrastructure.RecruitmentServiceRequest" | ||
|
||
private val major1Minor0To2Migration = | ||
object : ApiMigration( 0, 2 ) | ||
{ | ||
override fun migrateRequest( request: JsonObject ): JsonObject = request.migrate { | ||
ifType( "$recruitmentRequest.AddParticipant" ) | ||
{ | ||
changeType( "$recruitmentRequest.AddParticipantByEmailAddress" ) | ||
} | ||
} | ||
|
||
override fun migrateResponse( | ||
request: JsonObject, | ||
response: ApiResponse, | ||
targetVersion: ApiVersion | ||
): ApiResponse = response | ||
|
||
override fun migrateEvent( event: JsonObject ): JsonObject = event | ||
} | ||
|
||
val RecruitmentServiceApiMigrator = ApplicationServiceApiMigrator( | ||
RecruitmentService.API_VERSION, | ||
RecruitmentServiceInvoker, | ||
RecruitmentServiceRequest.Serializer, | ||
RecruitmentService.Event.serializer() | ||
RecruitmentService.Event.serializer(), | ||
listOf( major1Minor0To2Migration ) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import dk.cachet.carp.common.application.users.AssignedTo | |
import dk.cachet.carp.common.application.users.ExpectedParticipantData | ||
import dk.cachet.carp.common.application.users.ParticipantAttribute | ||
import dk.cachet.carp.common.application.users.ParticipantRole | ||
import dk.cachet.carp.common.application.users.Username | ||
import dk.cachet.carp.protocols.application.StudyProtocolSnapshot | ||
import dk.cachet.carp.protocols.domain.StudyProtocol | ||
import dk.cachet.carp.studies.application.users.AssignedParticipantRoles | ||
|
@@ -41,20 +42,21 @@ interface RecruitmentServiceTest | |
|
||
|
||
@Test | ||
fun adding_and_retrieving_participant_succeeds() = runTest { | ||
fun adding_and_retrieving_participants_succeeds() = runTest { | ||
val (recruitmentService, studyService) = createSUT() | ||
val study = studyService.createStudy( UUID.randomUUID(), "Test" ) | ||
val studyId = study.studyId | ||
|
||
val participant = recruitmentService.addParticipant( studyId, EmailAddress( "[email protected]" ) ) | ||
val emailParticipant = recruitmentService.addParticipant( studyId, EmailAddress( "[email protected]" ) ) | ||
val usernameParticipant = recruitmentService.addParticipant( studyId, Username( "test" ) ) | ||
|
||
// Get single participant. | ||
val studyParticipant = recruitmentService.getParticipant( studyId, participant.id ) | ||
assertEquals( participant, studyParticipant ) | ||
// Get participants by ID. | ||
assertEquals( emailParticipant, recruitmentService.getParticipant( studyId, emailParticipant.id ) ) | ||
assertEquals( usernameParticipant, recruitmentService.getParticipant( studyId, usernameParticipant.id ) ) | ||
|
||
// Get all participants. | ||
val studyParticipants = recruitmentService.getParticipants( studyId ) | ||
assertEquals( participant, studyParticipants.single() ) | ||
assertEquals( setOf( emailParticipant, usernameParticipant ), studyParticipants.toSet() ) | ||
} | ||
|
||
@Test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package dk.cachet.carp.studies.infrastructure | |
|
||
import dk.cachet.carp.common.application.EmailAddress | ||
import dk.cachet.carp.common.application.UUID | ||
import dk.cachet.carp.common.application.users.Username | ||
import dk.cachet.carp.common.test.infrastructure.ApplicationServiceDecoratorTest | ||
import dk.cachet.carp.common.test.infrastructure.ApplicationServiceRequestsTest | ||
import dk.cachet.carp.studies.application.RecruitmentService | ||
|
@@ -19,7 +20,8 @@ class RecruitmentServiceRequestsTest : ApplicationServiceRequestsTest<Recruitmen | |
private val studyId = UUID.randomUUID() | ||
|
||
val REQUESTS: List<RecruitmentServiceRequest<*>> = listOf( | ||
RecruitmentServiceRequest.AddParticipant( studyId, EmailAddress( "[email protected]" ) ), | ||
RecruitmentServiceRequest.AddParticipantByEmailAddress( studyId, EmailAddress( "[email protected]" ) ), | ||
RecruitmentServiceRequest.AddParticipantByUsername( studyId, Username( "test" ) ), | ||
RecruitmentServiceRequest.GetParticipant( studyId, UUID.randomUUID() ), | ||
RecruitmentServiceRequest.GetParticipants( studyId ), | ||
RecruitmentServiceRequest.InviteNewParticipantGroup( studyId, setOf() ), | ||
|
16 changes: 16 additions & 0 deletions
16
...ce/1.2/RecruitmentServiceTest/addParticipantByEmailAddress_fails_for_unknown_studyId.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[ | ||
{ | ||
"outcome": "Failed", | ||
"request": { | ||
"__type": "dk.cachet.carp.studies.infrastructure.RecruitmentServiceRequest.AddParticipantByEmailAddress", | ||
"apiVersion": "1.1", | ||
"studyId": "1bd9db94-50a4-409e-a189-ef3bd2ec4bee", | ||
"email": "[email protected]" | ||
}, | ||
"precedingEvents": [ | ||
], | ||
"publishedEvents": [ | ||
], | ||
"exceptionType": "IllegalArgumentException" | ||
} | ||
] |
58 changes: 58 additions & 0 deletions
58
...2/RecruitmentServiceTest/addParticipantByEmailAddress_twice_returns_same_participant.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
[ | ||
{ | ||
"outcome": "Succeeded", | ||
"request": { | ||
"__type": "dk.cachet.carp.studies.infrastructure.RecruitmentServiceRequest.AddParticipantByEmailAddress", | ||
"apiVersion": "1.1", | ||
"studyId": "00000000-0000-0000-0000-000000000001", | ||
"email": "[email protected]" | ||
}, | ||
"precedingEvents": [ | ||
{ | ||
"__type": "dk.cachet.carp.studies.application.StudyService.Event.StudyCreated", | ||
"aggregateId": "00000000-0000-0000-0000-000000000001", | ||
"apiVersion": "1.1", | ||
"study": { | ||
"studyId": "00000000-0000-0000-0000-000000000001", | ||
"ownerId": "8b538dc7-edb3-4365-9fdc-819daba1485d", | ||
"name": "Test", | ||
"createdOn": "1970-01-01T00:00:00Z", | ||
"description": null, | ||
"invitation": { | ||
"name": "Test" | ||
}, | ||
"protocolSnapshot": null | ||
} | ||
} | ||
], | ||
"publishedEvents": [ | ||
], | ||
"response": { | ||
"accountIdentity": { | ||
"__type": "dk.cachet.carp.common.application.users.EmailAccountIdentity", | ||
"emailAddress": "[email protected]" | ||
}, | ||
"id": "00000000-0000-0000-0000-000000000002" | ||
} | ||
}, | ||
{ | ||
"outcome": "Succeeded", | ||
"request": { | ||
"__type": "dk.cachet.carp.studies.infrastructure.RecruitmentServiceRequest.AddParticipantByEmailAddress", | ||
"apiVersion": "1.1", | ||
"studyId": "00000000-0000-0000-0000-000000000001", | ||
"email": "[email protected]" | ||
}, | ||
"precedingEvents": [ | ||
], | ||
"publishedEvents": [ | ||
], | ||
"response": { | ||
"accountIdentity": { | ||
"__type": "dk.cachet.carp.common.application.users.EmailAccountIdentity", | ||
"emailAddress": "[email protected]" | ||
}, | ||
"id": "00000000-0000-0000-0000-000000000002" | ||
} | ||
} | ||
] |
Oops, something went wrong.