Search in sources :

Example 1 with IdentifierUpdate

use of org.sagebionetworks.bridge.models.accounts.IdentifierUpdate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantControllerTest method updateIdentifiersWithPhone.

@Test
public void updateIdentifiersWithPhone() throws Exception {
    mockRequestBody(mockRequest, PHONE_UPDATE);
    when(mockParticipantService.updateIdentifiers(eq(app), any(), any())).thenReturn(participant);
    JsonNode result = controller.updateIdentifiers();
    assertEquals(result.get("id").textValue(), TEST_USER_ID);
    verify(mockParticipantService).updateIdentifiers(eq(app), contextCaptor.capture(), identifierUpdateCaptor.capture());
    verify(mockCacheProvider).setUserSession(sessionCaptor.capture());
    assertEquals(sessionCaptor.getValue().getId(), participant.getId());
    IdentifierUpdate update = identifierUpdateCaptor.getValue();
    assertEquals(update.getSignIn().getEmail(), EMAIL_PASSWORD_SIGN_IN_REQUEST.getEmail());
    assertEquals(update.getSignIn().getPassword(), EMAIL_PASSWORD_SIGN_IN_REQUEST.getPassword());
    assertEquals(update.getPhoneUpdate(), PHONE);
    assertNull(update.getEmailUpdate());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IdentifierUpdate(org.sagebionetworks.bridge.models.accounts.IdentifierUpdate) Test(org.testng.annotations.Test)

Example 2 with IdentifierUpdate

use of org.sagebionetworks.bridge.models.accounts.IdentifierUpdate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantControllerTest method updateIdentifiersWithSynapseUserId.

@Test
public void updateIdentifiersWithSynapseUserId() throws Exception {
    mockRequestBody(mockRequest, SYNAPSE_ID_UPDATE);
    when(mockParticipantService.updateIdentifiers(eq(app), any(), any())).thenReturn(participant);
    JsonNode result = controller.updateIdentifiers();
    assertEquals(result.get("id").textValue(), TEST_USER_ID);
    verify(mockParticipantService).updateIdentifiers(eq(app), contextCaptor.capture(), identifierUpdateCaptor.capture());
    IdentifierUpdate update = identifierUpdateCaptor.getValue();
    assertEquals(update.getSignIn().getEmail(), EMAIL_PASSWORD_SIGN_IN_REQUEST.getEmail());
    assertEquals(update.getSignIn().getPassword(), EMAIL_PASSWORD_SIGN_IN_REQUEST.getPassword());
    assertEquals(update.getSynapseUserIdUpdate(), SYNAPSE_USER_ID);
    assertNull(update.getPhoneUpdate());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IdentifierUpdate(org.sagebionetworks.bridge.models.accounts.IdentifierUpdate) Test(org.testng.annotations.Test)

Example 3 with IdentifierUpdate

use of org.sagebionetworks.bridge.models.accounts.IdentifierUpdate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantController method updateIdentifiers.

@PostMapping("/v3/participants/self/identifiers")
public JsonNode updateIdentifiers() {
    UserSession session = getAuthenticatedSession();
    IdentifierUpdate update = parseJson(IdentifierUpdate.class);
    App app = appService.getApp(session.getAppId());
    CriteriaContext context = getCriteriaContext(session);
    StudyParticipant participant = participantService.updateIdentifiers(app, context, update);
    sessionUpdateService.updateParticipant(session, context, participant);
    return UserSessionInfo.toJSON(session);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) IdentifierUpdate(org.sagebionetworks.bridge.models.accounts.IdentifierUpdate) CriteriaContext(org.sagebionetworks.bridge.models.CriteriaContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with IdentifierUpdate

use of org.sagebionetworks.bridge.models.accounts.IdentifierUpdate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantServiceTest method updateIdentifiersValidatesWithInvalidPhone.

@Test(expectedExceptions = InvalidEntityException.class)
public void updateIdentifiersValidatesWithInvalidPhone() {
    IdentifierUpdate update = new IdentifierUpdate(EMAIL_PASSWORD_SIGN_IN, null, new Phone("US", "1231231234"), null);
    participantService.updateIdentifiers(APP, CONTEXT, update);
}
Also used : Phone(org.sagebionetworks.bridge.models.accounts.Phone) IdentifierUpdate(org.sagebionetworks.bridge.models.accounts.IdentifierUpdate) Test(org.testng.annotations.Test)

Example 5 with IdentifierUpdate

use of org.sagebionetworks.bridge.models.accounts.IdentifierUpdate in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantServiceTest method updateIdentifiersAddsSynapseUserId.

@Test
public void updateIdentifiersAddsSynapseUserId() {
    mockAccountNoEmail();
    when(accountService.authenticate(APP, EMAIL_PASSWORD_SIGN_IN)).thenReturn(account);
    when(accountService.getAccount(any())).thenReturn(Optional.of(account));
    IdentifierUpdate update = new IdentifierUpdate(EMAIL_PASSWORD_SIGN_IN, EMAIL, null, SYNAPSE_USER_ID);
    participantService.updateIdentifiers(APP, CONTEXT, update);
    assertEquals(account.getSynapseUserId(), SYNAPSE_USER_ID);
}
Also used : IdentifierUpdate(org.sagebionetworks.bridge.models.accounts.IdentifierUpdate) Test(org.testng.annotations.Test)

Aggregations

IdentifierUpdate (org.sagebionetworks.bridge.models.accounts.IdentifierUpdate)35 Test (org.testng.annotations.Test)32 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)14 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 Phone (org.sagebionetworks.bridge.models.accounts.Phone)5 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)2 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)2 App (org.sagebionetworks.bridge.models.apps.App)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)1