Skip to content

Commit

Permalink
Merge pull request #90 from uphold/feature/add-documents-endpoint
Browse files Browse the repository at this point in the history
Add support for the documents endpoint
  • Loading branch information
SandroMachado authored Apr 18, 2017
2 parents 0713f1f + 2919d58 commit 900d33d
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.uphold.uphold_android_sdk.model.card.CardRequest;
import com.uphold.uphold_android_sdk.model.card.Settings;
import com.uphold.uphold_android_sdk.model.user.Contact;
import com.uphold.uphold_android_sdk.model.user.Document;
import com.uphold.uphold_android_sdk.model.user.Phone;
import com.uphold.uphold_android_sdk.paginator.Paginator;
import com.uphold.uphold_android_sdk.test.BuildConfig;
Expand Down Expand Up @@ -129,6 +130,31 @@ public Promise<Contact> call(UpholdRestAdapter adapter) {
Assert.assertEquals(contact.getName(), "Foo Bar");
}

@Test
public void createDocumentShouldReturnTheDocument() throws Exception {
String responseString = "{\"type\": \"foo\", \"value\": \"bar\"}";
MockRestAdapter<Document> adapter = new MockRestAdapter<>("foobar", responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Document>() {
@Override
public Promise<Document> call(UpholdRestAdapter adapter) {
User user = Fixtures.loadUser();

user.setUpholdRestAdapter(adapter);

return user.createDocument(Fixtures.loadDocumentRequest());
}
});

Document document = adapter.getResult();
Request request = adapter.getRequest();

Assert.assertEquals(request.getMethod(), "POST");
Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/documents", BuildConfig.API_SERVER_URL));
Assert.assertEquals(document.getType(), "foo");
Assert.assertEquals(document.getValue(), "bar");
}

