Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/src/main/java/io/constructor/core/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Constants {
const val ORIGINAL_QUERY = "original_query"
const val CLIENT = "c"
const val EVENT = "tr"
const val AUTOCOMPLETE_KEY = "autocomplete_key"
const val API_KEY = "key"
const val NUM_RESULTS = "num_results_"
const val GROUP_ID = "group[group_id]"
const val GROUP_DISPLAY_NAME = "group[display_name]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TokenInterceptor(val context: Context, private val preferencesHelper: Pref
override fun intercept(chain: Interceptor.Chain): Response {
var request = chain.request()
val builder = request.url().newBuilder()
.addQueryParameter(Constants.QueryConstants.AUTOCOMPLETE_KEY, preferencesHelper.token)
.addQueryParameter(Constants.QueryConstants.API_KEY, preferencesHelper.token)
.addQueryParameter(Constants.QueryConstants.IDENTITY, preferencesHelper.id)
.addQueryParameter(Constants.QueryConstants.TIMESTAMP, System.currentTimeMillis().toString())
.addQueryParameter(Constants.QueryConstants.CLIENT, BuildConfig.CLIENT_VERSION)
Expand Down
28 changes: 14 additions & 14 deletions library/src/test/java/io/constructor/core/ConstructorIoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ConstructorIoTest {

@Test
fun verifySelectUrl() {
val expected = "https://ac.cnstrc.com/autocomplete/hot%20dogs/select?s=1&i=1&_dt=1520000000000&autocomplete_section=Search%20Suggestions&original_query=dog&group%5Bgroup_id%5D=Meat%20%26%20Seafood&group%5Bdisplay_name%5D=Meat%20%26%20Seafood&tr=click&c=cioand-${BuildConfig.VERSION_NAME}&autocomplete_key=testKey"
val expected = "https://ac.cnstrc.com/autocomplete/hot%20dogs/select?s=1&i=1&_dt=1520000000000&autocomplete_section=Search%20Suggestions&original_query=dog&group%5Bgroup_id%5D=Meat%20%26%20Seafood&group%5Bdisplay_name%5D=Meat%20%26%20Seafood&tr=click&c=cioand-${BuildConfig.VERSION_NAME}&key=testKey"
val searchQuery = "dog"
val term = "hot dogs"
val urlBuilder = HttpUrl.Builder().scheme("https")
Expand All @@ -70,43 +70,43 @@ class ConstructorIoTest {
.addEncodedQueryParameter(Constants.QueryConstants.GROUP_DISPLAY_NAME.urlEncode(), "Meat & Seafood".urlEncode())
.addQueryParameter(Constants.QueryConstants.EVENT, Constants.QueryValues.EVENT_CLICK)
.addQueryParameter(Constants.QueryConstants.CLIENT, BuildConfig.CLIENT_VERSION)
.addQueryParameter(Constants.QueryConstants.AUTOCOMPLETE_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.API_KEY, "testKey")
val urlString = urlBuilder.build().url().toString()
assertEquals(expected, urlString)
}

@Test
fun verifyGetSuggestionsUrl() {
val expected = "https://ac.cnstrc.com/autocomplete/dog?autocomplete_key=testKey&_dt=1520000000000"
val expected = "https://ac.cnstrc.com/autocomplete/dog?key=testKey&_dt=1520000000000"
val searchQuery = "dog"
val urlBuilder = HttpUrl.Builder().scheme("https")
.host("ac.cnstrc.com")
.addPathSegment("autocomplete")
.addPathSegment(searchQuery)
.addQueryParameter(Constants.QueryConstants.AUTOCOMPLETE_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.API_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.TIMESTAMP, sampleMillis)
val urlString = urlBuilder.build().url().toString()
assertEquals(expected, urlString)
}

@Test
fun verifySessionStartUrl() {
val expected = "https://ac.cnstrc.com/behavior?c=cioand-0.1.0&s=1&action=session_start&autocomplete_key=testKey&_dt=1520000000000"
val expected = "https://ac.cnstrc.com/behavior?c=cioand-0.1.0&s=1&action=session_start&key=testKey&_dt=1520000000000"
val urlBuilder = HttpUrl.Builder().scheme("https")
.host("ac.cnstrc.com")
.addPathSegment("behavior")
.addQueryParameter(Constants.QueryConstants.CLIENT, BuildConfig.CLIENT_VERSION)
.addQueryParameter(Constants.QueryConstants.SESSION, "1")
.addQueryParameter(Constants.QueryConstants.ACTION, "session_start")
.addQueryParameter(Constants.QueryConstants.AUTOCOMPLETE_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.API_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.TIMESTAMP, sampleMillis)
val urlString = urlBuilder.build().url().toString()
assertEquals(expected, urlString)
}

@Test
fun verifySearchClickThroughEvent() {
val expected = "https://ac.cnstrc.com/autocomplete/term/click_through?c=cioand-0.1.0&s=1&autocomplete_section=Products&autocomplete_key=testKey&_dt=1520000000000"
val expected = "https://ac.cnstrc.com/autocomplete/term/click_through?c=cioand-0.1.0&s=1&autocomplete_section=Products&key=testKey&_dt=1520000000000"
val urlBuilder = HttpUrl.Builder().scheme("https")
.host("ac.cnstrc.com")
.addPathSegment("autocomplete")
Expand All @@ -115,38 +115,38 @@ class ConstructorIoTest {
.addQueryParameter(Constants.QueryConstants.CLIENT, BuildConfig.CLIENT_VERSION)
.addQueryParameter(Constants.QueryConstants.SESSION, "1")
.addQueryParameter(Constants.QueryConstants.AUTOCOMPLETE_SECTION, "Products")
.addQueryParameter(Constants.QueryConstants.AUTOCOMPLETE_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.API_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.TIMESTAMP, sampleMillis)
val urlString = urlBuilder.build().url().toString()
assertEquals(expected, urlString)
}

@Test
fun verifySearchLoadedEventUrl() {
val expected = "https://ac.cnstrc.com/behavior?c=cioand-0.1.0&s=1&action=search-results&autocomplete_key=testKey&_dt=1520000000000"
val expected = "https://ac.cnstrc.com/behavior?c=cioand-0.1.0&s=1&action=search-results&key=testKey&_dt=1520000000000"
val urlBuilder = HttpUrl.Builder().scheme("https")
.host("ac.cnstrc.com")
.addPathSegment("behavior")
.addQueryParameter(Constants.QueryConstants.CLIENT, BuildConfig.CLIENT_VERSION)
.addQueryParameter(Constants.QueryConstants.SESSION, "1")
.addQueryParameter(Constants.QueryConstants.ACTION, Constants.QueryValues.EVENT_SEARCH_RESULTS)
.addQueryParameter(Constants.QueryConstants.AUTOCOMPLETE_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.API_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.TIMESTAMP, sampleMillis)
val urlString = urlBuilder.build().url().toString()
assertEquals(expected, urlString)
}

@Test
fun verifyInputFocusEvent() {
val expected = "https://ac.cnstrc.com/behavior?c=cioand-0.1.0&i=user_id&s=1&action=focus&autocomplete_key=testKey&_dt=1520000000000"
val expected = "https://ac.cnstrc.com/behavior?c=cioand-0.1.0&i=user_id&s=1&action=focus&key=testKey&_dt=1520000000000"
val urlBuilder = HttpUrl.Builder().scheme("https")
.host("ac.cnstrc.com")
.addPathSegment("behavior")
.addQueryParameter(Constants.QueryConstants.CLIENT, BuildConfig.CLIENT_VERSION)
.addQueryParameter(Constants.QueryConstants.IDENTITY, "user_id")
.addQueryParameter(Constants.QueryConstants.SESSION, "1")
.addQueryParameter(Constants.QueryConstants.ACTION, Constants.QueryValues.EVENT_INPUT_FOCUS)
.addQueryParameter(Constants.QueryConstants.AUTOCOMPLETE_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.API_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.TIMESTAMP, sampleMillis)
val urlString = urlBuilder.build().url().toString()
assertEquals(expected, urlString)
Expand Down Expand Up @@ -184,7 +184,7 @@ class ConstructorIoTest {

@Test
fun verifySearchUrl() {
val expected = "https://ac.cnstrc.com/autocomplete/hot%20dogs/search?s=1&i=1&_dt=1520000000000&original_query=dog&group%5Bgroup_id%5D=Meat%20%26%20Seafood&group%5Bdisplay_name%5D=Meat%20%26%20Seafood&tr=search&c=cioand-${BuildConfig.VERSION_NAME}&autocomplete_key=testKey"
val expected = "https://ac.cnstrc.com/autocomplete/hot%20dogs/search?s=1&i=1&_dt=1520000000000&original_query=dog&group%5Bgroup_id%5D=Meat%20%26%20Seafood&group%5Bdisplay_name%5D=Meat%20%26%20Seafood&tr=search&c=cioand-${BuildConfig.VERSION_NAME}&key=testKey"
val originalQuery = "dog"
val term = "hot dogs"
val urlBuilder = HttpUrl.Builder().scheme("https")
Expand All @@ -200,7 +200,7 @@ class ConstructorIoTest {
.addEncodedQueryParameter(Constants.QueryConstants.GROUP_DISPLAY_NAME.urlEncode(), "Meat & Seafood".urlEncode())
.addQueryParameter(Constants.QueryConstants.EVENT, Constants.QueryValues.EVENT_SEARCH)
.addQueryParameter(Constants.QueryConstants.CLIENT, BuildConfig.CLIENT_VERSION)
.addQueryParameter(Constants.QueryConstants.AUTOCOMPLETE_KEY, "testKey")
.addQueryParameter(Constants.QueryConstants.API_KEY, "testKey")
val urlString = urlBuilder.build().url().toString()
assertEquals(expected, urlString)
}
Expand Down