From 97169200a30caaaad4ac31db8b440be75c221c40 Mon Sep 17 00:00:00 2001 From: Diogo Moreira Date: Fri, 29 Sep 2017 14:15:20 +0100 Subject: [PATCH] Add Verifications to user model --- .../integration/client/UpholdClientTest.java | 88 ++++++++----- .../test/integration/model/UserTest.java | 40 ++++++ .../test/util/Fixtures.java | 31 ++++- .../uphold/uphold_android_sdk/model/User.java | 16 ++- .../model/user/VerificationParameter.java | 46 +++++++ .../model/user/Verifications.java | 124 ++++++++++++++++++ .../test/unit/model/UserTest.java | 29 +++- 7 files changed, 340 insertions(+), 34 deletions(-) create mode 100644 src/app/src/main/java/com/uphold/uphold_android_sdk/model/user/VerificationParameter.java create mode 100644 src/app/src/main/java/com/uphold/uphold_android_sdk/model/user/Verifications.java diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/client/UpholdClientTest.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/client/UpholdClientTest.java index 04ed6ee..f5fe2a6 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/client/UpholdClientTest.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/client/UpholdClientTest.java @@ -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 adapter = new MockRestAdapter<>("foobar", responseString, null); adapter.request(new RepromiseFunction() { @@ -358,6 +379,13 @@ public Promise 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 diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/UserTest.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/UserTest.java index 6916380..38a859d 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/UserTest.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/UserTest.java @@ -777,6 +777,46 @@ public void getUsernameShouldReturnTheUsername() { Assert.assertEquals(user.getUsername(), "foobar"); } + @Test + public void getVerificationsShouldReturnTheVerifications() { + HashMap data = new HashMap() {{ + 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\" }"; diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/util/Fixtures.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/util/Fixtures.java index f170ba6..6eab13c 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/util/Fixtures.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/util/Fixtures.java @@ -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; @@ -328,6 +330,22 @@ public static User loadUser(HashMap 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) { @@ -345,8 +363,17 @@ public static User loadUser(HashMap 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); } } diff --git a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/User.java b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/User.java index 1e86d5c..2500070 100644 --- a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/User.java +++ b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/User.java @@ -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; @@ -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. @@ -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 currencies, String email, String firstName, String lastName, String memberAt, String name, Settings settings, String state, String status, String username) { + public User(String country, List 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; @@ -75,6 +78,7 @@ public User(String country, List currencies, String email, String firstN this.state = state; this.status = status; this.username = username; + this.verifications = verifications; } /** @@ -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. * diff --git a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/user/VerificationParameter.java b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/user/VerificationParameter.java new file mode 100644 index 0000000..2020614 --- /dev/null +++ b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/user/VerificationParameter.java @@ -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; + } + +} diff --git a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/user/Verifications.java b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/user/Verifications.java new file mode 100644 index 0000000..237acf2 --- /dev/null +++ b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/user/Verifications.java @@ -0,0 +1,124 @@ +package com.uphold.uphold_android_sdk.model.user; + +import java.io.Serializable; + +/** + * Verifications model. + */ + +public class Verifications implements Serializable { + + private VerificationParameter address; + private VerificationParameter birthdate; + private VerificationParameter documents; + private VerificationParameter email; + private VerificationParameter identity; + private VerificationParameter location; + private VerificationParameter phone; + private VerificationParameter terms; + + /** + * Constructor. + * + * @param address The address verification. + * @param birthdate The birthdate verification. + * @param documents The documents verification. + * @param email The email verification. + * @param identity The identity verification. + * @param location The location verification. + * @param phone The phone verification. + * @param terms The terms verification. + */ + + public Verifications(VerificationParameter address, VerificationParameter birthdate, VerificationParameter documents, VerificationParameter email, VerificationParameter identity, VerificationParameter location, VerificationParameter phone, VerificationParameter terms) { + this.address = address; + this.birthdate = birthdate; + this.documents = documents; + this.email = email; + this.identity = identity; + this.location = location; + this.phone = phone; + this.terms = terms; + } + + /** + * Gets the address verification. + * + * @return the address verification. + */ + + public VerificationParameter getAddress() { + return address; + } + + /** + * Gets the birthdate verification. + * + * @return the birthdate verification. + */ + + public VerificationParameter getBirthdate() { + return birthdate; + } + + /** + * Gets the documents verification. + * + * @return the documents verification. + */ + + public VerificationParameter getDocuments() { + return documents; + } + + /** + * Gets the email verification. + * + * @return the email verification. + */ + + public VerificationParameter getEmail() { + return email; + } + + /** + * Gets the identity verification. + * + * @return the identity verification. + */ + + public VerificationParameter getIdentity() { + return identity; + } + + /** + * Gets the location verification. + * + * @return the location verification. + */ + + public VerificationParameter getLocation() { + return location; + } + + /** + * Gets the phone verification. + * + * @return the phone verification. + */ + + public VerificationParameter getPhone() { + return phone; + } + + /** + * Gets the terms verification. + * + * @return the terms verification. + */ + + public VerificationParameter getTerms() { + return terms; + } + +} diff --git a/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/UserTest.java b/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/UserTest.java index ad6d302..033c349 100644 --- a/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/UserTest.java +++ b/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/UserTest.java @@ -1,6 +1,8 @@ package com.uphold.uphold_android_sdk.test.unit.model; import com.uphold.uphold_android_sdk.model.User; +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.InternationalizationUserSetting; import com.uphold.uphold_android_sdk.model.user.settings.InternationalizationUserSettings; import com.uphold.uphold_android_sdk.model.user.settings.otp.Login; @@ -37,7 +39,16 @@ public void shouldBeSerializable() { Otp otp = new Otp(new Login(false), new Transactions(new Send(false), new Transfer(false), new Withdraw(new Crypto(true)))); Settings settings = new Settings("FIZ", true, false, internationalizationUserSettings, otp, "FUZ"); ArrayList currencies = new ArrayList<>(); - User user = new User("foobar", currencies, "foobar@foo.com", "foo", "bar", "foobar", "Foo Bar", settings, "foobiz", "foobar", "fizbiz"); + VerificationParameter addressVerification = new VerificationParameter("address", "required"); + VerificationParameter birthdateVerification = new VerificationParameter("birthdate", "required"); + VerificationParameter documentsVerification = new VerificationParameter("documents", "required"); + VerificationParameter emailVerification = new VerificationParameter("email", "unconfirmed"); + VerificationParameter identityVerification = new VerificationParameter("identity", "required"); + VerificationParameter locationVerification = new VerificationParameter("location", "required"); + VerificationParameter phoneVerification = new VerificationParameter("phone", "required"); + VerificationParameter termsVerification = new VerificationParameter("terms", "required"); + Verifications verifications = new Verifications(addressVerification, birthdateVerification, documentsVerification, emailVerification, identityVerification, locationVerification, phoneVerification, termsVerification); + User user = new User("foobar", currencies, "foobar@foo.com", "foo", "bar", "foobar", "Foo Bar", settings, "foobiz", "foobar", "fizbiz", verifications); currencies.add("EUR"); currencies.add("USD"); @@ -67,6 +78,22 @@ public void shouldBeSerializable() { Assert.assertEquals(user.getState(), deserializedUser.getState()); Assert.assertEquals(user.getStatus(), deserializedUser.getStatus()); Assert.assertEquals(user.getUsername(), deserializedUser.getUsername()); + Assert.assertEquals(user.getVerifications().getAddress().getReason(), deserializedUser.getVerifications().getAddress().getReason()); + Assert.assertEquals(user.getVerifications().getAddress().getStatus(), deserializedUser.getVerifications().getAddress().getStatus()); + Assert.assertEquals(user.getVerifications().getBirthdate().getReason(), deserializedUser.getVerifications().getBirthdate().getReason()); + Assert.assertEquals(user.getVerifications().getBirthdate().getStatus(), deserializedUser.getVerifications().getBirthdate().getStatus()); + Assert.assertEquals(user.getVerifications().getDocuments().getReason(), deserializedUser.getVerifications().getDocuments().getReason()); + Assert.assertEquals(user.getVerifications().getDocuments().getStatus(), deserializedUser.getVerifications().getDocuments().getStatus()); + Assert.assertEquals(user.getVerifications().getEmail().getReason(), deserializedUser.getVerifications().getEmail().getReason()); + Assert.assertEquals(user.getVerifications().getEmail().getStatus(), deserializedUser.getVerifications().getEmail().getStatus()); + Assert.assertEquals(user.getVerifications().getIdentity().getReason(), deserializedUser.getVerifications().getIdentity().getReason()); + Assert.assertEquals(user.getVerifications().getIdentity().getStatus(), deserializedUser.getVerifications().getIdentity().getStatus()); + Assert.assertEquals(user.getVerifications().getLocation().getReason(), deserializedUser.getVerifications().getLocation().getReason()); + Assert.assertEquals(user.getVerifications().getLocation().getStatus(), deserializedUser.getVerifications().getLocation().getStatus()); + Assert.assertEquals(user.getVerifications().getPhone().getReason(), deserializedUser.getVerifications().getPhone().getReason()); + Assert.assertEquals(user.getVerifications().getPhone().getStatus(), deserializedUser.getVerifications().getPhone().getStatus()); + Assert.assertEquals(user.getVerifications().getTerms().getReason(), deserializedUser.getVerifications().getTerms().getReason()); + Assert.assertEquals(user.getVerifications().getTerms().getStatus(), deserializedUser.getVerifications().getTerms().getStatus()); } }