Skip to content

Commit

Permalink
Update transaction commit request model with security code
Browse files Browse the repository at this point in the history
  • Loading branch information
d-moreira committed Apr 18, 2016
1 parent f2f731a commit 1572be8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,49 @@ public Promise<Transaction> call(UpholdRestAdapter adapter) {
Assert.assertEquals(bodyOutput.toString(), "{\"message\":\"foobar\"}");
}

@Test
public void commitWithMessageAndSecurityCodeShouldReturnTheTransaction() throws Exception {
ByteArrayOutputStream bodyOutput = new ByteArrayOutputStream();
String responseString = "{ \"id\": \"foobar\" }";

MockRestAdapter<Transaction> adapter = new MockRestAdapter<>("foobar", responseString, null);

adapter.request(new RepromiseFunction<UpholdRestAdapter, Transaction>() {
@Override
public Promise<Transaction> call(UpholdRestAdapter adapter) {
Transaction transaction = Fixtures.loadTransaction(new HashMap<String, String>() {{
put("transactionStatus", "pending");
put("originCardId", "foo");
put("transactionId", "bar");
}});

transaction.setUpholdRestAdapter(adapter);

return transaction.commit(new TransactionCommitRequest("foobar", "foo"));
}
});

Header otpHeader = null;
Request request = adapter.getRequest();
Transaction transaction = adapter.getResult();

for (Header header : request.getHeaders()) {
if (header.getName().compareToIgnoreCase("X-Bitreserve-OTP") == 0) {
otpHeader = header;

break;
}
}

request.getBody().writeTo(bodyOutput);

Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/cards/foo/transactions/bar/commit", BuildConfig.API_SERVER_URL));
Assert.assertEquals(request.getMethod(), "POST");
Assert.assertNull(otpHeader);
Assert.assertEquals(transaction.getId(), "foobar");
Assert.assertEquals(bodyOutput.toString(), "{\"message\":\"foobar\",\"securityCode\":\"foo\"}");
}

@Test
public void commitWithOTPShouldReturnTheTransaction() throws Exception {
ByteArrayOutputStream bodyOutput = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Promise<Transaction> call(UpholdRestAdapter upholdRestAdapter) {
UserCardService userCardService = adapter.getRestAdapter().create(UserCardService.class);
RetrofitPromise<Transaction> promise = new RetrofitPromise<>();

userCardService.confirmTransaction("foo", "bar", new TransactionCommitRequest("message"), "otp", promise);
userCardService.confirmTransaction("foo", "bar", new TransactionCommitRequest("message", "securityCode"), "otp", promise);

return promise;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,30 @@
public class TransactionCommitRequest implements Serializable {

String message;
String securityCode;

/**
* Constructor.
*
* @param message The transanction message.
* @param message The transaction message.
*/

public TransactionCommitRequest(String message) {
this.message = message;
}

/**
* Constructor.
*
* @param message The transaction message.
* @param securityCode The transaction security code.
*/

public TransactionCommitRequest(String message, String securityCode) {
this.message = message;
this.securityCode = securityCode;
}

/**
* Gets the transaction request message.
*
Expand All @@ -30,4 +43,14 @@ public String getMessage() {
return message;
}

/**
* Gets the transaction security code.
*
* @return the transaction security code
*/

public String getSecurityCode() {
return securityCode;
}

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

import com.uphold.uphold_android_sdk.model.transaction.TransactionCommitRequest;

import junit.framework.Assert;

import org.apache.commons.lang3.SerializationUtils;
import com.uphold.uphold_android_sdk.model.transaction.TransactionCommitRequest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -16,12 +17,22 @@
public class TransactionCommitRequestTest {

@Test
public void shouldBeSerializable() {
public void shouldBeSerializableTransactionCommitRequest() {
TransactionCommitRequest transactionCommitRequest = new TransactionCommitRequest("foobar");
byte[] serializedTransactionCommitRequestTest = SerializationUtils.serialize(transactionCommitRequest);
TransactionCommitRequest deserializedTransactionCommitRequestTest = SerializationUtils.deserialize(serializedTransactionCommitRequestTest);

Assert.assertEquals(transactionCommitRequest.getMessage(), deserializedTransactionCommitRequestTest.getMessage());
}

@Test
public void shouldBeSerializableTransactionCommitRequestWithSecurityCode() {
TransactionCommitRequest transactionCommitRequest = new TransactionCommitRequest("foobar", "foo");
byte[] serializedTransactionCommitRequestTest = SerializationUtils.serialize(transactionCommitRequest);
TransactionCommitRequest deserializedTransactionCommitRequestTest = SerializationUtils.deserialize(serializedTransactionCommitRequestTest);

Assert.assertEquals(transactionCommitRequest.getMessage(), deserializedTransactionCommitRequestTest.getMessage());
Assert.assertEquals(transactionCommitRequest.getSecurityCode(), deserializedTransactionCommitRequestTest.getSecurityCode());
}

}

0 comments on commit 1572be8

Please sign in to comment.