Skip to content

Commit

Permalink
Merge pull request #123 from braintree/pwv
Browse files Browse the repository at this point in the history
Pay With Venmo
  • Loading branch information
Quinn Neumiiller committed Dec 8, 2015
2 parents f65d029 + 0547536 commit 254c1e7
Show file tree
Hide file tree
Showing 51 changed files with 1,504 additions and 72 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"clientApiUrl": "client_api_url",
"environment": "test",
"merchantId": "integration_merchant_id",
"merchantAccountId": "integration_merchant_account_id",
"payWithVenmo": {
"accessToken" : "access-token"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public void newInstance_returnsABraintreeFragmentFromAClientToken()

@Test(timeout = 1000, expected = InvalidArgumentException.class)
@SmallTest
public void newInstance_throwsAnExceptionForABadTokenizationKey() throws InvalidArgumentException {
public void newInstance_throwsAnExceptionForABadTokenizationKey()
throws InvalidArgumentException {
BraintreeFragment.newInstance(mActivity, "test_key_merchant");
}

Expand Down Expand Up @@ -125,7 +126,7 @@ public void newInstance_setsIntegrationTypeToCustomForAllActivities()

@Test(timeout = 1000)
@SmallTest
public void sendsAnalyticsEventForTokenizationKey() throws InterruptedException{
public void sendsAnalyticsEventForTokenizationKey() throws InterruptedException {
BraintreeFragment fragment = getFragment(mActivity, TOKENIZATION_KEY);
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
Expand Down Expand Up @@ -333,7 +334,8 @@ public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {

@Test(timeout = 1000)
@SmallTest
public void addListener_flushesPaymentMethodNoncesUpdatedCallback() throws InterruptedException {
public void addListener_flushesPaymentMethodNoncesUpdatedCallback()
throws InterruptedException {
BraintreeFragment fragment = getFragment(mActivity, mClientToken);
fragment.postCallback(new ArrayList<PaymentMethodNonce>());

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.braintreepayments.api.internal;

import android.os.SystemClock;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;

import com.braintreepayments.api.BuildConfig;

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

import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

@RunWith(AndroidJUnit4.class)
public class SignatureVerificationTest {

@Test(timeout = 15000)
@LargeTest
public void isSignatureValid_returnsFalseWhenAppNotInstalled() {
if (!BuildConfig.RUN_ALL_TESTS) {
return;
}

Log.d("request_command", "uninstall fakewallet");
SystemClock.sleep(10000);

assertFalse(checkSignature());
}

@Test(timeout = 65000)
@LargeTest
public void isSignatureValid_returnsTrueWhenAppIsInstalled() {
if (!BuildConfig.RUN_ALL_TESTS) {
return;
}

Log.d("request_command", "install fakewallet");
SystemClock.sleep(60000);

assertTrue(checkSignature());
}

private boolean checkSignature() {
return SignatureVerification.isSignatureValid(getTargetContext(), "com.braintreepayments.fake.wallet",
"CN=Android Debug,O=Android,C=US", "CN=Android Debug,O=Android,C=US", 496242318);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.braintreepayments.api.internal;

public class SignatureVerificationTestUtils {

public static void disableSignatureVerification() {
SignatureVerification.sEnableSignatureVerification = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import org.json.JSONException;
import org.junit.Test;
Expand Down Expand Up @@ -114,6 +115,26 @@ public void fromJson_parsesMerchantAccountId() throws JSONException {
assertEquals("integration_merchant_account_id", configuration.getMerchantAccountId());
}

@Test(timeout = 1000)
@SmallTest
public void returnsEmptyVenmoConfigurationWhenNotDefined() throws JSONException {
Configuration configuration = Configuration.fromJson(
stringFromFixture("configuration.json"));

assertNotNull(configuration.getPayWithVenmo());
assertTrue(TextUtils.isEmpty(configuration.getPayWithVenmo().getAccessToken()));
}

@Test(timeout = 1000)
@SmallTest
public void payWithVenmoIsEnabledWhenConfigurationExists() throws JSONException {
Configuration configuration = Configuration.fromJson(
stringFromFixture("configuration_with_pay_with_venmo.json"));

assertNotNull(configuration.getPayWithVenmo());
assertFalse(TextUtils.isEmpty(configuration.getPayWithVenmo().getAccessToken()));
}

@Test(timeout = 1000)
@SmallTest
public void reportsThreeDSecureEnabledWhenEnabled() throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.braintreepayments.api.models;

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

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

import static junit.framework.Assert.assertEquals;

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

private static final String NONCE = "nonce";
private static final String DESCRIPTION = "description";
private static final String USERNAME = "username";
private static final VenmoAccountNonce
VENMO_NONCE = new VenmoAccountNonce(NONCE, DESCRIPTION, USERNAME);

@Test(timeout = 1000)
public void getTypeLabel_returnsPayWithVenmo() {
assertEquals("Venmo", VENMO_NONCE.getTypeLabel());
}

@Test(timeout = 1000)
public void getNonce_returnsNonce() {
assertEquals(NONCE, VENMO_NONCE.getNonce());
}

@Test(timeout = 1000)
public void getDescription_returnsDescription() {
assertEquals(DESCRIPTION, VENMO_NONCE.getDescription());
}

@Test(timeout = 1000)
public void getUsername_returnsUsername() {
assertEquals(USERNAME, VENMO_NONCE.getUsername());
}

@Test(timeout = 1000)
public void writeToParcel_parcelsVenmoAccountNonce() {
Parcel parcel = Parcel.obtain();
VENMO_NONCE.writeToParcel(parcel, 0);
parcel.setDataPosition(0);

VenmoAccountNonce venmoAccountNonce = new VenmoAccountNonce(parcel);
assertEquals(NONCE, venmoAccountNonce.getNonce());
assertEquals(DESCRIPTION, venmoAccountNonce.getDescription());
assertEquals(USERNAME, venmoAccountNonce.getUsername());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.braintreepayments.api.models;

import android.support.test.runner.AndroidJUnit4;
import android.test.mock.MockContext;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;

import com.braintreepayments.api.internal.SignatureVerificationTestUtils;
import com.braintreepayments.testutils.MockContextForVenmo;

import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static com.braintreepayments.testutils.FixturesHelper.stringFromFixture;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

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

private Configuration configurationWithVenmo;

@Before
public void setup() throws JSONException {
configurationWithVenmo = Configuration.fromJson(
stringFromFixture("configuration_with_pay_with_venmo.json"));
}

@Test(timeout = 1000)
public void fromJson_parsesPayWithVenmoConfiguration() throws JSONException {
assertEquals("access-token", configurationWithVenmo.getPayWithVenmo().getAccessToken());
}

@Test(timeout = 1000)
public void fromJson_parsesEmptyVenmoConfigurationWhenConfigurationDoesntHavePayWithVenmo()
throws JSONException {
Configuration configuration = Configuration.fromJson(
stringFromFixture("configuration.json"));

VenmoConfiguration venmoConfiguration = configuration.getPayWithVenmo();
assertEquals("", venmoConfiguration.getAccessToken());
assertTrue(TextUtils.isEmpty(venmoConfiguration.getAccessToken()));
}

@Test(timeout = 1000)
public void isEnabled_returnsTrueWhenEnabled() throws JSONException {
VenmoConfiguration venmoConfiguration = configurationWithVenmo.getPayWithVenmo();
assertFalse(TextUtils.isEmpty(venmoConfiguration.getAccessToken()));
}

@Test(timeout = 1000)
public void isVenmoWhitelisted_returnsTrueForWhitelist() throws JSONException {
MockContext mockContext = new MockContextForVenmo()
.whitelistValue("true")
.build();

assertTrue(configurationWithVenmo.getPayWithVenmo()
.isVenmoWhitelisted(mockContext.getContentResolver()));
}

@Test(timeout = 1000)
public void isVenmoWhitelisted_returnsFalseForInvalidWhitelist() {
MockContext mockContext = new MockContextForVenmo()
.whitelistValue("false")
.build();

assertFalse(configurationWithVenmo.getPayWithVenmo()
.isVenmoWhitelisted(mockContext.getContentResolver()));
}

@Test(timeout = 1000)
public void isVenmoWhitelisted_returnsFalseForJunkContentProviderAndExceptionIsPosted() {
MockContext mockContext = new MockContextForVenmo()
.whitelistValue("neither")
.build();

assertFalse(configurationWithVenmo.getPayWithVenmo()
.isVenmoWhitelisted(mockContext.getContentResolver()));
}

@Test(timeout = 1000)
public void isEnabled_returnsTrueWhenAppIsInstalled() throws JSONException {
MockContext mockContext = new MockContextForVenmo()
.whitelistValue("true")
.venmoInstalled()
.build();

SignatureVerificationTestUtils.disableSignatureVerification();

assertTrue(configurationWithVenmo.getPayWithVenmo().isEnabled(mockContext));
}

@Test(timeout = 1000)
public void isEnabled_returnsFalseForNotInstalled() {
MockContext mockContext = new MockContextForVenmo()
.whitelistValue("true")
.build();

SignatureVerificationTestUtils.disableSignatureVerification();

assertFalse(configurationWithVenmo.getPayWithVenmo().isEnabled(mockContext));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ public void onActivityResult(final int requestCode, int resultCode, Intent data)
case ThreeDSecure.THREE_D_SECURE_REQUEST_CODE:
ThreeDSecure.onActivityResult(this, resultCode, data);
break;
case Venmo.VENMO_REQUEST_CODE:
Venmo.onActivityResult(this, resultCode, data);
break;
}

if (resultCode == Activity.RESULT_CANCELED) {
Expand Down
Loading

0 comments on commit 254c1e7

Please sign in to comment.