use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.
the class UserService method getUserListBySearch.
/**
* Will return and sync a list of contacts matching the search term, from the server.
*
* <p>Note: The local contacts are also updated locally.</p>
*
* <p>Note: This method has database and network operation. Run it asynchronously.</p>
*
* @param searchString the search term
* @return a list of users (as Contact objects)
* @throws ApplozicException when the backend returns an error response
*/
@Nullable
public List<Contact> getUserListBySearch(@Nullable String searchString) throws ApplozicException {
try {
ApiResponse response = userClientService.getUsersBySearchString(searchString);
if (response == null) {
return null;
}
if (response.isSuccess()) {
UserDetail[] userDetails = (UserDetail[]) GsonUtils.getObjectFromJson(GsonUtils.getJsonFromObject(response.getResponse(), List.class), UserDetail[].class);
List<Contact> contactList = new ArrayList<>();
for (UserDetail userDetail : userDetails) {
contactList.add(getContactFromUserDetail(userDetail));
}
return contactList;
} else {
if (response.getErrorResponse() != null && !response.getErrorResponse().isEmpty()) {
throw new ApplozicException(GsonUtils.getJsonFromObject(response.getErrorResponse(), List.class));
}
}
} catch (Exception e) {
throw new ApplozicException(e.getMessage());
}
return null;
}
use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.
the class UserServiceTest method processUserBlockSuccess.
@Test
public void processUserBlockSuccess() {
ApiResponse expectedFailureApiResponse = new ApiResponse();
expectedFailureApiResponse.setStatus("success");
Mockito.when(userClientService.userBlock(testUserId, true)).thenReturn(expectedFailureApiResponse);
ApiResponse actualSuccessApiResponse = userService.processUserBlock(testUserId, true);
Truth.assertThat(actualSuccessApiResponse).isNotNull();
// in applozic as of the date this test is written, only the status of the ApiResponse is used
Truth.assertThat(actualSuccessApiResponse.getStatus()).isEqualTo("success");
Mockito.verify(appContactService, Mockito.times(1)).updateUserBlocked(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean());
}
use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.
the class UserServiceTest method updateUserDisplayNameFailureNull.
@Test
public void updateUserDisplayNameFailureNull() {
// Note: return value from userService.updateUserDisplayName() is not used
ApiResponse apiResponse = new ApiResponse();
apiResponse.setStatus("anything but success");
Mockito.when(userClientService.updateUserDisplayName(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(apiResponse);
ApiResponse actualApiResponse = userService.updateUserDisplayName(testUserId, "Display Name");
Mockito.verify(appContactService, Mockito.never()).updateMetadataKeyValueForUserId(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString());
Truth.assertThat(actualApiResponse).isEqualTo(apiResponse);
}
use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.
the class UserServiceTest method muteUserNotifications.
@Test
public void muteUserNotifications() {
ApiResponse expectedApiResponse = new ApiResponse();
expectedApiResponse.setStatus("success");
Mockito.when(userClientService.muteUserNotifications(ArgumentMatchers.anyString(), ArgumentMatchers.anyLong())).thenReturn(expectedApiResponse);
ApiResponse apiResponse = userService.muteUserNotifications(ArgumentMatchers.anyString(), ArgumentMatchers.anyLong());
Truth.assertThat(apiResponse).isEqualTo(expectedApiResponse);
Truth.assertThat(apiResponse.isSuccess()).isTrue();
}
use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.
the class UserServiceTest method updateUserWithResponse.
@Test
public void updateUserWithResponse() {
ApiResponse expectedApiResponse = new ApiResponse();
expectedApiResponse.setStatus("success");
Mockito.when(userClientService.updateDisplayNameORImageLink("displayName", "profileImageLink", "status", "contactNumber", "emailId", null, "userId")).thenReturn(expectedApiResponse);
Mockito.when(appContactService.getContactById(ArgumentMatchers.anyString())).thenReturn(new Contact());
ApiResponse apiResponse = userService.updateUserWithResponse("displayName", "profileImageLink", "localURL", "status", "contactNumber", "emailId", null, "userId");
Truth.assertThat(apiResponse).isEqualTo(expectedApiResponse);
Mockito.verify(appContactService, Mockito.times(1)).upsert(ArgumentMatchers.any(Contact.class));
}
Aggregations