Skip to content

Commit

Permalink
(For David) $app and $browsers to more events (#32)
Browse files Browse the repository at this point in the history
* $app and $browsers to more events

* Undo all app and browser repetitive tests. Just tests on BaseAppBrowserFieldSet

* subclass test

* proper build.gradle

* fix one nit

* missing a few subclasses

* update change log

* Minor version bump instead of patch version bump
  • Loading branch information
hd authored Oct 22, 2018
1 parent 1a8da1c commit 8aa50ab
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 59 deletions.
4 changes: 4 additions & 0 deletions CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.4.0 (2018-10-22)
=================
- Add support for `$app` and `$browser` to the following events: `AddItemToCart`, `AddPromotion`, `CreateAccount`, `CreateContent`, `CreateOrder`, `CustomEvent`, `RemoveItemFromCart`, `Transaction`, `UpdateAccount`, and `UpdateContent`

2.3.0 (2018-08-08)
=================

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'org.skyscreamer', name: 'jsonassert', version: '1.3.0'
testCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.4.2'
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.okhttp3:okhttp:3.4.2'
compile 'com.squareup.okio:okio:1.9.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class AddItemToCartFieldSet extends EventsApiRequestFieldSet<AddItemToCartFieldSet> {
public class AddItemToCartFieldSet extends BaseAppBrowserFieldSet<AddItemToCartFieldSet> {
public static AddItemToCartFieldSet fromJson(String json) {
return gson.fromJson(json, AddItemToCartFieldSet.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.List;

public class AddPromotionFieldSet extends EventsApiRequestFieldSet<AddPromotionFieldSet> {
public class AddPromotionFieldSet extends BaseAppBrowserFieldSet<AddPromotionFieldSet> {
public static AddPromotionFieldSet fromJson(String json) {
return gson.fromJson(json, AddPromotionFieldSet.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

public abstract class BaseAccountFieldSet<T extends BaseAccountFieldSet<T>>
extends EventsApiRequestFieldSet<T> {
extends BaseAppBrowserFieldSet<T> {
@Expose @SerializedName("$user_email") private String userEmail;
@Expose @SerializedName("$name") private String name;
@Expose @SerializedName("$phone") private String phone;
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/siftscience/model/BaseAppBrowserFieldSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.siftscience.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public abstract class BaseAppBrowserFieldSet<T extends BaseAppBrowserFieldSet<T>>
extends EventsApiRequestFieldSet<T> {
@Expose @SerializedName("$app") private App app;
@Expose @SerializedName("$browser") private Browser browser;

public App getApp() {
return app;
}

public T setApp(App app) {
this.app = app;
return (T) this;
}

public Browser getBrowser() {
return browser;
}

public T setBrowser(Browser browser) {
this.browser = browser;
return (T) this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

public abstract class BaseContentFieldSet<T extends BaseContentFieldSet<T>>
extends EventsApiRequestFieldSet<T> {
extends BaseAppBrowserFieldSet<T> {
@Expose @SerializedName("$content_id") private String contentId;
@Expose @SerializedName("$status") private String status;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/siftscience/model/BaseOrderFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.List;

public abstract class BaseOrderFieldSet<T extends BaseOrderFieldSet<T>>
extends EventsApiRequestFieldSet<T> {
extends BaseAppBrowserFieldSet<T> {
@Expose @SerializedName("$order_id") private String orderId;
@Expose @SerializedName("$user_email") private String userEmail;
@Expose @SerializedName("$amount") private Long amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class CustomEventFieldSet extends EventsApiRequestFieldSet<CustomEventFieldSet> {
public class CustomEventFieldSet extends BaseAppBrowserFieldSet<CustomEventFieldSet> {
public static CustomEventFieldSet fromJson(String json) {
return gson.fromJson(json, CustomEventFieldSet.class);
}
Expand Down
22 changes: 1 addition & 21 deletions src/main/java/com/siftscience/model/LoginFieldSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class LoginFieldSet extends EventsApiRequestFieldSet<LoginFieldSet> {
public class LoginFieldSet extends BaseAppBrowserFieldSet<LoginFieldSet> {
public static LoginFieldSet fromJson(String json) {
return gson.fromJson(json, LoginFieldSet.class);
}

@Expose @SerializedName("$login_status") private String loginStatus;
@Expose @SerializedName("$browser") private Browser browser;
@Expose @SerializedName("$app") private App app;

@Override
public String getEventType() {
Expand All @@ -25,22 +23,4 @@ public LoginFieldSet setLoginStatus(String loginStatus) {
this.loginStatus = loginStatus;
return this;
}

public Browser getBrowser() {
return browser;
}

public LoginFieldSet setBrowser(Browser browser) {
this.browser = browser;
return this;
}

public App getApp() {
return app;
}

public LoginFieldSet setApp(App app) {
this.app = app;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class RemoveItemFromCartFieldSet
extends EventsApiRequestFieldSet<RemoveItemFromCartFieldSet> {
public class RemoveItemFromCartFieldSet extends BaseAppBrowserFieldSet<RemoveItemFromCartFieldSet> {
public static RemoveItemFromCartFieldSet fromJson(String json) {
return gson.fromJson(json, RemoveItemFromCartFieldSet.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class TransactionFieldSet extends EventsApiRequestFieldSet<TransactionFieldSet> {
public class TransactionFieldSet extends BaseAppBrowserFieldSet<TransactionFieldSet> {
@Expose @SerializedName("$amount") private Long amount;
@Expose @SerializedName("$currency_code") private String currencyCode;
@Expose @SerializedName("$user_email") private String userEmail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,41 @@

import static java.net.HttpURLConnection.HTTP_OK;

public class AddItemToCardEventTest {
public class AddItemToCartEventTest {

@Test
public void testAddItemToCart() throws Exception {
String expectedRequestBody = "{\n" +
" \"$type\" : \"$add_item_to_cart\",\n" +
" \"$api_key\" : \"your_api_key_here\",\n" +
" \"$user_id\" : \"billy_jones_301\",\n" +
"\n" +
" \"$session_id\" : \"gigtleqddo84l8cm15qe4il\",\n" +
" \"$item\" : {\n" +
" \"$item_id\" : \"B004834GQO\",\n" +
" \"$product_title\" : \"The Slanket Blanket-Texas Tea\",\n" +
" \"$price\" : 39990000,\n" +
" \"$upc\" : \"67862114510011\",\n" +
" \"$sku\" : \"004834GQ\",\n" +
" \"$brand\" : \"Slanket\",\n" +
" \"$manufacturer\" : \"Slanket\",\n" +
" \"$category\" : \"Blankets & Throws\",\n" +
" \"$tags\" : [\"Awesome\", \"Wintertime specials\"],\n" +
" \"$color\" : \"Texas Tea\",\n" +
" \"$quantity\" : 2\n" +
" }\n" +
"}";
" \"$type\" : \"$add_item_to_cart\",\n" +
" \"$api_key\" : \"your_api_key_here\",\n" +
" \"$user_id\" : \"billy_jones_301\",\n" +
"\n" +
" \"$session_id\" : \"gigtleqddo84l8cm15qe4il\",\n" +
" \"$item\" : {\n" +
" \"$item_id\" : \"B004834GQO\",\n" +
" \"$product_title\" : \"The Slanket Blanket-Texas Tea\",\n" +
" \"$price\" : 39990000,\n" +
" \"$upc\" : \"67862114510011\",\n" +
" \"$sku\" : \"004834GQ\",\n" +
" \"$brand\" : \"Slanket\",\n" +
" \"$manufacturer\" : \"Slanket\",\n" +
" \"$category\" : \"Blankets & Throws\",\n" +
" \"$tags\" : [\"Awesome\", \"Wintertime specials\"],\n" +
" \"$color\" : \"Texas Tea\",\n" +
" \"$quantity\" : 2\n" +
" }\n" +
"}";

// Start a new mock server and enqueue a mock response.
MockWebServer server = new MockWebServer();
MockResponse response = new MockResponse();
response.setResponseCode(HTTP_OK);
response.setBody("{\n" +
" \"status\" : 0,\n" +
" \"error_message\" : \"OK\",\n" +
" \"time\" : 1327604222,\n" +
" \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" +
"}");
" \"status\" : 0,\n" +
" \"error_message\" : \"OK\",\n" +
" \"time\" : 1327604222,\n" +
" \"request\" : \"" + TestUtils.unescapeJson(expectedRequestBody) + "\"\n" +
"}");
server.enqueue(response);
server.start();
HttpUrl baseUrl = server.url("");
Expand All @@ -55,9 +56,9 @@ public void testAddItemToCart() throws Exception {

// Build and execute the request against the mock server.
SiftRequest request = client.buildRequest(new AddItemToCartFieldSet()
.setUserId("billy_jones_301")
.setSessionId("gigtleqddo84l8cm15qe4il")
.setItem(TestUtils.sampleItem2()));
.setUserId("billy_jones_301")
.setSessionId("gigtleqddo84l8cm15qe4il")
.setItem(TestUtils.sampleItem2()));

SiftResponse siftResponse = request.send();

Expand All @@ -71,7 +72,7 @@ public void testAddItemToCart() throws Exception {
Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
Assert.assertEquals(0, (int) siftResponse.getBody().getStatus());
JSONAssert.assertEquals(response.getBody().readUtf8(),
siftResponse.getBody().toJson(), true);
siftResponse.getBody().toJson(), true);

server.shutdown();
}
Expand Down
Loading

0 comments on commit 8aa50ab

Please sign in to comment.