use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.
the class BridgeUtilsTest method accountHasValidIdentifierInvalid.
@Test
public void accountHasValidIdentifierInvalid() {
Account account = Account.create();
account.setEnrollments(null);
assertFalse(BridgeUtils.hasValidIdentifier(account));
account = Account.create();
Enrollment en1 = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
account.setEnrollments(ImmutableSet.of(en1));
assertFalse(BridgeUtils.hasValidIdentifier(account));
account = Account.create();
account.setEnrollments(ImmutableSet.of());
assertFalse(BridgeUtils.hasValidIdentifier(account));
}
use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.
the class BridgeUtilsTest method externalIdsVisibleToCaller.
@Test
public void externalIdsVisibleToCaller() {
Set<String> callerStudies = ImmutableSet.of("studyA", "studyB", "studyD");
RequestContext.set(new RequestContext.Builder().withCallerUserId(TEST_USER_ID).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).withOrgSponsoredStudies(callerStudies).build());
Enrollment enA = Enrollment.create(TEST_APP_ID, "studyA", "id", "extA");
Enrollment enB = Enrollment.create(TEST_APP_ID, "studyB", "id", "extB");
Enrollment enC = Enrollment.create(TEST_APP_ID, "studyC", "id", "extC");
Account account = Account.create();
account.setId("id");
account.setEnrollments(ImmutableSet.of(enA, enB, enC));
Map<String, String> visibles = BridgeUtils.studyAssociationsVisibleToCaller(account).getExternalIdsVisibleToCaller();
assertEquals(visibles, ImmutableMap.of("studyA", "extA", "studyB", "extB"));
}
use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.
the class BridgeUtilsTest method participantEligibleForDeletion_affiliatedResearcherAllowed.
@Test
public void participantEligibleForDeletion_affiliatedResearcherAllowed() {
RequestContext.set(new RequestContext.Builder().withOrgSponsoredStudies(USER_STUDY_IDS).withCallerRoles(ImmutableSet.of(RESEARCHER)).build());
RequestInfoService mockService = mock(RequestInfoService.class);
Account account = Account.create();
account.setEnrollments(STUDY_A_AND_B_ENROLLMENT);
assertTrue(participantEligibleForDeletion(mockService, account));
}
use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.
the class BridgeUtilsTest method participantEligibleForDeletion_multipleEnrollmentsFail.
@Test
public void participantEligibleForDeletion_multipleEnrollmentsFail() {
RequestContext.set(new RequestContext.Builder().withOrgSponsoredStudies(// mismatch
ImmutableSet.of("studyA", "studyC")).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).build());
RequestInfoService mockService = mock(RequestInfoService.class);
Account account = Account.create();
account.setEnrollments(STUDY_A_AND_B_ENROLLMENT);
assertFalse(participantEligibleForDeletion(mockService, account));
}
use of org.sagebionetworks.bridge.models.accounts.Account in project BridgeServer2 by Sage-Bionetworks.
the class BridgeUtilsTest method studyIdsVisibleToCallerFilters.
@Test
public void studyIdsVisibleToCallerFilters() {
Set<String> callerStudies = ImmutableSet.of("studyA", "studyB", "studyD");
RequestContext.set(new RequestContext.Builder().withCallerUserId("callerUserId").withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).withOrgSponsoredStudies(callerStudies).build());
Enrollment enA = Enrollment.create(TEST_APP_ID, "studyA", "id");
Enrollment enB = Enrollment.create(TEST_APP_ID, "studyB", "id");
Enrollment enC = Enrollment.create(TEST_APP_ID, "studyC", "id");
Account account = Account.create();
account.setEnrollments(ImmutableSet.of(enA, enB, enC));
Set<String> visibles = BridgeUtils.studyAssociationsVisibleToCaller(account).getStudyIdsVisibleToCaller();
assertEquals(visibles, ImmutableSet.of("studyA", "studyB"));
}
Aggregations