Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CoJ receivedFromTis #380

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "uk.nhs.hee.trainee.details"
version = "0.31.0"
version = "0.32.0"

configurations {
compileOnly {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
*
* @param signedAt When the Conditions of Joining were signed.
* @param version The Gold Guide version of the Conditions of Joining.
* @param syncedAt When the saved Conditions of Joining was synced from TIS.
*/
public record ConditionsOfJoiningDto(Instant signedAt, GoldGuideVersion version) {
public record ConditionsOfJoiningDto(Instant signedAt, GoldGuideVersion version,
Instant syncedAt) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
*
* @param signedAt When the Conditions of Joining were signed.
* @param version The Gold Guide version of the Conditions of Joining.
* @param syncedAt When the saved Conditions of Joining was synced from TIS.
*/
public record ConditionsOfJoining(Instant signedAt, GoldGuideVersion version) implements
public record ConditionsOfJoining(Instant signedAt, GoldGuideVersion version,
Instant syncedAt) implements
Serializable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public Optional<ProgrammeMembership> signProgrammeMembershipCoj(
for (ProgrammeMembership existingProgrammeMembership : existingProgrammeMemberships) {
if (existingProgrammeMembership.getTisId().equals(programmeMembershipId)) {
ConditionsOfJoining conditionsOfJoining =
new ConditionsOfJoining(Instant.now(), GoldGuideVersion.getLatest());
new ConditionsOfJoining(Instant.now(), GoldGuideVersion.getLatest(), null);
Copy link
Contributor Author

@ReubenRobertsHEE ReubenRobertsHEE Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the syncedAt' value to null here is because the CoJ has just been signed; the complete record with that value set will be received from trainee-sync once it's been saved into TCS.

existingProgrammeMembership.setConditionsOfJoining(conditionsOfJoining);
repository.save(traineeProfile);
return Optional.of(existingProgrammeMembership);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public TraineeProfile getTraineeProfileByTraineeTisId(String traineeTisId) {
}

// Set latest CoJ version if not already signed.
ConditionsOfJoining coj = new ConditionsOfJoining(null, GoldGuideVersion.getLatest());
ConditionsOfJoining coj = new ConditionsOfJoining(null, GoldGuideVersion.getLatest(), null);

traineeProfile.getProgrammeMemberships().stream()
.filter(pm -> pm.getConditionsOfJoining() == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void shouldSignCojWhenTraineePmFound() throws Exception {
programmeMembership.setProgrammeName("programmeNameValue");
programmeMembership.setProgrammeNumber("programmeNumberValue");
programmeMembership.setConditionsOfJoining(
new ConditionsOfJoining(signedAt, GoldGuideVersion.getLatest()));
new ConditionsOfJoining(signedAt, GoldGuideVersion.getLatest(), null));

when(service.signProgrammeMembershipCoj("tisIdValue", "40"))
.thenReturn(Optional.of(programmeMembership));
Expand All @@ -311,6 +311,8 @@ void shouldSignCojWhenTraineePmFound() throws Exception {
.andExpect(jsonPath("$.programmeNumber").value(is("programmeNumberValue")))
.andExpect(jsonPath("$.conditionsOfJoining.signedAt").value(is(signedAt.toString())))
.andExpect(jsonPath("$.conditionsOfJoining.version")
.value(is(GoldGuideVersion.GG9.toString())));
.value(is(GoldGuideVersion.GG9.toString())))
.andExpect(jsonPath("$.conditionsOfJoining.syncedAt")
.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class TraineeProfileResourceTest {
private static final String PLACEMENT_SITE = "Addenbrookes Hospital";
private static final Status PLACEMENT_STATUS = Status.CURRENT;
private static final Instant NOW = Instant.now();
private static final Instant COJ_SYNCED_AT = Instant.MAX;

@Autowired
private MappingJackson2HttpMessageConverter jacksonMessageConverter;
Expand Down Expand Up @@ -204,7 +205,8 @@ void setupProgrammeMembershipsData() {
programmeMembership.setProgrammeName(PROGRAMME_NAME);
programmeMembership.setProgrammeNumber(PROGRAMME_NUMBER);
programmeMembership.setCurricula(List.of(curriculum));
programmeMembership.setConditionsOfJoining(new ConditionsOfJoining(NOW, GoldGuideVersion.GG9));
programmeMembership.setConditionsOfJoining(
new ConditionsOfJoining(NOW, GoldGuideVersion.GG9, COJ_SYNCED_AT));
}

/**
Expand Down Expand Up @@ -327,6 +329,9 @@ void getShouldReturnTraineeProfileWhenTisIdExists() throws Exception {
NOW.toString()))
.andExpect(jsonPath("$.programmeMemberships[*].conditionsOfJoining.version").value(
GoldGuideVersion.GG9.toString()))
.andExpect(
jsonPath("$.programmeMemberships[*].conditionsOfJoining.syncedAt")
.value(COJ_SYNCED_AT.toString()))
.andExpect(jsonPath("$.programmeMemberships[*].signature.hmac").value(signature.getHmac()))
.andExpect(jsonPath("$.programmeMemberships[*].signature.signedAt")
.value(signature.getSignedAt().toString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ void shouldReturnEmptyConditionsOfJoiningWhenNotCached() {
void shouldReturnCachedConditionsOfJoiningAfterCaching() {
String key = UUID.randomUUID().toString();

ConditionsOfJoining coj = new ConditionsOfJoining(Instant.now(), GoldGuideVersion.GG9);
ConditionsOfJoining coj
= new ConditionsOfJoining(Instant.now(), GoldGuideVersion.GG9, Instant.now());
ConditionsOfJoining cachedCoj = delegate.cacheConditionsOfJoining(key, coj);
assertThat("Unexpected cached value.", cachedCoj, is(coj));
}
Expand All @@ -72,7 +73,8 @@ void shouldReturnCachedConditionsOfJoiningAfterCaching() {
void shouldGetCachedConditionsOfJoiningWhenCached() {
String key = UUID.randomUUID().toString();

ConditionsOfJoining coj = new ConditionsOfJoining(Instant.now(), GoldGuideVersion.GG9);
ConditionsOfJoining coj
= new ConditionsOfJoining(Instant.now(), GoldGuideVersion.GG9, Instant.now());
delegate.cacheConditionsOfJoining(key, coj);

Optional<ConditionsOfJoining> cachedOptional = delegate.getConditionsOfJoining(key);
Expand All @@ -83,7 +85,8 @@ void shouldGetCachedConditionsOfJoiningWhenCached() {
void shouldRemoveConditionsOfJoiningWhenRetrieved() {
String key = UUID.randomUUID().toString();

ConditionsOfJoining coj = new ConditionsOfJoining(Instant.now(), GoldGuideVersion.GG9);
ConditionsOfJoining coj
= new ConditionsOfJoining(Instant.now(), GoldGuideVersion.GG9, Instant.now());
delegate.cacheConditionsOfJoining(key, coj);

// Ignore this result, the cached value should be evicted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ void setUp() {

@Test
void shouldReturnCachedConditionsOfJoining() {
ConditionsOfJoining cachedCoj = new ConditionsOfJoining(Instant.now(), GoldGuideVersion.GG9);
ConditionsOfJoining cachedCoj
= new ConditionsOfJoining(Instant.now(), GoldGuideVersion.GG9, Instant.now());
ConditionsOfJoining returnedCoj = delegate.cacheConditionsOfJoining("40", cachedCoj);
assertThat("Unexpected Conditions of Joining.", cachedCoj, is(returnedCoj));
}
Expand Down
Loading
Loading