Skip to content

Commit a687a34

Browse files
authored
fix(insights): disable events auto sending by default (#406)
* fix(insights): disable events auto sending by default * fix tests
1 parent db7d8c8 commit a687a34

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

instantsearch/src/commonMain/kotlin/com/algolia/instantsearch/searcher/hits/HitsSearcher.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public fun HitsSearcher(
7777
coroutineScope: CoroutineScope = SearcherScope(),
7878
coroutineDispatcher: CoroutineDispatcher = defaultDispatcher,
7979
triggerSearchFor: SearchForQuery = SearchForQuery.All,
80-
isAutoSendingHitsViewEvents: Boolean = true,
80+
isAutoSendingHitsViewEvents: Boolean = false,
8181
userToken: UserToken = UserToken.anonymous(),
8282
): HitsSearcher = DefaultHitsSearcher(
8383
searchService = DefaultHitsSearchService(client),
@@ -117,7 +117,7 @@ public fun HitsSearcher(
117117
coroutineScope: CoroutineScope = SearcherScope(),
118118
coroutineDispatcher: CoroutineDispatcher = defaultDispatcher,
119119
triggerSearchFor: SearchForQuery = SearchForQuery.All,
120-
isAutoSendingHitsViewEvents: Boolean = true,
120+
isAutoSendingHitsViewEvents: Boolean = false,
121121
userToken: UserToken = UserToken.anonymous(),
122122
): HitsSearcher = HitsSearcher(
123123
client = ClientSearch(applicationID, apiKey),
@@ -149,7 +149,7 @@ public fun MultiSearcher.addHitsSearcher(
149149
requestOptions: RequestOptions? = null,
150150
isDisjunctiveFacetingEnabled: Boolean = true,
151151
triggerSearchFor: SearchForQuery = SearchForQuery.All,
152-
isAutoSendingHitsViewEvents: Boolean = true,
152+
isAutoSendingHitsViewEvents: Boolean = false,
153153
userToken: UserToken = UserToken.anonymous(),
154154
): HitsSearcher {
155155
return DefaultHitsSearcher(

instantsearch/src/commonTest/kotlin/searcher/Extensions.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ fun TestSearcherSingle(
2222
indexName: IndexName,
2323
insights: ClientInsights = ClientInsights(client.applicationID, client.apiKey),
2424
coroutineScope: CoroutineScope = TestCoroutineScope,
25+
isAutoSendingHitsViewEvents: Boolean = false,
2526
) = HitsSearcher(
2627
client = client,
2728
insights = insights,
2829
indexName = indexName,
2930
isDisjunctiveFacetingEnabled = false,
30-
coroutineScope = coroutineScope
31+
coroutineScope = coroutineScope,
32+
isAutoSendingHitsViewEvents = isAutoSendingHitsViewEvents,
3133
)
3234

3335
fun TestSearcherForFacets(client: ClientSearch, indexName: IndexName, attribute: Attribute) = FacetsSearcher(

instantsearch/src/commonTest/kotlin/searcher/TestSearcherSingleIndex.kt

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ class TestSearcherSingleIndex {
9898
)
9999
}
100100
val searcher =
101-
TestSearcherSingle(mockClient(mockSearchEngine), indexName, mockClientInsights(mockInsightsEngine), this)
101+
TestSearcherSingle(
102+
client = mockClient(mockSearchEngine),
103+
indexName = indexName,
104+
insights = mockClientInsights(mockInsightsEngine),
105+
coroutineScope = this,
106+
isAutoSendingHitsViewEvents = true,
107+
)
102108
searcher.searchAsync().join()
103109
userToken.startsWith("anonymous-").shouldBeTrue()
104110
fetchedObjectIDs shouldEqual listOf("\"obj1\"", "\"obj2\"", "\"obj3\"")
@@ -131,7 +137,13 @@ class TestSearcherSingleIndex {
131137
)
132138
}
133139
val searcher =
134-
TestSearcherSingle(mockClient(mockSearchEngine), indexName, mockClientInsights(mockInsightsEngine), this)
140+
TestSearcherSingle(
141+
client = mockClient(mockSearchEngine),
142+
indexName = indexName,
143+
insights = mockClientInsights(mockInsightsEngine),
144+
coroutineScope = this,
145+
isAutoSendingHitsViewEvents = true,
146+
)
135147

136148
searcher.searchAsync().join()
137149
eventsCount shouldEqual 2
@@ -163,7 +175,13 @@ class TestSearcherSingleIndex {
163175
)
164176
}
165177
val searcher =
166-
TestSearcherSingle(mockClient(mockSearchEngine), indexName, mockClientInsights(mockInsightsEngine), this)
178+
TestSearcherSingle(
179+
client = mockClient(mockSearchEngine),
180+
indexName = indexName,
181+
insights = mockClientInsights(mockInsightsEngine),
182+
coroutineScope = this,
183+
isAutoSendingHitsViewEvents = true,
184+
)
167185
searcher.isAutoSendingHitsViewEvents = false
168186
searcher.searchAsync().join()
169187
calledInsights.shouldBeFalse()
@@ -197,11 +215,16 @@ class TestSearcherSingleIndex {
197215
)
198216
}
199217
val searcher =
200-
TestSearcherSingle(mockClient(mockSearchEngine), indexName, mockClientInsights(mockInsightsEngine), this)
218+
TestSearcherSingle(
219+
client = mockClient(mockSearchEngine),
220+
indexName = indexName,
221+
insights = mockClientInsights(mockInsightsEngine),
222+
coroutineScope = this,
223+
isAutoSendingHitsViewEvents = true,
224+
)
201225
searcher.userToken = UserToken("my-user-token");
202226
searcher.searchAsync().join()
203227

204228
userToken shouldEqual "my-user-token"
205229
}
206-
207230
}

0 commit comments

Comments
 (0)