Skip to content

Commit

Permalink
[JN-1636] Don't sync deactivated kits (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewBemis authored Feb 28, 2025
1 parent c3cae1f commit 9bf4e59
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,22 @@ protected String stringifyPepperAddress(PepperKitAddress kitAddress) {
*/
private void saveKitStatus(KitRequest kitRequest, PepperKit pepperKit, Instant pepperStatusFetchedAt) {
KitRequestStatus priorStatus = kitRequest.getStatus();

if(priorStatus.equals(KitRequestStatus.DEACTIVATED)) {
// if the kit has been deactivated in Juniper, we no longer need to update the status
// based on what DSM thinks. this allows us to independently deactivate kits in Juniper
// without having to worry about DSM status updates.
if(!PepperKitStatus.mapToKitRequestStatus(pepperKit.getCurrentStatus()).equals(priorStatus)) {
// if the statuses don't match, log a warning so we know about the inconsistency
// this case is expected if a kit has been deactivated in Juniper but not DSM
log.warn((
"Skipped status update for deactivated kit request %s, " +
"and statuses did not match. Juniper status: %s, DSM status: %s"
).formatted(kitRequest.getId(), priorStatus, pepperKit.getCurrentStatus()));
}
return;
}

try {
kitRequest.setExternalKit(objectMapper.writeValueAsString(pepperKit));
kitRequest.setExternalKitFetchedAt(pepperStatusFetchedAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,31 @@ void testUpdateKitStatus(TestInfo testInfo) throws Exception {
assertThat(savedKit.getSentAt(), equalTo(Instant.parse(sentDate)));
}

@Transactional
@Test
public void testSkipStatusUpdateForDeactivatedKit(TestInfo testInfo) throws Exception {
String testName = getTestName(testInfo);
AdminUser adminUser = adminUserFactory.buildPersisted(testName);
EnrolleeBundle enrolleeBundle = enrolleeFactory.buildWithPortalUser(testName);
Enrollee enrollee = enrolleeBundle.enrollee();
KitType kitType = kitTypeFactory.buildPersisted(testName);
KitRequest kitRequest = kitRequestFactory.buildPersisted(testName,
enrollee, PepperKitStatus.DEACTIVATED, kitType.getId(), adminUser.getId());

PepperKit pepperKit = PepperKit.builder()
.juniperKitId(kitRequest.getId().toString())
.currentStatus(PepperKitStatus.SENT.pepperString)
.build();
when(mockPepperDSMClient.fetchKitStatus(any(), eq(kitRequest.getId()))).thenReturn(pepperKit);

kitRequestService.syncKitStatusFromPepper(kitRequest.getId());

// Verify that the status was not updated
KitRequest savedKit = kitRequestDao.find(kitRequest.getId()).get();
assertThat(savedKit.getStatus(), equalTo(KitRequestStatus.DEACTIVATED));
verify(mockPepperDSMClient).fetchKitStatus(any(), eq(kitRequest.getId()));
}

@Transactional
@Test
public void testGetKitsByStudyEnvironment(TestInfo testInfo) throws Exception {
Expand Down

0 comments on commit 9bf4e59

Please sign in to comment.