Skip to content

Commit

Permalink
Merge 24fac78 into b0ac0fd
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon6193 committed May 22, 2019
2 parents b0ac0fd + 24fac78 commit 76add97
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 193 deletions.
Expand Up @@ -62,7 +62,7 @@ final class ButtonApiImpl implements ButtonApi {
private final String userAgent;

@VisibleForTesting
String baseUrl = "https://%s.mobileapi.usebutton.com";
String baseUrl = "https://api.usebutton.com";

private static ButtonApi buttonApi;

Expand Down Expand Up @@ -96,7 +96,7 @@ public PostInstallLink getPendingLink(String applicationId, String ifa,
requestBody.put("signals", new JSONObject(signalsMap));

// setup url connection
final URL url = new URL(getBaseUrl(applicationId) + "/v1/web/deferred-deeplink");
final URL url = new URL(baseUrl + "/v1/web/deferred-deeplink");
urlConnection = (HttpURLConnection) url.openConnection();
initializeUrlConnection(urlConnection);

Expand Down Expand Up @@ -193,7 +193,7 @@ public Void postActivity(String applicationId, String sourceToken, String timest
requestBody.put("source", "merchant-library");

// setup url connection
final URL url = new URL(getBaseUrl(applicationId) + "/v1/activity/order");
final URL url = new URL(baseUrl + "/v1/activity/order");
urlConnection = (HttpURLConnection) url.openConnection();
initializeUrlConnection(urlConnection);

Expand Down Expand Up @@ -251,10 +251,6 @@ public Void postActivity(String applicationId, String sourceToken, String timest
return null;
}

String getBaseUrl(String applicationId) {
return String.format(baseUrl, applicationId);
}

private String getUserAgent() {
return userAgent;
}
Expand Down
Expand Up @@ -30,7 +30,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.util.Log;

import com.usebutton.merchant.exception.ApplicationIdNotFoundException;

Expand All @@ -42,9 +41,8 @@
* The methods in the ButtonInternalImpl class should never be public because it will only be used
* by {@link ButtonMerchant}.
*/
final class ButtonInternalImpl implements ButtonInternal {

private static final String TAG = ButtonInternal.class.getSimpleName();
final class ButtonInternalImpl implements ButtonInternal {

/**
* A list of {@link ButtonMerchant.AttributionTokenListener}. All listeners will be notified of
Expand All @@ -68,15 +66,6 @@ final class ButtonInternalImpl implements ButtonInternal {
}

public void configure(ButtonRepository buttonRepository, String applicationId) {
final boolean isApplicationIdValid = ButtonUtil.isApplicationIdValid(applicationId);
if (!isApplicationIdValid) {
final String errorMessage = String.format(
"Button App ID '%s' is not valid. You can find your App ID in the dashboard by"
+ " logging in at https://app.usebutton.com/", applicationId);
Log.e(TAG, errorMessage);
return;
}

buttonRepository.setApplicationId(applicationId);
}

Expand Down

This file was deleted.

Expand Up @@ -40,7 +40,6 @@

import java.util.Collections;

import static com.usebutton.merchant.TestHelper.APPLICATION_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

Expand Down Expand Up @@ -82,7 +81,7 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
});

PostInstallLink postInstallLink =
buttonApi.getPendingLink(APPLICATION_ID, "valid_ifa",
buttonApi.getPendingLink("valid_application_id", "valid_ifa",
true, Collections.<String, String>emptyMap());

assertNotNull(postInstallLink);
Expand All @@ -99,7 +98,7 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
public void getPendingLink_validateRequest() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200).setBody("{}"));

buttonApi.getPendingLink(APPLICATION_ID, "valid_ifa",
buttonApi.getPendingLink("valid_application_id", "valid_ifa",
true, Collections.singletonMap("key", "value"));

RecordedRequest recordedRequest = server.takeRequest();
Expand All @@ -117,7 +116,7 @@ public void getPendingLink_validateRequest() throws Exception {
assertEquals("application/json", headers.get("Content-Type"));

// request body
assertEquals(APPLICATION_ID, bodyJson.getString("application_id"));
assertEquals("valid_application_id", bodyJson.getString("application_id"));
assertEquals("valid_ifa", bodyJson.getString("ifa"));
assertEquals(true, bodyJson.getBoolean("ifa_limited"));
assertEquals("value", signalsJson.getString("key"));
Expand All @@ -133,7 +132,7 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
}
});

buttonApi.getPendingLink(APPLICATION_ID, "valid_ifa", true,
buttonApi.getPendingLink("valid_application_id", "valid_ifa", true,
Collections.<String, String>emptyMap());
}

Expand All @@ -152,15 +151,15 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
}
});

buttonApi.getPendingLink(APPLICATION_ID, "valid_ifa", true,
buttonApi.getPendingLink("valid_application_id", "valid_ifa", true,
Collections.<String, String>emptyMap());
}

@Test(expected = ButtonNetworkException.class)
public void getPendingLink_invalidUrl_catchException() throws Exception {
buttonApi.baseUrl = "invalid_url";

buttonApi.getPendingLink(APPLICATION_ID, "valid_ifa", true,
buttonApi.getPendingLink("valid_application_id", "valid_ifa", true,
Collections.<String, String>emptyMap());
}

Expand All @@ -175,7 +174,7 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
});

Order order = new Order.Builder("123").setCurrencyCode("AUG").build();
buttonApi.postActivity(APPLICATION_ID, "valid_aid", "valid_ts", order);
buttonApi.postActivity("valid_application_id", "valid_aid", "valid_ts", order);
}

@Test(expected = ButtonNetworkException.class)
Expand All @@ -195,15 +194,15 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
});

Order order = new Order.Builder("123").setCurrencyCode("AUG").build();
buttonApi.postActivity(APPLICATION_ID, "valid_aid", "valid_ts", order);
buttonApi.postActivity("valid_application_id", "valid_aid", "valid_ts", order);
}

@Test(expected = ButtonNetworkException.class)
public void postUserActivity_invalidUrl_catchException() throws Exception {
buttonApi.baseUrl = "invalid_url";

Order order = new Order.Builder("123").setCurrencyCode("AUG").build();
buttonApi.postActivity(APPLICATION_ID, "valid_aid", "valid_ts", order);
buttonApi.postActivity("valid_application_id", "valid_aid", "valid_ts", order);
}

@Test
Expand All @@ -212,7 +211,7 @@ public void postUserActivity_validateRequest() throws Exception {
.setBody("{\"meta\":{\"status\":\"ok\"}}\n"));

Order order = new Order.Builder("123").setAmount(999).setCurrencyCode("AUG").build();
buttonApi.postActivity(APPLICATION_ID, "valid_aid", "valid_ts", order);
buttonApi.postActivity("valid_application_id", "valid_aid", "valid_ts", order);

RecordedRequest recordedRequest = server.takeRequest();
Headers headers = recordedRequest.getHeaders();
Expand All @@ -227,7 +226,7 @@ public void postUserActivity_validateRequest() throws Exception {
assertEquals("application/json", headers.get("Content-Type"));

// request body
assertEquals(APPLICATION_ID, requestBodyJson.getString("app_id"));
assertEquals("valid_application_id", requestBodyJson.getString("app_id"));
assertEquals("valid_ts", requestBodyJson.getString("user_local_time"));
assertEquals("valid_aid", requestBodyJson.getString("btn_ref"));
assertEquals("123", requestBodyJson.getString("order_id"));
Expand All @@ -252,17 +251,6 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio
});

Order order = new Order.Builder("123").setCurrencyCode("AUG").build();
buttonApi.postActivity(APPLICATION_ID, "valid_aid", "valid_ts", order);
}

@Test()
public void getBaseUrl_validateApplicationIdInUrl() {
// Reinitialize the buttonApi variable to reset the baseUrl back to the original.
buttonApi = new ButtonApiImpl(userAgent);

final String expectedUrl = "https://" + APPLICATION_ID + ".mobileapi.usebutton.com";
final String actualUrl = buttonApi.getBaseUrl(APPLICATION_ID);

assertEquals(expectedUrl, actualUrl);
buttonApi.postActivity("valid_application_id", "valid_aid", "valid_ts", order);
}
}
Expand Up @@ -40,7 +40,6 @@

import java.util.concurrent.Executor;

import static com.usebutton.merchant.TestHelper.APPLICATION_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -70,25 +69,17 @@ public void setUp() {
public void configure_saveApplicationIdInMemory() {
ButtonRepository buttonRepository = mock(ButtonRepository.class);

buttonInternal.configure(buttonRepository, APPLICATION_ID);
verify(buttonRepository).setApplicationId(APPLICATION_ID);
}

@Test
public void configure_shouldNotSaveApplicationIdInMemory_InvalidAppId() {
ButtonRepository buttonRepository = mock(ButtonRepository.class);

buttonInternal.configure(buttonRepository, "invalid_application_id");
verify(buttonRepository, never()).setApplicationId(APPLICATION_ID);
buttonInternal.configure(buttonRepository, "valid_application_id");
verify(buttonRepository).setApplicationId("valid_application_id");
}

@Test
public void getApplicationId_retrieveFromRepository() {
ButtonRepository buttonRepository = mock(ButtonRepository.class);
when(buttonRepository.getApplicationId()).thenReturn(APPLICATION_ID);
when(buttonRepository.getApplicationId()).thenReturn("valid_application_id");

String applicationId = buttonInternal.getApplicationId(buttonRepository);
assertEquals(APPLICATION_ID, applicationId);
assertEquals("valid_application_id", applicationId);
}

@Test
Expand Down Expand Up @@ -292,7 +283,7 @@ public void handlePostInstallIntent_returnValidPostInstallLink_setSourceToken()
PostInstallIntentListener postInstallIntentListener = mock(PostInstallIntentListener.class);
DeviceManager deviceManager = mock(DeviceManager.class);

when(buttonRepository.getApplicationId()).thenReturn(APPLICATION_ID);
when(buttonRepository.getApplicationId()).thenReturn("valid_application_id");

buttonInternal.handlePostInstallIntent(buttonRepository, postInstallIntentListener,
"com.usebutton.merchant",
Expand Down Expand Up @@ -321,7 +312,7 @@ public void handlePostInstallIntent_returnInvalidPostInstallLink_doNotSetSourceT
PostInstallIntentListener postInstallIntentListener = mock(PostInstallIntentListener.class);
DeviceManager deviceManager = mock(DeviceManager.class);

when(buttonRepository.getApplicationId()).thenReturn(APPLICATION_ID);
when(buttonRepository.getApplicationId()).thenReturn("valid_application_id");

buttonInternal.handlePostInstallIntent(buttonRepository, postInstallIntentListener,
"com.usebutton.merchant",
Expand Down Expand Up @@ -366,7 +357,7 @@ public void handlePostInstallIntent_throwButtonNetworkException() {
PostInstallIntentListener postInstallIntentListener = mock(PostInstallIntentListener.class);
DeviceManager deviceManager = mock(DeviceManager.class);

when(buttonRepository.getApplicationId()).thenReturn(APPLICATION_ID);
when(buttonRepository.getApplicationId()).thenReturn("valid_application_id");

buttonInternal.handlePostInstallIntent(buttonRepository, postInstallIntentListener,
"com.usebutton.merchant",
Expand All @@ -389,7 +380,7 @@ public void handlePostInstallIntent_newInstallationAndDidNotCheckDeferredDeepLin
PostInstallIntentListener postInstallIntentListener = mock(PostInstallIntentListener.class);
DeviceManager deviceManager = mock(DeviceManager.class);

when(buttonRepository.getApplicationId()).thenReturn(APPLICATION_ID);
when(buttonRepository.getApplicationId()).thenReturn("valid_application_id");
when(deviceManager.isOldInstallation()).thenReturn(false);
when(buttonRepository.checkedDeferredDeepLink()).thenReturn(false);

Expand All @@ -407,7 +398,7 @@ public void handlePostInstallIntent_oldInstallation_doNotUpdateCheckDeferredDeep
PostInstallIntentListener postInstallIntentListener = mock(PostInstallIntentListener.class);
DeviceManager deviceManager = mock(DeviceManager.class);

when(buttonRepository.getApplicationId()).thenReturn(APPLICATION_ID);
when(buttonRepository.getApplicationId()).thenReturn("valid_application_id");
when(deviceManager.isOldInstallation()).thenReturn(true);
when(buttonRepository.checkedDeferredDeepLink()).thenReturn(false);

Expand All @@ -425,7 +416,7 @@ public void handlePostInstallIntent_checkedDeferredDeepLink_doNotUpdateCheckDefe
PostInstallIntentListener postInstallIntentListener = mock(PostInstallIntentListener.class);
DeviceManager deviceManager = mock(DeviceManager.class);

when(buttonRepository.getApplicationId()).thenReturn(APPLICATION_ID);
when(buttonRepository.getApplicationId()).thenReturn("valid_application_id");
when(deviceManager.isOldInstallation()).thenReturn(false);
when(buttonRepository.checkedDeferredDeepLink()).thenReturn(true);

Expand Down

This file was deleted.

0 comments on commit 76add97

Please sign in to comment.