From 1572be83fa23f6ec33dcc5d4fc360450c607679e Mon Sep 17 00:00:00 2001 From: Diogo Moreira Date: Fri, 15 Apr 2016 18:01:48 +0100 Subject: [PATCH] Update transaction commit request model with security code --- .../integration/model/TransactionTest.java | 43 +++++++++++++++++++ .../service/UserCardServiceTest.java | 2 +- .../transaction/TransactionCommitRequest.java | 25 ++++++++++- .../TransactionCommitRequestTest.java | 15 ++++++- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/TransactionTest.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/TransactionTest.java index d321461..a727af6 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/TransactionTest.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/TransactionTest.java @@ -361,6 +361,49 @@ public Promise call(UpholdRestAdapter adapter) { Assert.assertEquals(bodyOutput.toString(), "{\"message\":\"foobar\"}"); } + @Test + public void commitWithMessageAndSecurityCodeShouldReturnTheTransaction() throws Exception { + ByteArrayOutputStream bodyOutput = new ByteArrayOutputStream(); + String responseString = "{ \"id\": \"foobar\" }"; + + MockRestAdapter adapter = new MockRestAdapter<>("foobar", responseString, null); + + adapter.request(new RepromiseFunction() { + @Override + public Promise call(UpholdRestAdapter adapter) { + Transaction transaction = Fixtures.loadTransaction(new HashMap() {{ + 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(); diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/service/UserCardServiceTest.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/service/UserCardServiceTest.java index 3ed4110..1639bd5 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/service/UserCardServiceTest.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/service/UserCardServiceTest.java @@ -72,7 +72,7 @@ public Promise call(UpholdRestAdapter upholdRestAdapter) { UserCardService userCardService = adapter.getRestAdapter().create(UserCardService.class); RetrofitPromise promise = new RetrofitPromise<>(); - userCardService.confirmTransaction("foo", "bar", new TransactionCommitRequest("message"), "otp", promise); + userCardService.confirmTransaction("foo", "bar", new TransactionCommitRequest("message", "securityCode"), "otp", promise); return promise; } diff --git a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/transaction/TransactionCommitRequest.java b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/transaction/TransactionCommitRequest.java index 298b85f..37f56b2 100644 --- a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/transaction/TransactionCommitRequest.java +++ b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/transaction/TransactionCommitRequest.java @@ -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. * @@ -30,4 +43,14 @@ public String getMessage() { return message; } + /** + * Gets the transaction security code. + * + * @return the transaction security code + */ + + public String getSecurityCode() { + return securityCode; + } + } diff --git a/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/transaction/TransactionCommitRequestTest.java b/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/transaction/TransactionCommitRequestTest.java index ec71c81..59c4676 100644 --- a/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/transaction/TransactionCommitRequestTest.java +++ b/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/transaction/TransactionCommitRequestTest.java @@ -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; @@ -16,7 +17,7 @@ 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); @@ -24,4 +25,14 @@ public void shouldBeSerializable() { 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()); + } + }