Skip to content

Commit

Permalink
Merge pull request #97 from uphold/feature/user-verifications
Browse files Browse the repository at this point in the history
Add Verifications to user model
  • Loading branch information
SandroMachado authored Oct 4, 2017
2 parents bf2e875 + 9716920 commit 0ed81ce
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,44 +279,65 @@ public void getUserShouldReturnTheUser() throws Exception {
"\"country\": \"BAR\"," +
"\"state\": \"FOO\"," +
"\"currencies\": [" +
"\"BTC\"," +
"\"BTC\"," +
"]," +
"\"status\": \"ok\"," +
"\"settings\": {" +
"\"theme\": \"minimalistic\"," +
"\"currency\": \"USD\"," +
"\"hasNewsSubscription\": \"true\"," +
"\"intl\": {" +
"\"language\": {" +
"\"locale\": \"en-US\"" +
"}," +
"\"dateTimeFormat\": {" +
"\"locale\": \"en-US\"" +
"\"theme\": \"minimalistic\"," +
"\"currency\": \"USD\"," +
"\"hasNewsSubscription\": \"true\"," +
"\"intl\": {" +
"\"language\": {" +
"\"locale\": \"en-US\"" +
"}," +
"\"dateTimeFormat\": {" +
"\"locale\": \"en-US\"" +
"}," +
"\"numberFormat\": {" +
"\"locale\": \"en-US\"" +
"}" +
"}," +
"\"numberFormat\": {" +
"\"locale\": \"en-US\"" +
"\"otp\": {" +
"\"login\": {" +
"\"enabled\": false" +
"}," +
"\"transactions\": {" +
"\"send\": {" +
"\"enabled\": false" +
"}," +
"\"transfer\": {" +
"\"enabled\": true" +
"}," +
"\"withdraw\": {" +
"\"crypto\": {" +
"\"enabled\": true" +
"}" +
"}" +
"}" +
"}" +
"}," +
"\"otp\": {" +
"\"login\": {" +
"\"enabled\": false" +
"}," +
"\"verifications\": {" +
"\"email\": {" +
"\"status\": \"unconfirmed\"" +
"}," +
"\"transactions\": {" +
"\"send\": {" +
"\"enabled\": false" +
"}," +
"\"transfer\": {" +
"\"enabled\": true" +
"}," +
"\"withdraw\": {" +
"\"crypto\": {" +
"\"enabled\": true" +
"}" +
"}" +
"\"phone\": {" +
"\"status\": \"required\"" +
"}," +
"\"address\": {" +
"\"status\": \"required\"" +
"}," +
"\"identity\": {" +
"\"status\": \"required\"" +
"}," +
"\"location\": {" +
"\"reason\": \"state\"," +
"\"status\": \"required\"" +
"}," +
"\"birthdate\": {" +
"\"status\": \"required\"" +
"}" +
"}" +
"}" +
"}";
"}";
MockRestAdapter<User> adapter = new MockRestAdapter<>("foobar", responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, User>() {
Expand Down Expand Up @@ -358,6 +379,13 @@ public Promise<User> call(UpholdRestAdapter adapter) {
Assert.assertTrue(user.getSettings().getOtp().getTransactions().getTransfer().getEnabled());
Assert.assertTrue(user.getSettings().getOtp().getTransactions().getWithdraw().getCrypto().getEnabled());
Assert.assertTrue(user.getSettings().getHasNewsSubscription());
Assert.assertEquals(user.getVerifications().getAddress().getStatus(), "required");
Assert.assertEquals(user.getVerifications().getBirthdate().getStatus(), "required");
Assert.assertEquals(user.getVerifications().getEmail().getStatus(), "unconfirmed");
Assert.assertEquals(user.getVerifications().getIdentity().getStatus(), "required");
Assert.assertEquals(user.getVerifications().getLocation().getReason(), "state");
Assert.assertEquals(user.getVerifications().getLocation().getStatus(), "required");
Assert.assertEquals(user.getVerifications().getPhone().getStatus(), "required");
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,46 @@ public void getUsernameShouldReturnTheUsername() {
Assert.assertEquals(user.getUsername(), "foobar");
}

@Test
public void getVerificationsShouldReturnTheVerifications() {
HashMap<String, String> data = new HashMap<String, String>() {{
put("verificationsReasonAddress", "reasonAddress");
put("verificationsReasonBirthdate", "reasonBirthdate");
put("verificationsReasonDocuments", "reasonDocuments");
put("verificationsReasonEmail", "reasonEmail");
put("verificationsReasonIdentity", "reasonIdentity");
put("verificationsReasonLocation", "reasonLocation");
put("verificationsReasonPhone", "reasonPhone");
put("verificationsReasonTerms", "reasonTerms");
put("verificationsStatusAddress", "statusAddress");
put("verificationsStatusBirthdate", "statusBirthdate");
put("verificationsStatusDocuments", "statusDocuments");
put("verificationsStatusEmail", "statusEmail");
put("verificationsStatusIdentity", "statusIdentity");
put("verificationsStatusLocation", "statusLocation");
put("verificationsStatusPhone", "statusPhone");
put("verificationsStatusTerms", "statusTerms");
}};
User user = Fixtures.loadUser(data);

Assert.assertEquals(user.getVerifications().getAddress().getReason(), "reasonAddress");
Assert.assertEquals(user.getVerifications().getAddress().getStatus(), "statusAddress");
Assert.assertEquals(user.getVerifications().getBirthdate().getReason(), "reasonBirthdate");
Assert.assertEquals(user.getVerifications().getBirthdate().getStatus(), "statusBirthdate");
Assert.assertEquals(user.getVerifications().getDocuments().getReason(), "reasonDocuments");
Assert.assertEquals(user.getVerifications().getDocuments().getStatus(), "statusDocuments");
Assert.assertEquals(user.getVerifications().getEmail().getReason(), "reasonEmail");
Assert.assertEquals(user.getVerifications().getEmail().getStatus(), "statusEmail");
Assert.assertEquals(user.getVerifications().getIdentity().getReason(), "reasonIdentity");
Assert.assertEquals(user.getVerifications().getIdentity().getStatus(), "statusIdentity");
Assert.assertEquals(user.getVerifications().getLocation().getReason(), "reasonLocation");
Assert.assertEquals(user.getVerifications().getLocation().getStatus(), "statusLocation");
Assert.assertEquals(user.getVerifications().getPhone().getReason(), "reasonPhone");
Assert.assertEquals(user.getVerifications().getPhone().getStatus(), "statusPhone");
Assert.assertEquals(user.getVerifications().getTerms().getReason(), "reasonTerms");
Assert.assertEquals(user.getVerifications().getTerms().getStatus(), "statusTerms");
}

@Test
public void updateShouldReturnTheUser() throws Exception {
String responseString = "{ \"username\": \"FOOBAR\" }";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.uphold.uphold_android_sdk.model.user.ContactRequest;
import com.uphold.uphold_android_sdk.model.user.DocumentRequest;
import com.uphold.uphold_android_sdk.model.user.Settings;
import com.uphold.uphold_android_sdk.model.user.VerificationParameter;
import com.uphold.uphold_android_sdk.model.user.Verifications;
import com.uphold.uphold_android_sdk.model.user.settings.InternationalizationUserSettings;
import com.uphold.uphold_android_sdk.model.user.settings.Otp;
import com.uphold.uphold_android_sdk.model.user.settings.internationalizationusersettings.InternationalizationUserSetting;
Expand Down Expand Up @@ -328,6 +330,22 @@ public static User loadUser(HashMap<String, String> fields) {
put("status", faker.lorem().fixedString(10));
put("theme", faker.lorem().fixedString(10));
put("username", faker.lorem().fixedString(10));
put("verificationsReasonAddress", faker.lorem().fixedString(10));
put("verificationsReasonBirthdate", faker.lorem().fixedString(10));
put("verificationsReasonDocuments", faker.lorem().fixedString(10));
put("verificationsReasonEmail", faker.lorem().fixedString(10));
put("verificationsReasonIdentity", faker.lorem().fixedString(10));
put("verificationsReasonLocation", faker.lorem().fixedString(10));
put("verificationsReasonPhone", faker.lorem().fixedString(10));
put("verificationsReasonTerms", faker.lorem().fixedString(10));
put("verificationsStatusAddress", faker.lorem().fixedString(10));
put("verificationsStatusBirthdate", faker.lorem().fixedString(10));
put("verificationsStatusDocuments", faker.lorem().fixedString(10));
put("verificationsStatusEmail", faker.lorem().fixedString(10));
put("verificationsStatusIdentity", faker.lorem().fixedString(10));
put("verificationsStatusLocation", faker.lorem().fixedString(10));
put("verificationsStatusPhone", faker.lorem().fixedString(10));
put("verificationsStatusTerms", faker.lorem().fixedString(10));
}};

if (fields != null) {
Expand All @@ -345,8 +363,17 @@ public static User loadUser(HashMap<String, String> fields) {
InternationalizationUserSettings internationalizationUserSettings = new InternationalizationUserSettings(internationalizationUserSettingLanguage, internationalizationUserSettingDateTimeFormat, internationalizationUserSettingNumberFormat);
Otp otp = new Otp(new Login(Boolean.valueOf(fakerFields.get("settingsOTPLogin"))), new Transactions(new Send(Boolean.valueOf(fakerFields.get("settingsOTPTransactionsSend"))), new Transfer(Boolean.valueOf(fakerFields.get("settingsOTPTransactionsTransfer"))), new Withdraw(new Crypto(Boolean.valueOf(fakerFields.get("settingsOTPTransactionsWithdrawCrypto"))))));
Settings settings = new Settings(fakerFields.get("currency"), Boolean.valueOf(fakerFields.get("hasNewsSubscription")), Boolean.valueOf(fakerFields.get("hasOtpEnabled")), internationalizationUserSettings, otp, fakerFields.get("theme"));

return new User(fakerFields.get("country"), currencies, fakerFields.get("email"), fakerFields.get("firstName"), fakerFields.get("lastName"), fakerFields.get("memberAt"), fakerFields.get("name"), settings, fakerFields.get("state"), fakerFields.get("status"), fakerFields.get("username"));
VerificationParameter verificationsAddress = new VerificationParameter(fakerFields.get("verificationsReasonAddress"), fakerFields.get("verificationsStatusAddress"));
VerificationParameter verificationsBirthdate = new VerificationParameter(fakerFields.get("verificationsReasonBirthdate"), fakerFields.get("verificationsStatusBirthdate"));
VerificationParameter verificationsDocuments = new VerificationParameter(fakerFields.get("verificationsReasonDocuments"), fakerFields.get("verificationsStatusDocuments"));
VerificationParameter verificationsEmail = new VerificationParameter(fakerFields.get("verificationsReasonEmail"), fakerFields.get("verificationsStatusEmail"));
VerificationParameter verificationsIdentity = new VerificationParameter(fakerFields.get("verificationsReasonIdentity"), fakerFields.get("verificationsStatusIdentity"));
VerificationParameter verificationsLocation = new VerificationParameter(fakerFields.get("verificationsReasonLocation"), fakerFields.get("verificationsStatusLocation"));
VerificationParameter verificationsPhone = new VerificationParameter(fakerFields.get("verificationsReasonPhone"), fakerFields.get("verificationsStatusPhone"));
VerificationParameter verificationsTerms = new VerificationParameter(fakerFields.get("verificationsReasonTerms"), fakerFields.get("verificationsStatusTerms"));
Verifications verifications = new Verifications(verificationsAddress, verificationsBirthdate, verificationsDocuments, verificationsEmail, verificationsIdentity, verificationsLocation, verificationsPhone, verificationsTerms);

return new User(fakerFields.get("country"), currencies, fakerFields.get("email"), fakerFields.get("firstName"), fakerFields.get("lastName"), fakerFields.get("memberAt"), fakerFields.get("name"), settings, fakerFields.get("state"), fakerFields.get("status"), fakerFields.get("username"), verifications);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.uphold.uphold_android_sdk.model.user.Phone;
import com.uphold.uphold_android_sdk.model.user.Settings;
import com.uphold.uphold_android_sdk.model.user.Status;
import com.uphold.uphold_android_sdk.model.user.Verifications;
import com.uphold.uphold_android_sdk.paginator.Paginator;
import com.uphold.uphold_android_sdk.paginator.PaginatorInterface;
import com.uphold.uphold_android_sdk.service.AccountsService;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class User extends BaseModel implements Serializable {
private final String state;
private final String status;
private final String username;
private final Verifications verifications;

/**
* Constructor.
Expand All @@ -61,9 +63,10 @@ public class User extends BaseModel implements Serializable {
* @param state The user state
* @param status The user {@link Status}
* @param username The user username
* @param verifications The user user verifications
*/

public User(String country, List<String> currencies, String email, String firstName, String lastName, String memberAt, String name, Settings settings, String state, String status, String username) {
public User(String country, List<String> currencies, String email, String firstName, String lastName, String memberAt, String name, Settings settings, String state, String status, String username, Verifications verifications) {
this.country = country;
this.currencies = currencies;
this.email = email;
Expand All @@ -75,6 +78,7 @@ public User(String country, List<String> currencies, String email, String firstN
this.state = state;
this.status = status;
this.username = username;
this.verifications = verifications;
}

/**
Expand Down Expand Up @@ -514,6 +518,16 @@ public String getUsername() {
return username;
}

/**
* Gets the user verifications.
*
* @return the user verifications
*/

public Verifications getVerifications() {
return verifications;
}

/**
* Updates the user.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.uphold.uphold_android_sdk.model.user;

import java.io.Serializable;

/**
* VerificationParameter model.
*/

public class VerificationParameter implements Serializable {

private String reason;
private String status;

/**
* Constructor.
*
* @param reason The verification reason.
* @param status The verification status.
*/

public VerificationParameter(String reason, String status) {
this.reason = reason;
this.status = status;
}

/**
* Gets the verification reason.
*
* @return the verification reason.
*/

public String getReason() {
return reason;
}

/**
* Gets the verification status.
*
* @return the verification status.
*/

public String getStatus() {
return status;
}

}
Loading

0 comments on commit 0ed81ce

Please sign in to comment.