From 6b9b1fdf44cf4da343318582d96eac478fedf7f3 Mon Sep 17 00:00:00 2001 From: cgee1 Date: Thu, 14 May 2020 09:33:14 -0700 Subject: [PATCH 1/5] Update functions to match ios sdk --- .../java/io/constructor/core/ConstructorIo.kt | 12 +++---- .../java/io/constructor/data/DataManager.kt | 12 +++---- .../constructor/data/remote/ConstructorApi.kt | 7 ++-- .../core/ConstructorIoTrackingTest.kt | 36 +++++++++---------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/library/src/main/java/io/constructor/core/ConstructorIo.kt b/library/src/main/java/io/constructor/core/ConstructorIo.kt index 8b57aec4..e2ae5ec7 100755 --- a/library/src/main/java/io/constructor/core/ConstructorIo.kt +++ b/library/src/main/java/io/constructor/core/ConstructorIo.kt @@ -129,7 +129,7 @@ object ConstructorIo { /** * Tracks autocomplete select events */ - fun trackAutocompleteSelect(searchTerm: String, originalQuery: String, sectionName: String, group: Group? = null): Completable { + fun trackAutocompleteSelect(searchTerm: String, originalQuery: String, sectionName: String, group: Group? = null, resultID: String? = null): Completable { preferenceHelper.getSessionId(sessionIncrementHandler) val encodedParams: ArrayList> = arrayListOf() group?.groupId?.let { encodedParams.add(Constants.QueryConstants.GROUP_ID.urlEncode() to it) } @@ -138,7 +138,7 @@ object ConstructorIo { Constants.QueryConstants.AUTOCOMPLETE_SECTION to sectionName, Constants.QueryConstants.ORIGINAL_QUERY to originalQuery, Constants.QueryConstants.EVENT to Constants.QueryValues.EVENT_CLICK - ), encodedParams.toTypedArray()).subscribeOn(Schedulers.io()) + ), encodedParams.toTypedArray(), resultID).subscribeOn(Schedulers.io()) if (this.broadcast) { completable.subscribeOn(Schedulers.io()).subscribe { @@ -184,12 +184,12 @@ object ConstructorIo { /** * Tracks search result click events */ - fun trackSearchResultClick(itemName: String, customerId: String, searchTerm: String = Constants.QueryConstants.TERM_UNKNOWN, sectionName: String? = null): Completable { + fun trackSearchResultClick(itemName: String, customerId: String, searchTerm: String = Constants.QueryConstants.TERM_UNKNOWN, sectionName: String? = null, resultID: String? = null): Completable { preferenceHelper.getSessionId(sessionIncrementHandler) val sName = sectionName ?: preferenceHelper.defaultItemSection return dataManager.trackSearchResultClick(itemName, customerId, searchTerm, arrayOf( Constants.QueryConstants.AUTOCOMPLETE_SECTION to sName - )) + ), resultID) } @@ -207,12 +207,12 @@ object ConstructorIo { /** * Tracks purchase events */ - fun trackPurchase(clientIds: Array, revenue: Double?, sectionName: String? = null): Completable { + fun trackPurchase(orderID: String, clientIds: Array, revenue: Double?, sectionName: String? = null): Completable { preferenceHelper.getSessionId(sessionIncrementHandler) val sectionNameParam = sectionName ?: preferenceHelper.defaultItemSection val revenueString = revenue?.let { "%.2f".format(revenue) } val params = mutableListOf(Constants.QueryConstants.AUTOCOMPLETE_SECTION to sectionNameParam) - return dataManager.trackPurchase(clientIds.toList(), revenueString, params.toTypedArray()) + return dataManager.trackPurchase(orderID, clientIds.toList(), revenueString, params.toTypedArray()) } } \ No newline at end of file diff --git a/library/src/main/java/io/constructor/data/DataManager.kt b/library/src/main/java/io/constructor/data/DataManager.kt index 6fe02d6a..021f8516 100755 --- a/library/src/main/java/io/constructor/data/DataManager.kt +++ b/library/src/main/java/io/constructor/data/DataManager.kt @@ -53,8 +53,8 @@ constructor(private val constructorApi: ConstructorApi, private val moshi: Moshi }.toObservable() } - fun trackAutocompleteSelect(term: String, params: Array> = arrayOf(), encodedParams: Array> = arrayOf()): Completable { - return constructorApi.trackAutocompleteSelect(term, params.toMap(), encodedParams.toMap()) + fun trackAutocompleteSelect(term: String, params: Array> = arrayOf(), encodedParams: Array> = arrayOf(), resultID: String? = null): Completable { + return constructorApi.trackAutocompleteSelect(term, params.toMap(), encodedParams.toMap(), resultID) } fun trackSearchSubmit(term: String, params: Array> = arrayOf(), encodedParams: Array> = arrayOf()): Completable { @@ -69,8 +69,8 @@ constructor(private val constructorApi: ConstructorApi, private val moshi: Moshi return constructorApi.trackConversion(term, itemName, customerId, revenue, params.toMap()) } - fun trackSearchResultClick(itemName: String, customerId: String, term: String, params: Array> = arrayOf()): Completable { - return constructorApi.trackSearchResultClick(term, itemName, customerId, params.toMap()) + fun trackSearchResultClick(itemName: String, customerId: String, term: String, params: Array> = arrayOf(), resultID: String? = null): Completable { + return constructorApi.trackSearchResultClick(term, itemName, customerId, params.toMap(), resultID) } fun trackSearchResultsLoaded(term: String, resultCount: Int, params: Array>): Completable { @@ -81,8 +81,8 @@ constructor(private val constructorApi: ConstructorApi, private val moshi: Moshi return constructorApi.trackInputFocus(term, params.toMap()) } - fun trackPurchase(customerIds: List, revenue: String? = null, params: Array>): Completable { - return constructorApi.trackPurchase(customerIds, revenue, params.toMap()) + fun trackPurchase(orderID: String, customerIds: List, revenue: String? = null, params: Array>): Completable { + return constructorApi.trackPurchase(orderID, customerIds, revenue, params.toMap()) } } \ No newline at end of file diff --git a/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt b/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt index de40e272..f16fbd97 100755 --- a/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt +++ b/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt @@ -14,7 +14,7 @@ interface ConstructorApi { fun getAutocompleteResults(@Path("value") value: String, @QueryMap data: Map): Single> @GET(ApiPaths.URL_AUTOCOMPLETE_SELECT_EVENT) - fun trackAutocompleteSelect(@Path("term") term: String, @QueryMap data: Map, @QueryMap(encoded = true) encodedData: Map): Completable + fun trackAutocompleteSelect(@Path("term") term: String, @QueryMap data: Map, @QueryMap(encoded = true) encodedData: Map, @Query("result_id") resultID: String?): Completable @GET(ApiPaths.URL_SEARCH_SUBMIT_EVENT) fun trackSearchSubmit(@Path("term") term: String, @QueryMap data: Map, @QueryMap(encoded = true) encodedData: Map): Completable @@ -26,7 +26,7 @@ interface ConstructorApi { fun trackConversion(@Path("term") term: String, @Query("name") itemName: String, @Query("customer_id") customerId: String, @Query("revenue") revenue: String?, @QueryMap params: Map): Completable @GET(ApiPaths.URL_SEARCH_RESULT_CLICK_EVENT) - fun trackSearchResultClick(@Path("term") term: String, @Query("name") itemName: String, @Query("customer_id") customerId: String, @QueryMap params: Map): Completable + fun trackSearchResultClick(@Path("term") term: String, @Query("name") itemName: String, @Query("customer_id") customerId: String, @QueryMap params: Map, @Query("result_id") resultID: String?): Completable @GET(ApiPaths.URL_BEHAVIOR) fun trackSearchResultsLoaded(@Query("term") term: String, @Query("num_results") resultCount: Int, @QueryMap params: Map): Completable @@ -35,7 +35,8 @@ interface ConstructorApi { fun trackInputFocus(@Query("term") term: String?, @QueryMap params: Map): Completable @GET(ApiPaths.URL_PURCHASE) - fun trackPurchase(@Query(Constants.QueryConstants.CUSTOMER_ID) customerIds: List, + fun trackPurchase(@Query("order_id") orderID: String, + @Query(Constants.QueryConstants.CUSTOMER_ID) customerIds: List, @Query("revenue") revenue: String?, @QueryMap params: Map): Completable diff --git a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt index d318d70e..d5e09dee 100755 --- a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt +++ b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt @@ -52,10 +52,10 @@ class ConstructorIoTest { fun trackAutocompleteSelect() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions").test() + val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions", null, "2347874").test() observer.assertComplete() val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" + val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" assert(request.path.startsWith(path)) } @@ -63,10 +63,10 @@ class ConstructorIoTest { fun trackAutocompleteSelectWithServerError() { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions").test() + val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions", null, "2347874").test() observer.assertError { true } val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" + val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" assert(request.path.startsWith(path)) } @@ -75,10 +75,10 @@ class ConstructorIoTest { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockResponse.throttleBody(0, 5, TimeUnit.SECONDS) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions").test() + val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions", null, "2347874").test() observer.assertError(SocketTimeoutException::class.java) val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" + val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" assert(request.path.startsWith(path)) } @@ -188,10 +188,10 @@ class ConstructorIoTest { fun trackSearchResultClick() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic").test() + val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic", null, "2347874").test() observer.assertComplete() val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -199,10 +199,10 @@ class ConstructorIoTest { fun trackSearchResultClick500() { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic").test() + val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic", null, "2347874").test() observer.assertError { true } val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -211,10 +211,10 @@ class ConstructorIoTest { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockResponse.throttleBody(0, 5, TimeUnit.SECONDS) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic").test() + val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic", null, "2347874").test() observer.assertError(SocketTimeoutException::class.java) val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -290,10 +290,10 @@ class ConstructorIoTest { fun trackPurchase() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products").test() + val observer = ConstructorIo.trackPurchase("1312343", arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products").test() observer.assertComplete() val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?order_id=1312343&customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -301,10 +301,10 @@ class ConstructorIoTest { fun trackPurchase500() { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products").test() + val observer = ConstructorIo.trackPurchase("1312343", arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products").test() observer.assertError { true } val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?order_id=1312343&customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -313,10 +313,10 @@ class ConstructorIoTest { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockResponse.throttleBody(0, 5, TimeUnit.SECONDS) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products").test() + val observer = ConstructorIo.trackPurchase("1312343", arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products").test() observer.assertError(SocketTimeoutException::class.java) val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?order_id=1312343&customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } } \ No newline at end of file From f7a47ac2a2e692082584576894f707b8ab144c0a Mon Sep 17 00:00:00 2001 From: cgee1 Date: Thu, 14 May 2020 11:06:09 -0700 Subject: [PATCH 2/5] Change orderID parameter placement to match ios sdk --- .../main/java/io/constructor/core/ConstructorIo.kt | 4 ++-- .../src/main/java/io/constructor/data/DataManager.kt | 4 ++-- .../io/constructor/data/remote/ConstructorApi.kt | 6 +++--- .../io/constructor/core/ConstructorIoTrackingTest.kt | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/library/src/main/java/io/constructor/core/ConstructorIo.kt b/library/src/main/java/io/constructor/core/ConstructorIo.kt index e2ae5ec7..f203966c 100755 --- a/library/src/main/java/io/constructor/core/ConstructorIo.kt +++ b/library/src/main/java/io/constructor/core/ConstructorIo.kt @@ -207,12 +207,12 @@ object ConstructorIo { /** * Tracks purchase events */ - fun trackPurchase(orderID: String, clientIds: Array, revenue: Double?, sectionName: String? = null): Completable { + fun trackPurchase(clientIds: Array, revenue: Double?, sectionName: String? = null, orderID: String): Completable { preferenceHelper.getSessionId(sessionIncrementHandler) val sectionNameParam = sectionName ?: preferenceHelper.defaultItemSection val revenueString = revenue?.let { "%.2f".format(revenue) } val params = mutableListOf(Constants.QueryConstants.AUTOCOMPLETE_SECTION to sectionNameParam) - return dataManager.trackPurchase(orderID, clientIds.toList(), revenueString, params.toTypedArray()) + return dataManager.trackPurchase(clientIds.toList(), revenueString, params.toTypedArray(), orderID) } } \ No newline at end of file diff --git a/library/src/main/java/io/constructor/data/DataManager.kt b/library/src/main/java/io/constructor/data/DataManager.kt index 021f8516..6d165ed2 100755 --- a/library/src/main/java/io/constructor/data/DataManager.kt +++ b/library/src/main/java/io/constructor/data/DataManager.kt @@ -81,8 +81,8 @@ constructor(private val constructorApi: ConstructorApi, private val moshi: Moshi return constructorApi.trackInputFocus(term, params.toMap()) } - fun trackPurchase(orderID: String, customerIds: List, revenue: String? = null, params: Array>): Completable { - return constructorApi.trackPurchase(orderID, customerIds, revenue, params.toMap()) + fun trackPurchase(customerIds: List, revenue: String? = null, params: Array>, orderID: String): Completable { + return constructorApi.trackPurchase(customerIds, revenue, params.toMap(), orderID) } } \ No newline at end of file diff --git a/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt b/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt index f16fbd97..6b6d1ee6 100755 --- a/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt +++ b/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt @@ -35,10 +35,10 @@ interface ConstructorApi { fun trackInputFocus(@Query("term") term: String?, @QueryMap params: Map): Completable @GET(ApiPaths.URL_PURCHASE) - fun trackPurchase(@Query("order_id") orderID: String, - @Query(Constants.QueryConstants.CUSTOMER_ID) customerIds: List, + fun trackPurchase(@Query(Constants.QueryConstants.CUSTOMER_ID) customerIds: List, @Query("revenue") revenue: String?, - @QueryMap params: Map): Completable + @QueryMap params: Map, + @Query("order_id") orderID: String): Completable @GET fun getSearchResults(@Url searchUrl: String): Single> diff --git a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt index d5e09dee..f69175cd 100755 --- a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt +++ b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt @@ -290,10 +290,10 @@ class ConstructorIoTest { fun trackPurchase() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase("1312343", arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products", "1312343").test() observer.assertComplete() val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?order_id=1312343&customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&order_id=1312343&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -301,10 +301,10 @@ class ConstructorIoTest { fun trackPurchase500() { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase("1312343", arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products", "1312343").test() observer.assertError { true } val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?order_id=1312343&customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&order_id=1312343&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -313,10 +313,10 @@ class ConstructorIoTest { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockResponse.throttleBody(0, 5, TimeUnit.SECONDS) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase("1312343", arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products", "1312343").test() observer.assertError(SocketTimeoutException::class.java) val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?order_id=1312343&customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&order_id=1312343&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } } \ No newline at end of file From ea928b8673fefc0cc1b6d381cafda1daf1d27c2b Mon Sep 17 00:00:00 2001 From: cgee1 Date: Tue, 19 May 2020 07:57:44 -0700 Subject: [PATCH 3/5] Add optional params to encodedParams --- .../java/io/constructor/core/Constants.kt | 1 + .../java/io/constructor/core/ConstructorIo.kt | 11 +-- .../java/io/constructor/data/DataManager.kt | 12 ++-- .../constructor/data/remote/ConstructorApi.kt | 8 +-- .../core/ConstructorIoTrackingTest.kt | 71 ++++++++++++++----- 5 files changed, 71 insertions(+), 32 deletions(-) diff --git a/library/src/main/java/io/constructor/core/Constants.kt b/library/src/main/java/io/constructor/core/Constants.kt index bf1aafbd..0b7ccc5b 100755 --- a/library/src/main/java/io/constructor/core/Constants.kt +++ b/library/src/main/java/io/constructor/core/Constants.kt @@ -31,6 +31,7 @@ class Constants { const val PER_PAGE = "num_results_per_page" const val FILTER_GROUP_ID = "filters[group_id]" const val FILTER_FACET = "filters[%s]" + const val RESULT_ID = "result_id" } object QueryValues { diff --git a/library/src/main/java/io/constructor/core/ConstructorIo.kt b/library/src/main/java/io/constructor/core/ConstructorIo.kt index f203966c..6ddaeeb5 100755 --- a/library/src/main/java/io/constructor/core/ConstructorIo.kt +++ b/library/src/main/java/io/constructor/core/ConstructorIo.kt @@ -134,11 +134,12 @@ object ConstructorIo { val encodedParams: ArrayList> = arrayListOf() group?.groupId?.let { encodedParams.add(Constants.QueryConstants.GROUP_ID.urlEncode() to it) } group?.displayName?.let { encodedParams.add(Constants.QueryConstants.GROUP_DISPLAY_NAME.urlEncode() to it.urlEncode()) } + resultID?.let { encodedParams.add(Constants.QueryConstants.RESULT_ID.urlEncode() to it.urlEncode()) } val completable = dataManager.trackAutocompleteSelect(searchTerm, arrayOf( Constants.QueryConstants.AUTOCOMPLETE_SECTION to sectionName, Constants.QueryConstants.ORIGINAL_QUERY to originalQuery, Constants.QueryConstants.EVENT to Constants.QueryValues.EVENT_CLICK - ), encodedParams.toTypedArray(), resultID).subscribeOn(Schedulers.io()) + ), encodedParams.toTypedArray()).subscribeOn(Schedulers.io()) if (this.broadcast) { completable.subscribeOn(Schedulers.io()).subscribe { @@ -186,10 +187,12 @@ object ConstructorIo { */ fun trackSearchResultClick(itemName: String, customerId: String, searchTerm: String = Constants.QueryConstants.TERM_UNKNOWN, sectionName: String? = null, resultID: String? = null): Completable { preferenceHelper.getSessionId(sessionIncrementHandler) + val encodedParams: ArrayList> = arrayListOf() + resultID?.let { encodedParams.add(Constants.QueryConstants.RESULT_ID.urlEncode() to it.urlEncode()) } val sName = sectionName ?: preferenceHelper.defaultItemSection return dataManager.trackSearchResultClick(itemName, customerId, searchTerm, arrayOf( Constants.QueryConstants.AUTOCOMPLETE_SECTION to sName - ), resultID) + ), encodedParams.toTypedArray()) } @@ -207,12 +210,12 @@ object ConstructorIo { /** * Tracks purchase events */ - fun trackPurchase(clientIds: Array, revenue: Double?, sectionName: String? = null, orderID: String): Completable { + fun trackPurchase(clientIds: Array, revenue: Double?, orderID: String, sectionName: String? = null): Completable { preferenceHelper.getSessionId(sessionIncrementHandler) val sectionNameParam = sectionName ?: preferenceHelper.defaultItemSection val revenueString = revenue?.let { "%.2f".format(revenue) } val params = mutableListOf(Constants.QueryConstants.AUTOCOMPLETE_SECTION to sectionNameParam) - return dataManager.trackPurchase(clientIds.toList(), revenueString, params.toTypedArray(), orderID) + return dataManager.trackPurchase(clientIds.toList(), revenueString, orderID, params.toTypedArray()) } } \ No newline at end of file diff --git a/library/src/main/java/io/constructor/data/DataManager.kt b/library/src/main/java/io/constructor/data/DataManager.kt index 6d165ed2..aa1811e7 100755 --- a/library/src/main/java/io/constructor/data/DataManager.kt +++ b/library/src/main/java/io/constructor/data/DataManager.kt @@ -53,8 +53,8 @@ constructor(private val constructorApi: ConstructorApi, private val moshi: Moshi }.toObservable() } - fun trackAutocompleteSelect(term: String, params: Array> = arrayOf(), encodedParams: Array> = arrayOf(), resultID: String? = null): Completable { - return constructorApi.trackAutocompleteSelect(term, params.toMap(), encodedParams.toMap(), resultID) + fun trackAutocompleteSelect(term: String, params: Array> = arrayOf(), encodedParams: Array> = arrayOf()): Completable { + return constructorApi.trackAutocompleteSelect(term, params.toMap(), encodedParams.toMap()) } fun trackSearchSubmit(term: String, params: Array> = arrayOf(), encodedParams: Array> = arrayOf()): Completable { @@ -69,8 +69,8 @@ constructor(private val constructorApi: ConstructorApi, private val moshi: Moshi return constructorApi.trackConversion(term, itemName, customerId, revenue, params.toMap()) } - fun trackSearchResultClick(itemName: String, customerId: String, term: String, params: Array> = arrayOf(), resultID: String? = null): Completable { - return constructorApi.trackSearchResultClick(term, itemName, customerId, params.toMap(), resultID) + fun trackSearchResultClick(itemName: String, customerId: String, term: String, params: Array> = arrayOf(), encodedParams: Array> = arrayOf()): Completable { + return constructorApi.trackSearchResultClick(term, itemName, customerId, params.toMap(), encodedParams.toMap()) } fun trackSearchResultsLoaded(term: String, resultCount: Int, params: Array>): Completable { @@ -81,8 +81,8 @@ constructor(private val constructorApi: ConstructorApi, private val moshi: Moshi return constructorApi.trackInputFocus(term, params.toMap()) } - fun trackPurchase(customerIds: List, revenue: String? = null, params: Array>, orderID: String): Completable { - return constructorApi.trackPurchase(customerIds, revenue, params.toMap(), orderID) + fun trackPurchase(customerIds: List, revenue: String? = null, orderID: String, params: Array>): Completable { + return constructorApi.trackPurchase(customerIds, revenue, orderID, params.toMap()) } } \ No newline at end of file diff --git a/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt b/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt index 6b6d1ee6..8035f2b2 100755 --- a/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt +++ b/library/src/main/java/io/constructor/data/remote/ConstructorApi.kt @@ -14,7 +14,7 @@ interface ConstructorApi { fun getAutocompleteResults(@Path("value") value: String, @QueryMap data: Map): Single> @GET(ApiPaths.URL_AUTOCOMPLETE_SELECT_EVENT) - fun trackAutocompleteSelect(@Path("term") term: String, @QueryMap data: Map, @QueryMap(encoded = true) encodedData: Map, @Query("result_id") resultID: String?): Completable + fun trackAutocompleteSelect(@Path("term") term: String, @QueryMap data: Map, @QueryMap(encoded = true) encodedData: Map): Completable @GET(ApiPaths.URL_SEARCH_SUBMIT_EVENT) fun trackSearchSubmit(@Path("term") term: String, @QueryMap data: Map, @QueryMap(encoded = true) encodedData: Map): Completable @@ -26,7 +26,7 @@ interface ConstructorApi { fun trackConversion(@Path("term") term: String, @Query("name") itemName: String, @Query("customer_id") customerId: String, @Query("revenue") revenue: String?, @QueryMap params: Map): Completable @GET(ApiPaths.URL_SEARCH_RESULT_CLICK_EVENT) - fun trackSearchResultClick(@Path("term") term: String, @Query("name") itemName: String, @Query("customer_id") customerId: String, @QueryMap params: Map, @Query("result_id") resultID: String?): Completable + fun trackSearchResultClick(@Path("term") term: String, @Query("name") itemName: String, @Query("customer_id") customerId: String, @QueryMap params: Map, @QueryMap(encoded = true) encodedData: Map): Completable @GET(ApiPaths.URL_BEHAVIOR) fun trackSearchResultsLoaded(@Query("term") term: String, @Query("num_results") resultCount: Int, @QueryMap params: Map): Completable @@ -37,8 +37,8 @@ interface ConstructorApi { @GET(ApiPaths.URL_PURCHASE) fun trackPurchase(@Query(Constants.QueryConstants.CUSTOMER_ID) customerIds: List, @Query("revenue") revenue: String?, - @QueryMap params: Map, - @Query("order_id") orderID: String): Completable + @Query("order_id") orderID: String, + @QueryMap params: Map): Completable @GET fun getSearchResults(@Url searchUrl: String): Single> diff --git a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt index f69175cd..9f2876bc 100755 --- a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt +++ b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt @@ -3,6 +3,7 @@ package io.constructor.core import android.content.Context import io.constructor.data.local.PreferencesHelper import io.constructor.data.memory.ConfigMemoryHolder +import io.constructor.data.model.Group import io.constructor.test.createTestDataManager import io.constructor.util.RxSchedulersOverrideRule import io.mockk.Runs @@ -11,6 +12,7 @@ import io.mockk.just import io.mockk.mockk import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer +import org.json.JSONObject import org.junit.Before import org.junit.Rule import org.junit.Test @@ -52,10 +54,10 @@ class ConstructorIoTest { fun trackAutocompleteSelect() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions", null, "2347874").test() + val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions").test() observer.assertComplete() val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" + val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" assert(request.path.startsWith(path)) } @@ -63,10 +65,10 @@ class ConstructorIoTest { fun trackAutocompleteSelectWithServerError() { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions", null, "2347874").test() + val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions").test() observer.assertError { true } val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" + val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" assert(request.path.startsWith(path)) } @@ -75,10 +77,21 @@ class ConstructorIoTest { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockResponse.throttleBody(0, 5, TimeUnit.SECONDS) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions", null, "2347874").test() + val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions").test() observer.assertError(SocketTimeoutException::class.java) val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" + val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" + assert(request.path.startsWith(path)) + } + + @Test + fun trackAutocompleteSelectOptionalParams() { + val mockResponse = MockResponse().setResponseCode(204) + mockServer.enqueue(mockResponse) + val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions", Group("recommended", "123123"), "2346784").test() + observer.assertComplete() + val request = mockServer.takeRequest() + val path = "/autocomplete/titanic/select?autocomplete_section=Search%20Suggestions&original_query=tit&tr=click&group%5Bgroup_id%5D=123123&group%5Bdisplay_name%5D=recommended&result_id=2346784&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt=" assert(request.path.startsWith(path)) } @@ -188,10 +201,10 @@ class ConstructorIoTest { fun trackSearchResultClick() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic", null, "2347874").test() + val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic").test() observer.assertComplete() val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -199,10 +212,10 @@ class ConstructorIoTest { fun trackSearchResultClick500() { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic", null, "2347874").test() + val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic").test() observer.assertError { true } val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -211,10 +224,21 @@ class ConstructorIoTest { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockResponse.throttleBody(0, 5, TimeUnit.SECONDS) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic", null, "2347874").test() + val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic").test() observer.assertError(SocketTimeoutException::class.java) val request = mockServer.takeRequest() - val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&result_id=2347874&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + assert(request.path.startsWith(path)) + } + + @Test + fun trackSearchResultClickOptionalParams() { + val mockResponse = MockResponse().setResponseCode(204) + mockServer.enqueue(mockResponse) + val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic", "Products","3467632").test() + observer.assertComplete() + val request = mockServer.takeRequest() + val path = "/autocomplete/titanic/click_through?name=titanic%20replica&customer_id=TIT-REP-1997&autocomplete_section=Products&result_id=3467632&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -290,10 +314,10 @@ class ConstructorIoTest { fun trackPurchase() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products", "1312343").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "1312343").test() observer.assertComplete() val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&order_id=1312343&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=1312343&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -301,10 +325,10 @@ class ConstructorIoTest { fun trackPurchase500() { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products", "1312343").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "1312343").test() observer.assertError { true } val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&order_id=1312343&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=1312343&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -313,10 +337,21 @@ class ConstructorIoTest { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockResponse.throttleBody(0, 5, TimeUnit.SECONDS) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "Products", "1312343").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99,"1312343").test() observer.assertError(SocketTimeoutException::class.java) val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&autocomplete_section=Products&order_id=1312343&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=1312343&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + assert(request.path.startsWith(path)) + } + + @Test + fun trackPurchaseOptionalParams() { + val mockResponse = MockResponse().setResponseCode(204) + mockServer.enqueue(mockResponse) + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "1312343", "Recommendations").test() + observer.assertComplete() + val request = mockServer.takeRequest() + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=1312343&autocomplete_section=Recommendations&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } } \ No newline at end of file From afc767c7f889160f68befc5fd07b93c0eeabae7a Mon Sep 17 00:00:00 2001 From: cgee1 Date: Tue, 19 May 2020 09:12:01 -0700 Subject: [PATCH 4/5] Change test name --- .../core/ConstructorIoTrackingTest.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt index 9f2876bc..10e82ca7 100755 --- a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt +++ b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt @@ -85,7 +85,7 @@ class ConstructorIoTest { } @Test - fun trackAutocompleteSelectOptionalParams() { + fun trackAutocompleteSelectWithOptionalParams() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) val observer = ConstructorIo.trackAutocompleteSelect("titanic", "tit", "Search Suggestions", Group("recommended", "123123"), "2346784").test() @@ -232,7 +232,7 @@ class ConstructorIoTest { } @Test - fun trackSearchResultClickOptionalParams() { + fun trackSearchResultClickWithOptionalParams() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) val observer = ConstructorIo.trackSearchResultClick("titanic replica", "TIT-REP-1997", "titanic", "Products","3467632").test() @@ -314,10 +314,10 @@ class ConstructorIoTest { fun trackPurchase() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "1312343").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "ORD-1312343").test() observer.assertComplete() val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=1312343&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=ORD-1312343&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -325,10 +325,10 @@ class ConstructorIoTest { fun trackPurchase500() { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "1312343").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "ORD-1312343").test() observer.assertError { true } val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=1312343&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=ORD-1312343&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @@ -337,21 +337,21 @@ class ConstructorIoTest { val mockResponse = MockResponse().setResponseCode(500).setBody("Internal server error") mockResponse.throttleBody(0, 5, TimeUnit.SECONDS) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99,"1312343").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99,"ORD-1312343").test() observer.assertError(SocketTimeoutException::class.java) val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=1312343&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=ORD-1312343&autocomplete_section=Products&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } @Test - fun trackPurchaseOptionalParams() { + fun trackPurchaseWithOptionalParams() { val mockResponse = MockResponse().setResponseCode(204) mockServer.enqueue(mockResponse) - val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "1312343", "Recommendations").test() + val observer = ConstructorIo.trackPurchase(arrayOf("TIT-REP-1997", "QE2-REP-1969"), 12.99, "ORD-1312343", "Recommendations").test() observer.assertComplete() val request = mockServer.takeRequest() - val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=1312343&autocomplete_section=Recommendations&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; + val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=ORD-1312343&autocomplete_section=Recommendations&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } } \ No newline at end of file From 309e0e45dcf19242235bd71f7ec39db7c4af7d47 Mon Sep 17 00:00:00 2001 From: cgee1 Date: Tue, 19 May 2020 09:14:46 -0700 Subject: [PATCH 5/5] Lint --- .../test/java/io/constructor/core/ConstructorIoTrackingTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt index 10e82ca7..52eccb0c 100755 --- a/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt +++ b/library/src/test/java/io/constructor/core/ConstructorIoTrackingTest.kt @@ -354,4 +354,4 @@ class ConstructorIoTest { val path = "/autocomplete/TERM_UNKNOWN/purchase?customer_ids=TIT-REP-1997&customer_ids=QE2-REP-1969&revenue=12.99&order_id=ORD-1312343&autocomplete_section=Recommendations&key=copper-key&i=wacko-the-guid&ui=player-three&s=67&c=cioand-1.3.0&_dt="; assert(request.path.startsWith(path)) } -} \ No newline at end of file +}