use of org.sagebionetworks.bridge.models.RequestInfo in project BridgeServer2 by Sage-Bionetworks.
the class BridgeUtilsTest method participantEligibleForDeletion_testUserAllowedAfterSignIn.
@Test
public void participantEligibleForDeletion_testUserAllowedAfterSignIn() {
RequestInfoService mockService = mock(RequestInfoService.class);
Account account = Account.create();
account.setDataGroups(ImmutableSet.of(TEST_USER_GROUP));
// User has signed in, and is still eligible for deletion
RequestInfoService mockRequestService = mock(RequestInfoService.class);
RequestInfo requestInfo = new RequestInfo.Builder().withSignedInOn(CREATED_ON).build();
when(mockRequestService.getRequestInfo(TEST_USER_ID)).thenReturn(requestInfo);
assertTrue(participantEligibleForDeletion(mockService, account));
}
use of org.sagebionetworks.bridge.models.RequestInfo in project BridgeServer2 by Sage-Bionetworks.
the class CacheProviderTest method getRequestInfoNewCache.
@Test
public void getRequestInfoNewCache() throws Exception {
RequestInfo info = new RequestInfo.Builder().withUserId(USER_ID).build();
when(jedisOps.get(REQUEST_INFO_KEY)).thenReturn(BridgeObjectMapper.get().writeValueAsString(info));
RequestInfo returned = cacheProvider.getRequestInfo(USER_ID);
assertEquals(info, returned);
verify(jedisOps).get(REQUEST_INFO_KEY);
}
use of org.sagebionetworks.bridge.models.RequestInfo in project BridgeServer2 by Sage-Bionetworks.
the class AccountsController method getRequestInfo.
@GetMapping(path = { "/v1/accounts/{userId}/requestInfo" }, produces = { APPLICATION_JSON_UTF8_VALUE })
public String getRequestInfo(@PathVariable String userId) throws JsonProcessingException {
UserSession session = getAuthenticatedSession(ORG_ADMIN);
verifyOrgAdminIsActingOnOrgMember(session, userId);
// RequestInfo is accessible because the user is accessible, no reason to
// test again.
RequestInfo requestInfo = requestInfoService.getRequestInfo(userId);
if (requestInfo == null) {
requestInfo = new RequestInfo.Builder().build();
}
return REQUEST_INFO_WRITER.writeValueAsString(requestInfo);
}
use of org.sagebionetworks.bridge.models.RequestInfo in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledActivityControllerTest method getScheduledActivitiesV4.
@Test
public void getScheduledActivitiesV4() throws Exception {
DateTimeZone zone = DateTimeZone.forOffsetHours(4);
DateTime startsOn = DateTime.now(zone).minusMinutes(1);
DateTime endsOn = DateTime.now(zone).plusDays(7);
mockEditAccount(mockAccountService, mockAccount);
String result = controller.getScheduledActivitiesByDateRange(startsOn.toString(), endsOn.toString());
JsonNode node = BridgeObjectMapper.get().readTree(result);
assertEquals(node.get("startTime").textValue(), startsOn.toString());
assertEquals(node.get("endTime").textValue(), endsOn.toString());
verify(sessionUpdateService).updateTimeZone(any(UserSession.class), timeZoneCaptor.capture());
verify(mockRequestInfoService).updateRequestInfo(requestInfoCaptor.capture());
verify(mockScheduledActivityService).getScheduledActivitiesV4(eq(APP), contextCaptor.capture());
verify(controller).persistTimeZone(session, zone);
verify(mockAccount).setTimeZone(zone);
assertEquals(startsOn.getZone(), timeZoneCaptor.getValue());
RequestInfo requestInfo = requestInfoCaptor.getValue();
assertEquals(requestInfo.getUserId(), "id");
assertEquals(requestInfo.getClientInfo(), CLIENT_INFO);
assertEquals(requestInfo.getUserAgent(), USER_AGENT);
assertEquals(requestInfo.getLanguages(), LANGUAGES);
assertEquals(requestInfo.getUserDataGroups(), USER_DATA_GROUPS);
assertEquals(requestInfo.getUserStudyIds(), USER_STUDY_IDS);
assertTrue(requestInfo.getActivitiesAccessedOn().isAfter(startsOn));
assertNull(requestInfo.getSignedInOn());
assertEquals(requestInfo.getAppId(), TEST_APP_ID);
ScheduleContext context = contextCaptor.getValue();
assertEquals(context.getInitialTimeZone(), startsOn.getZone());
// To make the range inclusive, we need to adjust timestamp to right before the start instant
// This value is not mirrored back in the response (see test above of the response).
assertEquals(context.getStartsOn(), startsOn.minusMillis(1));
assertEquals(context.getEndsOn(), endsOn);
assertEquals(0, context.getMinimumPerSchedule());
assertEquals(context.getAccountCreatedOn(), ACCOUNT_CREATED_ON.withZone(DateTimeZone.UTC));
CriteriaContext critContext = context.getCriteriaContext();
assertEquals(critContext.getAppId(), TEST_APP_ID);
assertEquals(critContext.getHealthCode(), HEALTH_CODE);
assertEquals(critContext.getUserId(), ID);
assertEquals(critContext.getClientInfo(), CLIENT_INFO);
assertEquals(critContext.getUserDataGroups(), USER_DATA_GROUPS);
assertEquals(critContext.getUserStudyIds(), USER_STUDY_IDS);
assertEquals(critContext.getLanguages(), LANGUAGES);
}
use of org.sagebionetworks.bridge.models.RequestInfo in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledActivityControllerTest method getScheduledActivtiesAssemblesCorrectContext.
@SuppressWarnings("deprecation")
@Test
public void getScheduledActivtiesAssemblesCorrectContext() throws Exception {
mockEditAccount(mockAccountService, mockAccount);
DateTimeZone MSK = DateTimeZone.forOffsetHours(3);
List<ScheduledActivity> list = ImmutableList.of();
when(mockScheduledActivityService.getScheduledActivities(eq(APP), any(ScheduleContext.class))).thenReturn(list);
controller.getScheduledActivities(null, "+03:00", "3", "5");
verify(mockScheduledActivityService).getScheduledActivities(eq(APP), contextCaptor.capture());
ScheduleContext context = contextCaptor.getValue();
assertEquals(context.getInitialTimeZone(), MSK);
assertEquals(context.getCriteriaContext().getUserDataGroups(), USER_DATA_GROUPS);
assertEquals(context.getMinimumPerSchedule(), 5);
CriteriaContext critContext = context.getCriteriaContext();
assertEquals(critContext.getHealthCode(), HEALTH_CODE);
assertEquals(critContext.getLanguages(), LANGUAGES);
assertEquals(critContext.getUserStudyIds(), USER_STUDY_IDS);
assertEquals(critContext.getAppId(), TEST_APP_ID);
assertEquals(critContext.getClientInfo(), CLIENT_INFO);
verify(mockRequestInfoService).updateRequestInfo(requestInfoCaptor.capture());
RequestInfo requestInfo = requestInfoCaptor.getValue();
assertEquals(requestInfo.getUserId(), "id");
assertEquals(requestInfo.getLanguages(), LANGUAGES);
assertEquals(requestInfo.getUserDataGroups(), USER_DATA_GROUPS);
assertEquals(requestInfo.getUserStudyIds(), USER_STUDY_IDS);
assertEquals(requestInfo.getAppId(), TEST_APP_ID);
assertEquals(requestInfo.getUserAgent(), USER_AGENT);
assertEquals(requestInfo.getClientInfo(), CLIENT_INFO);
assertNotNull(requestInfo.getActivitiesAccessedOn());
assertEquals(requestInfo.getActivitiesAccessedOn().getZone(), MSK);
verify(sessionUpdateService).updateTimeZone(session, MSK);
// Verify that the account mock was updated with the anticipated time zone (however
// it's a mock as is sessionUpdateService, so this doesn't change RequestInfo, as it's
// based on changes to the session.
verify(mockAccount).setTimeZone(MSK);
}
Aggregations