Skip to content

Commit

Permalink
MAT-4169 changed based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-cecilialiu committed Dec 9, 2024
1 parent ccd894a commit 3b7e6b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
10 changes: 6 additions & 4 deletions src/main/java/gov/cms/madie/terminology/service/VsacService.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,13 @@ public Optional<UmlsUser> findByHarpId(String harpId) {
}

public boolean logoutUMLSUser(String userName) {
UmlsUser user = verifyUmlsAccess(userName);
boolean deleted = false;
Optional<UmlsUser> deletedUser = umlsUserRepository.deleteByHarpId(userName);
deleted = deletedUser.isPresent();
log.info("Log out UMLS User:{} : {}.", user.getHarpId(), deleted);
boolean deleted = deletedUser.isPresent();
if (deleted) {
log.info("Successfully deleted UMLS information for User Name: {}", userName);
} else {
log.error("Error while deleting UMLS information for User Name: {}", userName);
}
return deleted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,31 +595,15 @@ void testGetCodeStatusIfCodeNotFoundInSvs() {

@Test
void testUserUmlsLogout() {
when(umlsUserRepository.findByHarpId(anyString())).thenReturn(Optional.of(umlsUser));
UmlsUser user = vsacService.verifyUmlsAccess(TEST_API_KEY);
when(umlsUserRepository.deleteByHarpId(anyString())).thenReturn(Optional.of(umlsUser));
boolean loggedOut = vsacService.logoutUMLSUser(umlsUser.getHarpId());
assertThat(user.getHarpId(), is(equalTo(TEST_HARP_ID)));
assertThat(user.getApiKey(), is(equalTo(TEST_API_KEY)));
assertThat(loggedOut, is(equalTo(true)));
assertTrue(loggedOut);
}

@Test
void testUserUmlsLogoutUserNotFound() {
when(umlsUserRepository.findByHarpId(anyString())).thenReturn(Optional.empty());
Exception exception =
assertThrows(
VsacUnauthorizedException.class, () -> vsacService.logoutUMLSUser(TEST_API_KEY));
assertThat(exception.getMessage(), is(equalTo("Please login to UMLS before proceeding")));
}

@Test
void testUserUmlsLogoutUserApiKeyIsMissing() {
UmlsUser umlsUserCopy = umlsUser.toBuilder().apiKey(null).build();
when(umlsUserRepository.findByHarpId(anyString())).thenReturn(Optional.of(umlsUserCopy));
Exception exception =
assertThrows(
VsacUnauthorizedException.class, () -> vsacService.logoutUMLSUser(TEST_API_KEY));
assertThat(exception.getMessage(), is(equalTo("Please login to UMLS before proceeding")));
void testUserUmlsLogoutFailed() {
when(umlsUserRepository.deleteByHarpId(anyString())).thenReturn(Optional.empty());
boolean loggedOut = vsacService.logoutUMLSUser(umlsUser.getHarpId());
assertFalse(loggedOut);
}
}

0 comments on commit 3b7e6b8

Please sign in to comment.