Skip to content

Commit

Permalink
Fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
emyl3 committed Jan 14, 2025
1 parent 4dcbd8a commit 03c616a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public List<UUID> getOrgAdminUserIds(UUID orgId) {
.collect(Collectors.toList());
}

@Async
@Async("applicationTaskExecutor")
@AuthorizationConfiguration.RequireGlobalAdminUser
public CompletableFuture<List<String>> sendOrgAdminEmailCSVAsync(
List<UUID> orgInternalIds, String type, String state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import gov.cdc.usds.simplereport.test_util.SliceTestConfiguration.WithSimpleReportOrgAdminUser;
import gov.cdc.usds.simplereport.test_util.SliceTestConfiguration.WithSimpleReportSiteAdminUser;
import gov.cdc.usds.simplereport.test_util.SliceTestConfiguration.WithSimpleReportStandardUser;
import gov.cdc.usds.simplereport.test_util.TestDataFactory;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand All @@ -61,7 +60,6 @@
@EnableAsync
class OrganizationServiceTest extends BaseServiceTest<OrganizationService> {

@Autowired private TestDataFactory testDataFactory;
@Autowired private PatientRegistrationLinkRepository patientRegistrationLinkRepository;
@Autowired @SpyBean private FacilityRepository facilityRepository;
@Autowired @SpyBean private OrganizationRepository organizationRepository;
Expand Down Expand Up @@ -156,7 +154,7 @@ void createOrganizationAndFacility_success() {
}

private DeviceType getDeviceConfig() {
return testDataFactory.createDeviceType("Abbott ID Now", "Abbott", "1");
return _dataFactory.createDeviceType("Abbott ID Now", "Abbott", "1");
}

@Test
Expand Down Expand Up @@ -190,8 +188,8 @@ void createOrganizationAndFacility_orderingProviderRequired_failure() {
@WithSimpleReportSiteAdminUser
void getOrganizationsAndFacility_filterByIdentityVerified_success() {
// GIVEN
Organization verifiedOrg = testDataFactory.saveValidOrganization();
Organization unverifiedOrg = testDataFactory.saveUnverifiedOrganization();
Organization verifiedOrg = _dataFactory.saveValidOrganization();
Organization unverifiedOrg = _dataFactory.saveUnverifiedOrganization();

// WHEN
List<Organization> allOrgs = _service.getOrganizations(null);
Expand Down Expand Up @@ -221,9 +219,9 @@ void getOrganizationsAndFacility_filterByIdentityVerified_success() {
@Test
@WithSimpleReportSiteAdminUser
void getFacilitiesIncludeArchived_includeArchived_success() {
Organization org = testDataFactory.saveValidOrganization();
Facility deletedFacility = testDataFactory.createArchivedFacility(org, "Delete me");
testDataFactory.createValidFacility(org, "Not deleted");
Organization org = _dataFactory.saveValidOrganization();
Facility deletedFacility = _dataFactory.createArchivedFacility(org, "Delete me");
_dataFactory.createValidFacility(org, "Not deleted");

Set<Facility> archivedFacilities = _service.getFacilitiesIncludeArchived(org, true);

Expand All @@ -236,9 +234,9 @@ void getFacilitiesIncludeArchived_includeArchived_success() {
@Test
@WithSimpleReportSiteAdminUser
void getFacilitiesIncludeArchived_excludeArchived_success() {
Organization org = testDataFactory.saveValidOrganization();
testDataFactory.createArchivedFacility(org, "Delete me");
Facility activeFacility = testDataFactory.createValidFacility(org, "Not deleted");
Organization org = _dataFactory.saveValidOrganization();
_dataFactory.createArchivedFacility(org, "Delete me");
Facility activeFacility = _dataFactory.createValidFacility(org, "Not deleted");

Set<Facility> facilities = _service.getFacilitiesIncludeArchived(org, false);

Expand All @@ -251,8 +249,8 @@ void getFacilitiesIncludeArchived_excludeArchived_success() {
@Test
@WithSimpleReportOrgAdminUser
void viewArchivedFacilities_success() {
Organization org = testDataFactory.saveValidOrganization();
Facility deletedFacility = testDataFactory.createArchivedFacility(org, "Delete me");
Organization org = _dataFactory.saveValidOrganization();
Facility deletedFacility = _dataFactory.createArchivedFacility(org, "Delete me");

Set<Facility> archivedFacilities = _service.getArchivedFacilities(org);

Expand All @@ -264,8 +262,8 @@ void viewArchivedFacilities_success() {
@Test
@WithSimpleReportStandardUser
void viewArchivedFacilities_standardUser_failure() {
Organization org = testDataFactory.saveValidOrganization();
testDataFactory.createArchivedFacility(org, "Delete me");
Organization org = _dataFactory.saveValidOrganization();
_dataFactory.createArchivedFacility(org, "Delete me");

assertThrows(AccessDeniedException.class, () -> _service.getArchivedFacilities());
}
Expand All @@ -275,9 +273,9 @@ void viewArchivedFacilities_standardUser_failure() {
@WithSimpleReportSiteAdminUser
void deleteFacilityTest_successful() {
// GIVEN
Organization verifiedOrg = testDataFactory.saveValidOrganization();
Organization verifiedOrg = _dataFactory.saveValidOrganization();
Facility mistakeFacility =
testDataFactory.createValidFacility(verifiedOrg, "This facility is a mistake");
_dataFactory.createValidFacility(verifiedOrg, "This facility is a mistake");
// WHEN
Facility deletedFacility =
_service.markFacilityAsDeleted(mistakeFacility.getInternalId(), true);
Expand All @@ -303,7 +301,7 @@ void deletedFacilityTest_throwsErrorWhenFacilityNotFound() {
@WithSimpleReportSiteAdminUser
void deleteOrganizationTest_successful() {
// GIVEN
Organization verifiedOrg = testDataFactory.saveValidOrganization();
Organization verifiedOrg = _dataFactory.saveValidOrganization();
// WHEN
Organization deletedOrganization =
_service.markOrganizationAsDeleted(verifiedOrg.getInternalId(), true);
Expand Down Expand Up @@ -333,7 +331,7 @@ void adminUpdateOrganization_not_allowed() {

@Test
void verifyOrganizationNoPermissions_noUser_withOktaMigrationDisabled_success() {
Organization org = testDataFactory.saveUnverifiedOrganization();
Organization org = _dataFactory.saveUnverifiedOrganization();
_service.verifyOrganizationNoPermissions(org.getExternalId());

org = _service.getOrganization(org.getExternalId());
Expand All @@ -347,7 +345,7 @@ void verifyOrganizationNoPermissions_noUser_withOktaMigrationDisabled_success()
@WithSimpleReportSiteAdminUser
void verifyOrganizationNoPermissions_noUser_withOktaMigrationEnabled_throws() {
when(featureFlagsConfig.isOktaMigrationEnabled()).thenReturn(true);
Organization org = testDataFactory.saveUnverifiedOrganization();
Organization org = _dataFactory.saveUnverifiedOrganization();
String orgExternalId = org.getExternalId();

IllegalStateException e =
Expand All @@ -363,7 +361,7 @@ void verifyOrganizationNoPermissions_noUser_withOktaMigrationEnabled_throws() {
@WithSimpleReportSiteAdminUser
void verifyOrganizationNoPermissions_withUsers_withOktaMigrationEnabled_success() {
when(featureFlagsConfig.isOktaMigrationEnabled()).thenReturn(true);
Organization org = testDataFactory.saveUnverifiedOrganizationWithUser("[email protected]");
Organization org = _dataFactory.saveUnverifiedOrganizationWithUser("[email protected]");

_service.verifyOrganizationNoPermissions(org.getExternalId());
verify(dbAuthorizationService, times(1)).getOrgAdminUsers(org);
Expand All @@ -376,7 +374,7 @@ void verifyOrganizationNoPermissions_withUsers_withOktaMigrationEnabled_success(

@Test
void verifyOrganizationNoPermissions_orgAlreadyVerified_failure() {
Organization org = testDataFactory.saveValidOrganization();
Organization org = _dataFactory.saveValidOrganization();
String orgExternalId = org.getExternalId();
IllegalStateException e =
assertThrows(
Expand All @@ -390,7 +388,7 @@ void verifyOrganizationNoPermissions_orgAlreadyVerified_failure() {
@WithSimpleReportSiteAdminUser
void setIdentityVerified_withOktaMigrationDisabled_success() {
when(featureFlagsConfig.isOktaMigrationEnabled()).thenReturn(false);
Organization unverifiedOrg = testDataFactory.saveUnverifiedOrganization();
Organization unverifiedOrg = _dataFactory.saveUnverifiedOrganization();

boolean status = _service.setIdentityVerified(unverifiedOrg.getExternalId(), true);
verify(dbAuthorizationService, times(0)).getOrgAdminUsers(unverifiedOrg);
Expand All @@ -403,7 +401,7 @@ void setIdentityVerified_withOktaMigrationDisabled_success() {
void setIdentityVerified_withOktaMigrationEnabled_success() {
when(featureFlagsConfig.isOktaMigrationEnabled()).thenReturn(true);
Organization unverifiedOrg =
testDataFactory.saveUnverifiedOrganizationWithUser("[email protected]");
_dataFactory.saveUnverifiedOrganizationWithUser("[email protected]");

boolean status = _service.setIdentityVerified(unverifiedOrg.getExternalId(), true);
verify(dbAuthorizationService, times(1)).getOrgAdminUsers(unverifiedOrg);
Expand Down Expand Up @@ -743,16 +741,16 @@ private void setupDataByFacility() {
new Organization("Org A", "k12", "d6b3951b-6698-4ee7-9d63-aaadee85bac0", true));
_dataFactory.createValidFacility(orgA, "Org A Facility 1", orgAStreetAddress);
_dataFactory.createValidFacility(orgA, "Org A Facility 2", orgAStreetAddress);
testDataFactory.createValidApiUser("[email protected]", orgA, Role.ADMIN);
_dataFactory.createValidApiUser("[email protected]", orgA, Role.ADMIN);

StreetAddress orgBStreetAddress =
new StreetAddress("234 Red Street", null, "Minneapolis", "MN", "55407", "Hennepin");
Organization orgB =
_dataFactory.saveOrganization(
new Organization("Org B", "airport", "747e341d-0467-45b8-b92f-a638da2bf1ee", true));
_dataFactory.createValidFacility(orgB, "Org B Facility 1", orgBStreetAddress);
testDataFactory.createValidApiUser("[email protected]", orgB, Role.ADMIN);
testDataFactory.createValidApiUser("[email protected]", orgB, Role.ADMIN);
_dataFactory.createValidApiUser("[email protected]", orgB, Role.ADMIN);
_dataFactory.createValidApiUser("[email protected]", orgB, Role.ADMIN);
}

private void setupDataByPatient() {
Expand All @@ -766,7 +764,7 @@ private void setupDataByPatient() {
_dataFactory.saveOrganization(
new Organization(
"Org A", "k12", "CA-org-a-5359aa13-93b2-4680-802c-9c90acb5d251", true));
testDataFactory.createValidApiUser("[email protected]", orgA, Role.ADMIN);
_dataFactory.createValidApiUser("[email protected]", orgA, Role.ADMIN);
Facility orgAFacility =
_dataFactory.createValidFacility(orgA, "Org A Facility 1", caStreetAddress);

Expand All @@ -779,8 +777,8 @@ private void setupDataByPatient() {
_dataFactory.saveOrganization(
new Organization(
"Org B", "airport", "MN-org-b-3dddkv89-8981-421b-bd61-f293723284", true));
testDataFactory.createValidApiUser("[email protected]", orgB, Role.ADMIN);
testDataFactory.createValidApiUser("[email protected]", orgB, Role.USER);
_dataFactory.createValidApiUser("[email protected]", orgB, Role.ADMIN);
_dataFactory.createValidApiUser("[email protected]", orgB, Role.USER);
Facility orgBFacility =
_dataFactory.createValidFacility(orgB, "Org B Facility 1", mnStreetAddress);
// create patient in CA with a test event for Org A
Expand Down

0 comments on commit 03c616a

Please sign in to comment.