-
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/fix mutation error states (#6437)
* make errors more specific * lint
- Loading branch information
Showing
5 changed files
with
59 additions
and
29 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
...va/gov/cdc/usds/simplereport/api/model/errors/PrivilegeUpdateFacilityAccessException.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,32 @@ | ||
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 facility ID can't be found in an organization query */ | ||
public class PrivilegeUpdateFacilityAccessException extends RuntimeException | ||
implements GraphQLError { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public static final String PRIVILEGE_UPDATE_FACILITY_ACCESS_ERROR = | ||
"Operation must specify a list of facilities for the user to access or allow them access to all facilities"; | ||
|
||
public PrivilegeUpdateFacilityAccessException() { | ||
super(PRIVILEGE_UPDATE_FACILITY_ACCESS_ERROR); | ||
} | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package gov.cdc.usds.simplereport.service; | ||
|
||
import static gov.cdc.usds.simplereport.service.ApiUserService.MOVE_USER_ARGUMENT_ERROR; | ||
import static gov.cdc.usds.simplereport.api.model.errors.PrivilegeUpdateFacilityAccessException.PRIVILEGE_UPDATE_FACILITY_ACCESS_ERROR; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
@@ -17,6 +17,7 @@ | |
import gov.cdc.usds.simplereport.api.model.errors.IllegalGraphqlArgumentException; | ||
import gov.cdc.usds.simplereport.api.model.errors.NonexistentUserException; | ||
import gov.cdc.usds.simplereport.api.model.errors.OktaAccountUserException; | ||
import gov.cdc.usds.simplereport.api.model.errors.PrivilegeUpdateFacilityAccessException; | ||
import gov.cdc.usds.simplereport.api.model.errors.RestrictedAccessUserException; | ||
import gov.cdc.usds.simplereport.api.model.errors.UnidentifiedFacilityException; | ||
import gov.cdc.usds.simplereport.config.authorization.OrganizationRole; | ||
|
@@ -508,27 +509,27 @@ void updateUserPrivilegesAndGroupAccess_assignToAllFacilities_success() { | |
@Test | ||
@WithSimpleReportSiteAdminUser | ||
void | ||
updateUserPrivilegesAndGroupAccess_assignToAllFalseWithoutFacilities_throwsIllegalArgException() { | ||
updateUserPrivilegesAndGroupAccess_assignToAllFalseWithoutFacilities_throwsPrivilegeUpdateFacilityAccessException() { | ||
initSampleData(); | ||
final String email = "[email protected]"; | ||
Organization orgToTestMovementTo = _dataFactory.saveValidOrganization(); | ||
String moveOrgExternalId = orgToTestMovementTo.getExternalId(); | ||
List<UUID> emptyList = List.of(); | ||
IllegalArgumentException caught = | ||
PrivilegeUpdateFacilityAccessException caught = | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
PrivilegeUpdateFacilityAccessException.class, | ||
() -> | ||
_service.updateUserPrivilegesAndGroupAccess( | ||
email, moveOrgExternalId, false, emptyList, OrganizationRole.USER)); | ||
assertEquals(MOVE_USER_ARGUMENT_ERROR, caught.getMessage()); | ||
assertEquals(PRIVILEGE_UPDATE_FACILITY_ACCESS_ERROR, caught.getMessage()); | ||
|
||
IllegalArgumentException caught2 = | ||
PrivilegeUpdateFacilityAccessException caught2 = | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
PrivilegeUpdateFacilityAccessException.class, | ||
() -> | ||
_service.updateUserPrivilegesAndGroupAccess( | ||
email, moveOrgExternalId, false, OrganizationRole.USER)); | ||
assertEquals(MOVE_USER_ARGUMENT_ERROR, caught2.getMessage()); | ||
assertEquals(PRIVILEGE_UPDATE_FACILITY_ACCESS_ERROR, caught2.getMessage()); | ||
} | ||
|
||
@Test | ||
|