Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/main/java/com/descope/sdk/mgmt/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ UserResponseDetails updateEmail(String loginId, String email, Boolean isVerified
* Update the email address for an existing user.
*
* @param loginId The loginID is required.
* @param email The email parameter can be empty in which case the email will be removed.
* @param isVerified The isVerified flag must be true for the user to be able to login with the
* email address.
* @param failOnConflict The failOnConflict flag indicates whether to fail the update if the new
* email is also the login ID of another user.
* @return {@link UserResponseDetails UserResponseDetails}
* @throws DescopeException If there occurs any exception, a subtype of this exception will be
* thrown.
*/
UserResponseDetails updateEmail(String loginId, String email, Boolean isVerified,
Comment thread
shuni-bot[bot] marked this conversation as resolved.
Boolean failOnConflict) throws DescopeException;

/**
* Update the phone number for an existing user.
*
* @param loginId The loginID is required.
* @param phone The phone parameter can be empty in which case the phone will be removed.
* @param isVerified The isVerified flag must be true for the user to be able to login with the
* email address.
Expand All @@ -250,6 +266,22 @@ UserResponseDetails updateEmail(String loginId, String email, Boolean isVerified
UserResponseDetails updatePhone(String loginId, String phone, Boolean isVerified)
throws DescopeException;

/**
* Update the phone number for an existing user.
*
* @param loginId The loginID is required.
* @param phone The phone parameter can be empty in which case the phone will be removed.
* @param isVerified The isVerified flag must be true for the user to be able to login with the
* email address.
* @param failOnConflict The failOnConflict flag indicates whether to fail the update if the new
* phone number is also the login ID of another user.
* @return {@link UserResponseDetails UserResponseDetails}
* @throws DescopeException If there occurs any exception, a subtype of this exception will be
* thrown.
*/
UserResponseDetails updatePhone(String loginId, String phone, Boolean isVerified,
Comment thread
shuni-bot[bot] marked this conversation as resolved.
Boolean failOnConflict) throws DescopeException;

/**
* Update an existing user's display name (i.e., their full name).
*
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/com/descope/sdk/mgmt/impl/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,36 @@ public UserResponseDetails deactivate(String loginId) throws DescopeException {

@Override
public UserResponseDetails updateEmail(String loginId, String email, Boolean isVerified) throws DescopeException {
return updateEmail(loginId, email, isVerified, false);
}

@Override
public UserResponseDetails updateEmail(String loginId, String email, Boolean isVerified,
Boolean failOnConflict) throws DescopeException {
if (StringUtils.isBlank(loginId)) {
throw ServerCommonException.invalidArgument("Login ID");
}
URI updateEmailUri = composeUpdateEmailUri();
Map<String, Object> request = mapOf("loginId", loginId, "email", email, "verified", isVerified);
Map<String, Object> request = mapOf("loginId", loginId, "email", email, "verified", isVerified,
"failOnConflict", failOnConflict);
ApiProxy apiProxy = getApiProxy();
return apiProxy.post(updateEmailUri, request, UserResponseDetails.class);
}

@Override
public UserResponseDetails updatePhone(String loginId, String phone, Boolean isVerified) throws DescopeException {
return updatePhone(loginId, phone, isVerified, false);
}

@Override
public UserResponseDetails updatePhone(String loginId, String phone, Boolean isVerified,
Boolean failOnConflict) throws DescopeException {
if (StringUtils.isBlank(loginId)) {
throw ServerCommonException.invalidArgument("Login ID");
}
URI updatePhoneUri = composeUpdatePhoneUri();
Map<String, Object> request = mapOf("loginId", loginId, "phone", phone, "verified", isVerified);
Map<String, Object> request = mapOf("loginId", loginId, "phone", phone, "verified", isVerified,
"failOnConflict", failOnConflict);
ApiProxy apiProxy = getApiProxy();
return apiProxy.post(updatePhoneUri, request, UserResponseDetails.class);
}
Expand Down
28 changes: 26 additions & 2 deletions src/test/java/com/descope/sdk/mgmt/impl/UserServiceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,18 @@ void testUpdateEmailForSuccess() {
}
}

@Test
void testUpdateEmailWithFailOnConflictForSuccess() {
UserResponseDetails userResponseDetails = mock(UserResponseDetails.class);
ApiProxy apiProxy = mock(ApiProxy.class);
doReturn(userResponseDetails).when(apiProxy).post(any(), any(), any());
try (MockedStatic<ApiProxyBuilder> mockedApiProxyBuilder = mockStatic(ApiProxyBuilder.class)) {
mockedApiProxyBuilder.when(() -> ApiProxyBuilder.buildProxy(any(), any())).thenReturn(apiProxy);
UserResponseDetails response = userService.updateEmail("someLoginId", "someEmail", false, true);
Assertions.assertThat(response).isNotNull();
}
}

@Test
void testUpdatePhoneForEmptyLoginId() {
ServerCommonException thrown = assertThrows(ServerCommonException.class,
Expand All @@ -387,6 +399,18 @@ void testUpdatePhoneForSuccess() {
}
}

@Test
void testUpdatePhoneWithFailOnConflictForSuccess() {
UserResponseDetails userResponseDetails = mock(UserResponseDetails.class);
ApiProxy apiProxy = mock(ApiProxy.class);
doReturn(userResponseDetails).when(apiProxy).post(any(), any(), any());
try (MockedStatic<ApiProxyBuilder> mockedApiProxyBuilder = mockStatic(ApiProxyBuilder.class)) {
mockedApiProxyBuilder.when(() -> ApiProxyBuilder.buildProxy(any(), any())).thenReturn(apiProxy);
UserResponseDetails response = userService.updatePhone("someLoginId", "1234567890", false, true);
Assertions.assertThat(response).isNotNull();
}
}

@Test
void testUpdateDisplayNameForEmptyLoginId() {
ServerCommonException thrown = assertThrows(ServerCommonException.class,
Expand Down Expand Up @@ -886,8 +910,8 @@ void testFunctionalFullCycle() {
userService.updateDisplayName(loginId, "Testing Test");
userService.updateDisplayNames(loginId, "G Test", "M Test", "F Test");
email = TestUtils.getRandomName("test-") + "@descope.com";
userService.updateEmail(loginId, email, true);
userService.updatePhone(loginId, "+1-555-555-6666", true);
userService.updateEmail(loginId, email, true, false);
userService.updatePhone(loginId, "+1-555-555-6666", true, false);
String newLoginId = TestUtils.getRandomName("u-");
userService.updateLoginId(loginId, newLoginId);
UserResponseDetails loadResponse = userService.load(newLoginId);
Expand Down