@Test
public void getAccountByIdShouldReturnTheAccountWithId() throws Exception {
String responseString = "{ \"currency\": \"FOO\", \"id\": \"FOOBAR\", \"label\": \"BAR\", \"status\": \"FOO BAR\", \"type\": \"Bar\" }";
Expand Down Expand Up @@ -410,6 +436,32 @@ public void getCurrenciesShouldReturnTheListOfCurrencies() {
Assert.assertEquals(user.getCurrencies().get(2), "EUR");
}

@Test
public void getDocumentsShouldReturnTheListOfDocuments() throws Exception {
String responseString = "[{\"type\": \"foo\", \"value\": \"bar\"}]";
MockRestAdapter<List<Document>> adapter = new MockRestAdapter<>("foobar", responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Document>>() {
@Override
public Promise<List<Document>> call(UpholdRestAdapter adapter) {
User user = Fixtures.loadUser();

user.setUpholdRestAdapter(adapter);

return user.getDocuments();
}
});

List<Document> documents = adapter.getResult();
Request request = adapter.getRequest();

Assert.assertEquals(request.getMethod(), "GET");
Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/documents", BuildConfig.API_SERVER_URL));
Assert.assertEquals(documents.size(), 1);
Assert.assertEquals(documents.get(0).getType(), "foo");
Assert.assertEquals(documents.get(0).getValue(), "bar");
}

@Test
public void getEmailShouldReturnTheEmail() {
User user = Fixtures.loadUser(new HashMap<String, String>() {{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.uphold.uphold_android_sdk.test.integration.model.user;

import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

import com.uphold.uphold_android_sdk.model.user.DocumentRequest;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;

/**
* DocumentRequest integration tests.
*/

@RunWith(AndroidJUnit4.class)
@SmallTest
public class DocumentRequestTest {

@Test
public void getTypeShouldReturnTheType() {
DocumentRequest documentRequest = new DocumentRequest("foo", "bar");

Assert.assertEquals(documentRequest.getType(), "foo");
}

@Test
public void getValueShouldReturnTheValue() {
DocumentRequest documentRequest = new DocumentRequest("foo", "bar");

Assert.assertEquals(documentRequest.getValue(), "bar");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.uphold.uphold_android_sdk.test.integration.model.user;

import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

import com.uphold.uphold_android_sdk.model.user.Document;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Document integration tests.
*/

@RunWith(AndroidJUnit4.class)
@SmallTest
public class DocumentTest {

@Test
public void getTypeShouldReturnTheType() {
Document document = new Document("foo", "bar");

Assert.assertEquals(document.getType(), "foo");
}

@Test
public void getValueShouldReturnTheValue() {
Document document = new Document("foo", "bar");

Assert.assertEquals(document.getValue(), "bar");
}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package com.uphold.uphold_android_sdk.test.integration.service;

import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

import com.darylteo.rx.promises.java.Promise;
import com.darylteo.rx.promises.java.functions.RepromiseFunction;

import junit.framework.Assert;

import com.uphold.uphold_android_sdk.client.restadapter.UpholdRestAdapter;
import com.uphold.uphold_android_sdk.client.retrofitpromise.RetrofitPromise;
import com.uphold.uphold_android_sdk.model.Balance;
import com.uphold.uphold_android_sdk.model.Transaction;
import com.uphold.uphold_android_sdk.model.User;
import com.uphold.uphold_android_sdk.model.user.Contact;
import com.uphold.uphold_android_sdk.model.user.Document;
import com.uphold.uphold_android_sdk.model.user.Phone;
import com.uphold.uphold_android_sdk.service.UserService;
import com.uphold.uphold_android_sdk.test.util.Fixtures;
import com.uphold.uphold_android_sdk.test.BuildConfig;
import com.uphold.uphold_android_sdk.test.util.Fixtures;
import com.uphold.uphold_android_sdk.test.util.MockRestAdapter;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;

import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -58,6 +59,50 @@ public Promise<Contact> call(UpholdRestAdapter upholdRestAdapter) {
Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/contacts", BuildConfig.API_SERVER_URL));
}

@Test
public void createDocumentShouldReturnTheRequest() throws Exception {
final MockRestAdapter<Document> adapter = new MockRestAdapter<>(null, null, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Document>() {
@Override
public Promise<Document> call(UpholdRestAdapter upholdRestAdapter) {
UserService userService = adapter.getRestAdapter().create(UserService.class);
RetrofitPromise<Document> promise = new RetrofitPromise<>();

userService.createDocument(Fixtures.loadDocumentRequest(), promise);

return promise;
}
});

Request request = adapter.getRequest();

Assert.assertEquals(request.getMethod(), "POST");
Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/documents", BuildConfig.API_SERVER_URL));
}

@Test
public void getDocumentsShouldReturnTheRequest() throws Exception {
final MockRestAdapter<List<Document>> adapter = new MockRestAdapter<>(null, null, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, List<Document>>() {
@Override
public Promise<List<Document>> call(UpholdRestAdapter upholdRestAdapter) {
UserService userService = adapter.getRestAdapter().create(UserService.class);
RetrofitPromise<List<Document>> promise = new RetrofitPromise<>();

userService.getDocuments(promise);

return promise;
}
});

Request request = adapter.getRequest();

Assert.assertEquals(request.getMethod(), "GET");
Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/documents", BuildConfig.API_SERVER_URL));
}

@Test
public void getUserShouldReturnTheRequest() throws Exception {
final MockRestAdapter<User> adapter = new MockRestAdapter<>(null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.uphold.uphold_android_sdk.model.transaction.TransactionDepositRequest;
import com.uphold.uphold_android_sdk.model.transaction.TransactionTransferRequest;
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.settings.InternationalizationUserSettings;
import com.uphold.uphold_android_sdk.model.user.settings.Otp;
Expand Down Expand Up @@ -127,6 +128,24 @@ public static ContactRequest loadContactRequest(HashMap<String, String> fields)
return new ContactRequest(addresses, fakerFields.get("company"), emails, fakerFields.get("firstName"), fakerFields.get("lastName"));
}

public static DocumentRequest loadDocumentRequest() {
return loadDocumentRequest(null);
}

public static DocumentRequest loadDocumentRequest(HashMap<String, String> fields) {
final Faker faker = new Faker();
final HashMap<String, String> fakerFields = new HashMap<String, String>() {{
put("type", faker.lorem().fixedString(5));
put("value", faker.lorem().fixedString(5));
}};

if (fields != null) {
fakerFields.putAll(fields);
}

return new DocumentRequest(fakerFields.get("type"), fakerFields.get("value"));
}

public static Transaction loadTransaction() {
return loadTransaction(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.darylteo.rx.promises.java.Promise;
import com.darylteo.rx.promises.java.functions.PromiseFunction;

import com.uphold.uphold_android_sdk.client.retrofitpromise.RetrofitPaginatorPromise;
import com.uphold.uphold_android_sdk.client.retrofitpromise.RetrofitPromise;
import com.uphold.uphold_android_sdk.model.balance.Currency;
import com.uphold.uphold_android_sdk.model.balance.UserBalance;
import com.uphold.uphold_android_sdk.model.card.CardRequest;
import com.uphold.uphold_android_sdk.model.user.Contact;
import com.uphold.uphold_android_sdk.model.user.ContactRequest;
import com.uphold.uphold_android_sdk.model.user.Document;
import com.uphold.uphold_android_sdk.model.user.DocumentRequest;
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;
Expand Down Expand Up @@ -114,6 +115,23 @@ public Contact call(Contact contact) {
});
}

/**
* Creates a document for the user.
*
* @param documentRequest The {@link DocumentRequest} with the information to create the document.
*
* @return a {@link Promise< Document >} with the document created.
*/

public Promise<Document> createDocument(DocumentRequest documentRequest) {
RetrofitPromise<Document> promise = new RetrofitPromise<>();
UserService userService = this.getUpholdRestAdapter().create(UserService.class);

userService.createDocument(documentRequest, promise);

return promise;
}

/**
* Gets the user's accounts.
*
Expand Down Expand Up @@ -299,6 +317,21 @@ public List<String> getCurrencies() {
return currencies;
}

/**
* Gets the user documents.
*
* @return a promise {@link Promise<List<Document>>} with the list of user documents.
*/

public Promise<List<Document>> getDocuments() {
RetrofitPromise<List<Document>> promise = new RetrofitPromise<>();
UserService userService = this.getUpholdRestAdapter().create(UserService.class);

userService.getDocuments(promise);

return promise;
}

/**
* Gets the user email.
*
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;

/**
* Document model.
*/

public class Document implements Serializable {

private final String type;
private final String value;

/**
* Constructor.
*
* @param type The document type.
* @param value The document value.
*/

public Document(String type, String value) {
this.type = type;
this.value = value;
}

/**
* Gets the document type.
*
* @return the document type.
*/

public String getType() {
return type;
}

/**
* Gets the document value.
*
* @return the document value.
*/

public String getValue() {
return value;
}

}
Loading

0 comments on commit 900d33d

Please sign in to comment.