diff --git a/build.gradle b/build.gradle index 5126e367..d19c3302 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ plugins { } group = "uk.nhs.hee.trainee.details" -version = "0.31.0" +version = "0.32.0" configurations { compileOnly { diff --git a/src/main/java/uk/nhs/hee/trainee/details/dto/ConditionsOfJoiningDto.java b/src/main/java/uk/nhs/hee/trainee/details/dto/ConditionsOfJoiningDto.java index cae66d8e..4886f919 100644 --- a/src/main/java/uk/nhs/hee/trainee/details/dto/ConditionsOfJoiningDto.java +++ b/src/main/java/uk/nhs/hee/trainee/details/dto/ConditionsOfJoiningDto.java @@ -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) { } diff --git a/src/main/java/uk/nhs/hee/trainee/details/model/ConditionsOfJoining.java b/src/main/java/uk/nhs/hee/trainee/details/model/ConditionsOfJoining.java index e3e71c71..5713be29 100644 --- a/src/main/java/uk/nhs/hee/trainee/details/model/ConditionsOfJoining.java +++ b/src/main/java/uk/nhs/hee/trainee/details/model/ConditionsOfJoining.java @@ -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 { } diff --git a/src/main/java/uk/nhs/hee/trainee/details/service/ProgrammeMembershipService.java b/src/main/java/uk/nhs/hee/trainee/details/service/ProgrammeMembershipService.java index 048ec40c..d34f284f 100644 --- a/src/main/java/uk/nhs/hee/trainee/details/service/ProgrammeMembershipService.java +++ b/src/main/java/uk/nhs/hee/trainee/details/service/ProgrammeMembershipService.java @@ -220,7 +220,7 @@ public Optional 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); existingProgrammeMembership.setConditionsOfJoining(conditionsOfJoining); repository.save(traineeProfile); return Optional.of(existingProgrammeMembership); diff --git a/src/main/java/uk/nhs/hee/trainee/details/service/TraineeProfileService.java b/src/main/java/uk/nhs/hee/trainee/details/service/TraineeProfileService.java index 875673bb..e5845dfd 100644 --- a/src/main/java/uk/nhs/hee/trainee/details/service/TraineeProfileService.java +++ b/src/main/java/uk/nhs/hee/trainee/details/service/TraineeProfileService.java @@ -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 diff --git a/src/test/java/uk/nhs/hee/trainee/details/api/ProgrammeMembershipResourceTest.java b/src/test/java/uk/nhs/hee/trainee/details/api/ProgrammeMembershipResourceTest.java index e88e0dd3..a575a8be 100644 --- a/src/test/java/uk/nhs/hee/trainee/details/api/ProgrammeMembershipResourceTest.java +++ b/src/test/java/uk/nhs/hee/trainee/details/api/ProgrammeMembershipResourceTest.java @@ -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)); @@ -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()); } } diff --git a/src/test/java/uk/nhs/hee/trainee/details/api/TraineeProfileResourceTest.java b/src/test/java/uk/nhs/hee/trainee/details/api/TraineeProfileResourceTest.java index 9e16e680..d3b9d3a3 100644 --- a/src/test/java/uk/nhs/hee/trainee/details/api/TraineeProfileResourceTest.java +++ b/src/test/java/uk/nhs/hee/trainee/details/api/TraineeProfileResourceTest.java @@ -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; @@ -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)); } /** @@ -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())) diff --git a/src/test/java/uk/nhs/hee/trainee/details/service/CachingDelegateIntegrationTest.java b/src/test/java/uk/nhs/hee/trainee/details/service/CachingDelegateIntegrationTest.java index f8831c34..1160906c 100644 --- a/src/test/java/uk/nhs/hee/trainee/details/service/CachingDelegateIntegrationTest.java +++ b/src/test/java/uk/nhs/hee/trainee/details/service/CachingDelegateIntegrationTest.java @@ -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)); } @@ -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 cachedOptional = delegate.getConditionsOfJoining(key); @@ -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. diff --git a/src/test/java/uk/nhs/hee/trainee/details/service/CachingDelegateTest.java b/src/test/java/uk/nhs/hee/trainee/details/service/CachingDelegateTest.java index 5a7c1fd4..b018cc41 100644 --- a/src/test/java/uk/nhs/hee/trainee/details/service/CachingDelegateTest.java +++ b/src/test/java/uk/nhs/hee/trainee/details/service/CachingDelegateTest.java @@ -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)); } diff --git a/src/test/java/uk/nhs/hee/trainee/details/service/ProgrammeMembershipServiceTest.java b/src/test/java/uk/nhs/hee/trainee/details/service/ProgrammeMembershipServiceTest.java index 1acba3d6..ae88490d 100644 --- a/src/test/java/uk/nhs/hee/trainee/details/service/ProgrammeMembershipServiceTest.java +++ b/src/test/java/uk/nhs/hee/trainee/details/service/ProgrammeMembershipServiceTest.java @@ -72,6 +72,7 @@ class ProgrammeMembershipServiceTest { private static final UUID PROGRAMME_MEMBERSHIP_UUID = UUID.randomUUID(); private static final Instant COJ_SIGNED_AT = Instant.now(); private static final GoldGuideVersion GOLD_GUIDE_VERSION = GoldGuideVersion.GG9; + private static final Instant COJ_SYNCED_AT = Instant.now(); private ProgrammeMembershipService service; private TraineeProfileRepository repository; @@ -121,7 +122,8 @@ void shouldAddProgrammeMembershipWhenTraineeFoundAndNoProgrammeMembershipsExists expectedProgrammeMembership.setEndDate(END_DATE.plusDays(100)); expectedProgrammeMembership.setProgrammeCompletionDate(COMPLETION_DATE.plusDays(100)); expectedProgrammeMembership.setConditionsOfJoining( - new ConditionsOfJoining(COJ_SIGNED_AT.plus(Duration.ofDays(100)), GOLD_GUIDE_VERSION)); + new ConditionsOfJoining(COJ_SIGNED_AT.plus(Duration.ofDays(100)), GOLD_GUIDE_VERSION, + COJ_SYNCED_AT.plus(Duration.ofDays(100)))); assertThat("Unexpected programme membership.", programmeMembership.get(), is(expectedProgrammeMembership)); @@ -153,7 +155,8 @@ void shouldAddProgrammeMembershipWhenTraineeFoundAndProgrammeMembershipNotExists expectedProgrammeMembership.setEndDate(END_DATE.plusDays(100)); expectedProgrammeMembership.setProgrammeCompletionDate(COMPLETION_DATE.plusDays(100)); expectedProgrammeMembership.setConditionsOfJoining( - new ConditionsOfJoining(COJ_SIGNED_AT.plus(Duration.ofDays(100)), GOLD_GUIDE_VERSION)); + new ConditionsOfJoining(COJ_SIGNED_AT.plus(Duration.ofDays(100)), GOLD_GUIDE_VERSION, + COJ_SYNCED_AT.plus(Duration.ofDays(100)))); assertThat("Unexpected programme membership.", programmeMembership.get(), is(expectedProgrammeMembership)); @@ -187,7 +190,8 @@ void shouldUpdateProgrammeMembershipWhenTraineeFoundAndProgrammeMembershipExists expectedProgrammeMembership.setEndDate(END_DATE.plusDays(100)); expectedProgrammeMembership.setProgrammeCompletionDate(COMPLETION_DATE.plusDays(100)); expectedProgrammeMembership.setConditionsOfJoining( - new ConditionsOfJoining(COJ_SIGNED_AT.plus(Duration.ofDays(100)), GOLD_GUIDE_VERSION)); + new ConditionsOfJoining(COJ_SIGNED_AT.plus(Duration.ofDays(100)), GOLD_GUIDE_VERSION, + COJ_SYNCED_AT.plus(Duration.ofDays(100)))); assertThat("Unexpected programme membership.", programmeMembership.get(), is(expectedProgrammeMembership)); @@ -217,6 +221,7 @@ void shouldNotUpdateExistingConditionsOfJoiningWhenNewCojNull() { assertThat("Unexpected signed at.", conditionsOfJoining.signedAt(), is(COJ_SIGNED_AT)); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), is(COJ_SYNCED_AT)); } @Test @@ -250,6 +255,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmCojNullAndCojCached() { assertThat("Unexpected signed at.", conditionsOfJoining.signedAt(), is(COJ_SIGNED_AT)); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), is(COJ_SYNCED_AT)); } @Test @@ -262,7 +268,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmCojNotSignedAndCojCached() { ConditionsOfJoining coj = existingProgrammeMembership.getConditionsOfJoining(); existingProgrammeMembership.setConditionsOfJoining( - new ConditionsOfJoining(null, GoldGuideVersion.GG9)); + new ConditionsOfJoining(null, GoldGuideVersion.GG9, null)); when(cachingDelegate.getConditionsOfJoining(EXISTING_PROGRAMME_MEMBERSHIP_ID)).thenReturn( Optional.of(coj)); @@ -271,7 +277,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmCojNotSignedAndCojCached() { ProgrammeMembership newProgrammeMembership = createProgrammeMembership( EXISTING_PROGRAMME_MEMBERSHIP_ID, MODIFIED_SUFFIX, 100); newProgrammeMembership.setConditionsOfJoining( - new ConditionsOfJoining(null, GoldGuideVersion.GG9)); + new ConditionsOfJoining(null, GoldGuideVersion.GG9, null)); Optional programmeMembership = service .updateProgrammeMembershipForTrainee(TRAINEE_TIS_ID, newProgrammeMembership); @@ -285,6 +291,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmCojNotSignedAndCojCached() { assertThat("Unexpected signed at.", conditionsOfJoining.signedAt(), is(COJ_SIGNED_AT)); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), is(COJ_SYNCED_AT)); } @Test @@ -296,11 +303,12 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasMultipleIds() { traineeProfile.getProgrammeMemberships().add(programmeMembership); when(cachingDelegate.getConditionsOfJoining("123")).thenReturn( - Optional.of(new ConditionsOfJoining(Instant.MIN, GoldGuideVersion.GG9))); + Optional.of(new ConditionsOfJoining(Instant.MIN, GoldGuideVersion.GG9, Instant.MIN))); when(cachingDelegate.getConditionsOfJoining("456")).thenReturn( - Optional.of(new ConditionsOfJoining(Instant.MAX, GoldGuideVersion.GG9))); + Optional.of(new ConditionsOfJoining(Instant.MAX, GoldGuideVersion.GG9, Instant.MAX))); when(cachingDelegate.getConditionsOfJoining("789")).thenReturn( - Optional.of(new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9))); + Optional.of( + new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9, COJ_SYNCED_AT))); when(repository.findByTraineeTisId(TRAINEE_TIS_ID)).thenReturn(traineeProfile); @@ -317,6 +325,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasMultipleIds() { assertThat("Unexpected signed at.", conditionsOfJoining.signedAt(), is(COJ_SIGNED_AT)); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), is(COJ_SYNCED_AT)); verify(cachingDelegate, times(1)).getConditionsOfJoining("123"); verify(cachingDelegate, times(1)).getConditionsOfJoining("456"); @@ -333,7 +342,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndSavedPmHasUuid() { ProgrammeMembership savedProgrammeMembership = createProgrammeMembership( PROGRAMME_MEMBERSHIP_UUID.toString(), ORIGINAL_SUFFIX, 0); savedProgrammeMembership.setConditionsOfJoining( - new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9)); + new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9, COJ_SYNCED_AT)); traineeProfile.getProgrammeMemberships().add(savedProgrammeMembership); when(repository.findByTraineeTisId(TRAINEE_TIS_ID)).thenReturn(traineeProfile); @@ -351,6 +360,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndSavedPmHasUuid() { assertThat("Unexpected signed at.", conditionsOfJoining.signedAt(), is(COJ_SIGNED_AT)); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), is(COJ_SYNCED_AT)); } @Test @@ -370,7 +380,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndSavedUuidPmHasNoCojButLeg ProgrammeMembership savedProgrammeMembershipLegacy = createProgrammeMembership( "123", ORIGINAL_SUFFIX, 0); savedProgrammeMembershipLegacy.setConditionsOfJoining( - new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9)); + new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9, COJ_SYNCED_AT)); traineeProfile.getProgrammeMemberships().addAll( List.of(savedProgrammeMembership, savedProgrammeMembershipLegacy)); @@ -389,6 +399,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndSavedUuidPmHasNoCojButLeg assertThat("Unexpected signed at.", conditionsOfJoining.signedAt(), is(COJ_SIGNED_AT)); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), is(COJ_SYNCED_AT)); } @Test @@ -408,7 +419,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndSavedPmHasDeprecatedIds() ProgrammeMembership savedProgrammeMembership = createProgrammeMembership( "123,456", ORIGINAL_SUFFIX, 0); savedProgrammeMembership.setConditionsOfJoining( - new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9)); + new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9, COJ_SYNCED_AT)); TraineeProfile traineeProfile = new TraineeProfile(); traineeProfile.getProgrammeMemberships().add(savedProgrammeMembership); @@ -427,6 +438,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndSavedPmHasDeprecatedIds() assertThat("Unexpected signed at.", conditionsOfJoining.signedAt(), is(COJ_SIGNED_AT)); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), is(COJ_SYNCED_AT)); } @Test @@ -434,7 +446,8 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndFirstSavedPmHasCoj() { Curriculum curriculum123 = new Curriculum(); curriculum123.setTisId("123"); ProgrammeMembership oldPm123 = createProgrammeMembership("123", ORIGINAL_SUFFIX, 0); - oldPm123.setConditionsOfJoining(new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9)); + oldPm123.setConditionsOfJoining( + new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9, COJ_SYNCED_AT)); Curriculum curriculum456 = new Curriculum(); curriculum456.setTisId("456"); @@ -463,6 +476,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndFirstSavedPmHasCoj() { assertThat("Unexpected signed at.", conditionsOfJoining.signedAt(), is(COJ_SIGNED_AT)); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), is(COJ_SYNCED_AT)); } @Test @@ -475,7 +489,8 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndSecondSavedPmHasCoj() { Curriculum curriculum456 = new Curriculum(); curriculum456.setTisId("456"); ProgrammeMembership oldPm456 = createProgrammeMembership("456", ORIGINAL_SUFFIX, 0); - oldPm456.setConditionsOfJoining(new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9)); + oldPm456.setConditionsOfJoining( + new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9, COJ_SYNCED_AT)); TraineeProfile traineeProfile = new TraineeProfile(); traineeProfile.getProgrammeMemberships().addAll(List.of(oldPm123, oldPm456)); @@ -499,6 +514,7 @@ void shouldUpdateProgrammeMembershipCojWhenPmHasUuidAndSecondSavedPmHasCoj() { assertThat("Unexpected signed at.", conditionsOfJoining.signedAt(), is(COJ_SIGNED_AT)); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), is(COJ_SYNCED_AT)); } @Test @@ -513,7 +529,7 @@ void shouldNotUpdateProgrammeMembershipCojWhenPmHasUuidAndSavedPmNotFound() { ProgrammeMembership savedProgrammeMembership = createProgrammeMembership( "456,789", ORIGINAL_SUFFIX, 0); savedProgrammeMembership.setConditionsOfJoining( - new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9)); + new ConditionsOfJoining(COJ_SIGNED_AT, GoldGuideVersion.GG9, COJ_SYNCED_AT)); TraineeProfile traineeProfile = new TraineeProfile(); traineeProfile.getProgrammeMemberships().add(savedProgrammeMembership); @@ -536,7 +552,8 @@ void shouldNotUpdateProgrammeMembershipCojWhenCojAlreadySigned() { EXISTING_PROGRAMME_MEMBERSHIP_ID, ORIGINAL_SUFFIX, 0)); when(cachingDelegate.getConditionsOfJoining(EXISTING_PROGRAMME_MEMBERSHIP_ID)).thenReturn( - Optional.of(new ConditionsOfJoining(Instant.MAX, GoldGuideVersion.GG9))); + Optional.of( + new ConditionsOfJoining(Instant.MAX, GoldGuideVersion.GG9, COJ_SYNCED_AT))); when(repository.findByTraineeTisId(TRAINEE_TIS_ID)).thenReturn(traineeProfile); ProgrammeMembership newProgrammeMembership = createProgrammeMembership( @@ -555,6 +572,8 @@ void shouldNotUpdateProgrammeMembershipCojWhenCojAlreadySigned() { is(COJ_SIGNED_AT.plus(Duration.ofDays(100)))); assertThat("Unexpected signed version.", conditionsOfJoining.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected synced at.", conditionsOfJoining.syncedAt(), + is(COJ_SYNCED_AT.plus(Duration.ofDays(100)))); verifyNoInteractions(cachingDelegate); } @@ -627,7 +646,8 @@ void shouldCacheCojFromDeleteProgrammeMembershipsWhenCojSignedUsingUuid() { void shouldNotCacheCojFromDeleteProgrammeMembershipsWhenCojNotSigned() { ProgrammeMembership programmeMembership = createProgrammeMembership( EXISTING_PROGRAMME_MEMBERSHIP_ID, ORIGINAL_SUFFIX, 0); - programmeMembership.setConditionsOfJoining(new ConditionsOfJoining(null, GoldGuideVersion.GG9)); + programmeMembership.setConditionsOfJoining( + new ConditionsOfJoining(null, GoldGuideVersion.GG9, COJ_SYNCED_AT)); TraineeProfile traineeProfile = new TraineeProfile(); traineeProfile.getProgrammeMemberships().add(programmeMembership); @@ -734,6 +754,9 @@ void shouldSignCojWhenTraineeProgrammeMembershipFound() { assertThat("Unexpected COJ version.", programmeMembership.get().getConditionsOfJoining().version(), is(GoldGuideVersion.getLatest())); + assertThat("Unexpected CoJ synced at", + programmeMembership.get().getConditionsOfJoining().syncedAt(), + nullValue()); } @Test @@ -770,7 +793,7 @@ void shouldNotSignCojWhenTraineeFoundButProgrammeMembershipsNotExists() { * @return The dummy entity. */ private ProgrammeMembership createProgrammeMembership(String tisId, String stringSuffix, - int dateAdjustmentDays) { + int dateAdjustmentDays) { ProgrammeMembership programmeMembership = new ProgrammeMembership(); programmeMembership.setTisId(tisId); programmeMembership.setProgrammeTisId(PROGRAMME_TIS_ID + stringSuffix); @@ -783,7 +806,7 @@ private ProgrammeMembership createProgrammeMembership(String tisId, String strin programmeMembership.setProgrammeCompletionDate(COMPLETION_DATE.plusDays(dateAdjustmentDays)); programmeMembership.setConditionsOfJoining( new ConditionsOfJoining(COJ_SIGNED_AT.plus(Duration.ofDays(dateAdjustmentDays)), - GOLD_GUIDE_VERSION)); + GOLD_GUIDE_VERSION, COJ_SYNCED_AT.plus(Duration.ofDays(dateAdjustmentDays)))); return programmeMembership; } diff --git a/src/test/java/uk/nhs/hee/trainee/details/service/RabbitPublishServiceTest.java b/src/test/java/uk/nhs/hee/trainee/details/service/RabbitPublishServiceTest.java index a6410973..dcec716b 100644 --- a/src/test/java/uk/nhs/hee/trainee/details/service/RabbitPublishServiceTest.java +++ b/src/test/java/uk/nhs/hee/trainee/details/service/RabbitPublishServiceTest.java @@ -22,6 +22,7 @@ package uk.nhs.hee.trainee.details.service; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.ArgumentMatchers.any; @@ -71,7 +72,7 @@ void shouldPublishCojSignedEvent() { programmeMembership.setTisId("123"); Instant signedAt = Instant.now(); ConditionsOfJoining conditionsOfJoining - = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9); + = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9, null); programmeMembership.setConditionsOfJoining(conditionsOfJoining); rabbitPublishService.publishCojSignedEvent(programmeMembership); @@ -90,6 +91,8 @@ void shouldPublishCojSignedEvent() { conditionsOfJoiningSent.signedAt(), is(signedAt)); assertThat("Unexpected CoJ Version", conditionsOfJoiningSent.version(), is(GoldGuideVersion.GG9)); + assertThat("Unexpected CoJ synced at", conditionsOfJoiningSent.syncedAt(), + nullValue()); } @Test @@ -98,7 +101,7 @@ void shouldPublishCojSignedEventWithSimplifiedId() { programmeMembership.setTisId("123,456,7890"); Instant signedAt = Instant.now(); ConditionsOfJoining conditionsOfJoining - = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9); + = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9, null); programmeMembership.setConditionsOfJoining(conditionsOfJoining); rabbitPublishService.publishCojSignedEvent(programmeMembership); @@ -121,7 +124,7 @@ void shouldPublishCojSignedEventWithUuid() { programmeMembership.setTisId(uuid.toString()); Instant signedAt = Instant.now(); ConditionsOfJoining conditionsOfJoining - = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9); + = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9, null); programmeMembership.setConditionsOfJoining(conditionsOfJoining); rabbitPublishService.publishCojSignedEvent(programmeMembership); @@ -143,7 +146,7 @@ void shouldPublishCojSignedEventWithPmCorrelationId() { programmeMembership.setTisId("123,456,7890"); Instant signedAt = Instant.now(); ConditionsOfJoining conditionsOfJoining - = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9); + = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9, null); programmeMembership.setConditionsOfJoining(conditionsOfJoining); rabbitPublishService.publishCojSignedEvent(programmeMembership); @@ -191,7 +194,7 @@ void shouldNotThrowExceptionIfRabbitThrowsException() { programmeMembership.setTisId("123"); Instant signedAt = Instant.now(); ConditionsOfJoining conditionsOfJoining - = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9); + = new ConditionsOfJoining(signedAt, GoldGuideVersion.GG9, null); programmeMembership.setConditionsOfJoining(conditionsOfJoining); assertDoesNotThrow(() -> rabbitPublishService.publishCojSignedEvent(programmeMembership), diff --git a/src/test/java/uk/nhs/hee/trainee/details/service/TraineeProfileServiceTest.java b/src/test/java/uk/nhs/hee/trainee/details/service/TraineeProfileServiceTest.java index 7c0b7dd9..496f34e8 100644 --- a/src/test/java/uk/nhs/hee/trainee/details/service/TraineeProfileServiceTest.java +++ b/src/test/java/uk/nhs/hee/trainee/details/service/TraineeProfileServiceTest.java @@ -363,7 +363,7 @@ void shouldUseLatestCojVersionWhenNoCoj() { @Test void shouldUseLatestCojVersionWhenCojNotSigned() { // Currently only GG9 is available, so latest and unsigned PM version are the same. - programmeMembership.setConditionsOfJoining(new ConditionsOfJoining(null, GG9)); + programmeMembership.setConditionsOfJoining(new ConditionsOfJoining(null, GG9, null)); when(repository.findByTraineeTisId(DEFAULT_TIS_ID_1)).thenReturn(this.traineeProfile); @@ -373,13 +373,14 @@ void shouldUseLatestCojVersionWhenCojNotSigned() { assertThat("Unexpected Conditions of Joining", coj, notNullValue()); assertThat("Unexpected CoJ signed at timestamp", coj.signedAt(), nullValue()); assertThat("Unexpected CoJ version", coj.version(), is(GG9)); + assertThat("Unexpected CoJ synced at", coj.syncedAt(), nullValue()); } @Test void shouldUseSignedVersionWhenCojSigned() { // Currently only GG9 is available, so latest and signed PM version are the same. Instant now = Instant.now(); - programmeMembership.setConditionsOfJoining(new ConditionsOfJoining(now, GG9)); + programmeMembership.setConditionsOfJoining(new ConditionsOfJoining(now, GG9, null)); when(repository.findByTraineeTisId(DEFAULT_TIS_ID_1)).thenReturn(this.traineeProfile); @@ -389,6 +390,7 @@ void shouldUseSignedVersionWhenCojSigned() { assertThat("Unexpected Conditions of Joining", coj, notNullValue()); assertThat("Unexpected CoJ signed at timestamp", coj.signedAt(), is(now)); assertThat("Unexpected CoJ version", coj.version(), is(GG9)); + assertThat("Unexpected CoJ synced at", coj.syncedAt(), nullValue()); } @Test