Skip to content

Commit

Permalink
Merge ef938a0 into b0ac0fd
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon6193 committed May 22, 2019
2 parents b0ac0fd + ef938a0 commit 9bbc7a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 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 @@ -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(TestHelper.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(TestHelper.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(TestHelper.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(TestHelper.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(TestHelper.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(TestHelper.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(TestHelper.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(TestHelper.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(TestHelper.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(TestHelper.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(TestHelper.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(TestHelper.APPLICATION_ID, "valid_aid", "valid_ts", order);
}
}

0 comments on commit 9bbc7a9

Please sign in to comment.