-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bob/6936 query for admin emails (#6962)
* hook up new query wiring * get happy path working * add in error handling for not found cases * add tests * lint * genericize expected list of ids * codesmell * update tests * fix code issues * one last code smell
- Loading branch information
Showing
7 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...end/src/main/java/gov/cdc/usds/simplereport/api/model/errors/NonexistentOrgException.java
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,28 @@ | ||
package gov.cdc.usds.simplereport.api.model.errors; | ||
|
||
import graphql.ErrorClassification; | ||
import graphql.ErrorType; | ||
import graphql.GraphQLError; | ||
import graphql.language.SourceLocation; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** Exception to throw when a organization does not exist. */ | ||
public class NonexistentOrgException extends RuntimeException implements GraphQLError { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public NonexistentOrgException() { | ||
super("Cannot find organization."); | ||
} | ||
|
||
@Override // should-be-defaulted unused interface method | ||
public List<SourceLocation> getLocations() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public ErrorClassification getErrorType() { | ||
return ErrorType.ExecutionAborted; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,16 +10,20 @@ | |
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import gov.cdc.usds.simplereport.api.model.FacilityStats; | ||
import gov.cdc.usds.simplereport.api.model.errors.IllegalGraphqlArgumentException; | ||
import gov.cdc.usds.simplereport.api.model.errors.NonexistentOrgException; | ||
import gov.cdc.usds.simplereport.api.model.errors.OrderingProviderRequiredException; | ||
import gov.cdc.usds.simplereport.config.simplereport.DemoUserConfiguration; | ||
import gov.cdc.usds.simplereport.db.model.DeviceType; | ||
import gov.cdc.usds.simplereport.db.model.Facility; | ||
import gov.cdc.usds.simplereport.db.model.Organization; | ||
import gov.cdc.usds.simplereport.db.model.PatientSelfRegistrationLink; | ||
import gov.cdc.usds.simplereport.db.model.auxiliary.PersonName; | ||
import gov.cdc.usds.simplereport.db.model.auxiliary.StreetAddress; | ||
import gov.cdc.usds.simplereport.db.repository.ApiUserRepository; | ||
import gov.cdc.usds.simplereport.db.repository.DeviceTypeRepository; | ||
import gov.cdc.usds.simplereport.db.repository.FacilityRepository; | ||
import gov.cdc.usds.simplereport.db.repository.OrganizationRepository; | ||
|
@@ -52,6 +56,8 @@ class OrganizationServiceTest extends BaseServiceTest<OrganizationService> { | |
@Autowired private DeviceTypeRepository deviceTypeRepository; | ||
@Autowired @SpyBean private OktaRepository oktaRepository; | ||
@Autowired @SpyBean private PersonRepository personRepository; | ||
@Autowired ApiUserRepository _apiUserRepo; | ||
@Autowired private DemoUserConfiguration userConfiguration; | ||
|
||
@BeforeEach | ||
void setupData() { | ||
|
@@ -452,4 +458,44 @@ void updateFacilityTest() { | |
assertThat(updatedFacility.getDeviceTypes()).hasSize(2); | ||
} | ||
} | ||
|
||
@Test | ||
@WithSimpleReportSiteAdminUser | ||
void getOrgAdminUserIds_success() { | ||
Organization createdOrg = _dataFactory.saveValidOrganization(); | ||
List<String> adminUserEmails = oktaRepository.fetchAdminUserEmail(createdOrg); | ||
|
||
List<UUID> expectedIds = | ||
adminUserEmails.stream() | ||
.map(email -> _apiUserRepo.findByLoginEmail(email).get().getInternalId()) | ||
.collect(Collectors.toList()); | ||
|
||
List<UUID> adminIds = _service.getOrgAdminUserIds(createdOrg.getInternalId()); | ||
assertThat(adminIds).isEqualTo(expectedIds); | ||
} | ||
|
||
@Test | ||
@WithSimpleReportSiteAdminUser | ||
void getOrgAdminUserIds_throws_forNonExistentOrg() { | ||
UUID mismatchedUUID = UUID.fromString("5ebf893a-bb57-48ca-8fc2-1ef6b25e465b"); | ||
assertThrows(NonexistentOrgException.class, () -> _service.getOrgAdminUserIds(mismatchedUUID)); | ||
} | ||
|
||
@Test | ||
@WithSimpleReportSiteAdminUser | ||
void getOrgAdminUserIds_skipsUser_forNonExistentUserInOrg() { | ||
Organization createdOrg = _dataFactory.saveValidOrganization(); | ||
List<String> listWithAnExtraEmail = oktaRepository.fetchAdminUserEmail(createdOrg); | ||
listWithAnExtraEmail.add("[email protected]"); | ||
|
||
when(oktaRepository.fetchAdminUserEmail(createdOrg)).thenReturn(listWithAnExtraEmail); | ||
List<UUID> expectedIds = | ||
listWithAnExtraEmail.stream() | ||
.filter(email -> !email.equals("[email protected]")) | ||
.map(email -> _apiUserRepo.findByLoginEmail(email).get().getInternalId()) | ||
.collect(Collectors.toList()); | ||
|
||
List<UUID> adminIds = _service.getOrgAdminUserIds(createdOrg.getInternalId()); | ||
assertThat(adminIds).isEqualTo(expectedIds); | ||
} | ||
} |
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