Skip to content

Commit

Permalink
Merge pull request #80 from uphold/enhancement/update-card-request-model
Browse files Browse the repository at this point in the history
Update card request model
  • Loading branch information
ruipenso committed Apr 15, 2016
2 parents d5ab6df + 6e67bfa commit 46c9983
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,18 @@ user.getCards().then(new PromiseAction<List<Card>>() {
### Create new card

```java
// You can create a simple card request with just the label and the currency.
CardRequest cardRequest = new CardRequest("label", "USD");
user.createCard(cardRequest);

// Or a card request with the label, currency, position and whether it is starred or not.
CardRequest cardRequest = new CardRequest("label", "USD", new Settings(1, true));
user.createCard(cardRequest);
```

Handling the success and error flow:

```java
CardRequest cardRequest = new CardRequest("label", "USD");
user.createCard(cardRequest).then(new PromiseAction<Card>() {
@Override
public void call(Card card) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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.card.Settings;
import com.uphold.uphold_android_sdk.model.user.Contact;
import com.uphold.uphold_android_sdk.model.user.Phone;
import com.uphold.uphold_android_sdk.paginator.Paginator;
Expand Down Expand Up @@ -70,7 +71,7 @@ public Promise<Card> call(UpholdRestAdapter adapter) {

user.setUpholdRestAdapter(adapter);

return user.createCard(new CardRequest("foo", "BTC"));
return user.createCard(new CardRequest("foo", "BTC", new Settings(7, true)));
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.uphold.uphold_android_sdk.test.integration.model.card;

import junit.framework.Assert;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;

import com.uphold.uphold_android_sdk.model.card.CardRequest;
import com.uphold.uphold_android_sdk.model.card.Settings;

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;

/**
* CardRequest integration tests.
*/
Expand All @@ -31,4 +33,18 @@ public void getCurrencyShouldReturnTheCurrency() {
Assert.assertEquals(cardRequest.getCurrency(), "bar");
}

@Test
public void getSettingsPositionShouldReturnTheSettingsPosition() {
CardRequest cardRequest = new CardRequest("foo", "bar", new Settings(0, true));

Assert.assertEquals((int) cardRequest.getSettings().getPosition(), 0);
}

@Test
public void getSettingsStarredShouldReturnTheSettingsStarred() {
CardRequest cardRequest = new CardRequest("foo", "bar", new Settings(0, true));

Assert.assertEquals((boolean) cardRequest.getSettings().getStarred(), true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.uphold.uphold_android_sdk.model.Card;
import com.uphold.uphold_android_sdk.model.Transaction;
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.transaction.TransactionCardDepositRequest;
import com.uphold.uphold_android_sdk.model.transaction.TransactionCommitRequest;
import com.uphold.uphold_android_sdk.model.transaction.TransactionDenominationRequest;
Expand Down Expand Up @@ -181,6 +182,28 @@ public Promise<Card> call(UpholdRestAdapter upholdRestAdapter) {
Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/cards", BuildConfig.API_SERVER_URL));
}

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

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

userCardService.createUserCard(new CardRequest("foo", "bar", new Settings(0, true)), promise);

return promise;
}
});

Request request = adapter.getRequest();

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

@Test
public void getUserCardByIdShouldReturnTheRequest() throws Exception {
final MockRestAdapter<Card> adapter = new MockRestAdapter<>(null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CardRequest implements Serializable {

private final String label;
private final String currency;
private final Settings settings;

/**
* Constructor.
Expand All @@ -21,6 +22,21 @@ public class CardRequest implements Serializable {
public CardRequest(String label, String currency) {
this.label = label;
this.currency = currency;
this.settings = null;
}

/**
* Constructor.
*
* @param label The label of the card.
* @param currency The currency of the card.
* @param settings The settings of the card.
*/

public CardRequest(String label, String currency, Settings settings) {
this.label = label;
this.currency = currency;
this.settings = settings;
}

/**
Expand All @@ -43,4 +59,14 @@ public String getCurrency() {
return currency;
}

/**
* Gets the settings of the card.
*
* @return the settings of the card
*/

public Settings getSettings() {
return settings;
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.uphold.uphold_android_sdk.test.unit.model.card;

import com.uphold.uphold_android_sdk.model.card.CardRequest;
import com.uphold.uphold_android_sdk.model.card.Settings;

import junit.framework.Assert;

import org.apache.commons.lang3.SerializationUtils;
import com.uphold.uphold_android_sdk.model.card.CardRequest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -16,7 +18,7 @@
public class CardRequestTest {

@Test
public void shouldBeSerializable() {
public void cardRequestShouldBeSerializable() {
CardRequest cardRequest = new CardRequest("foo", "bar");
byte[] serializedCardRequest = SerializationUtils.serialize(cardRequest);
CardRequest deserializedCardRequest = SerializationUtils.deserialize(serializedCardRequest);
Expand All @@ -25,4 +27,16 @@ public void shouldBeSerializable() {
Assert.assertEquals(cardRequest.getLabel(), deserializedCardRequest.getLabel());
}

@Test
public void cardRequestWithSettingsshouldBeSerializable() {
CardRequest cardRequest = new CardRequest("foo", "bar", new Settings(0, true));
byte[] serializedCardRequest = SerializationUtils.serialize(cardRequest);
CardRequest deserializedCardRequest = SerializationUtils.deserialize(serializedCardRequest);

Assert.assertEquals(cardRequest.getCurrency(), deserializedCardRequest.getCurrency());
Assert.assertEquals(cardRequest.getLabel(), deserializedCardRequest.getLabel());
Assert.assertEquals(cardRequest.getSettings().getPosition(), deserializedCardRequest.getSettings().getPosition());
Assert.assertEquals(cardRequest.getSettings().getStarred(), deserializedCardRequest.getSettings().getStarred());
}

}

0 comments on commit 46c9983

Please sign in to comment.