From 573c1efce111a8475fb29645bb704e2e44468d5d Mon Sep 17 00:00:00 2001 From: Mouaad Aallam Date: Tue, 14 May 2024 16:40:34 +0200 Subject: [PATCH 1/2] fix(insights): disable events auto sending by default --- .../com/algolia/instantsearch/searcher/hits/HitsSearcher.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/instantsearch/src/commonMain/kotlin/com/algolia/instantsearch/searcher/hits/HitsSearcher.kt b/instantsearch/src/commonMain/kotlin/com/algolia/instantsearch/searcher/hits/HitsSearcher.kt index 4ba5124e6..3db5909d3 100644 --- a/instantsearch/src/commonMain/kotlin/com/algolia/instantsearch/searcher/hits/HitsSearcher.kt +++ b/instantsearch/src/commonMain/kotlin/com/algolia/instantsearch/searcher/hits/HitsSearcher.kt @@ -77,7 +77,7 @@ public fun HitsSearcher( coroutineScope: CoroutineScope = SearcherScope(), coroutineDispatcher: CoroutineDispatcher = defaultDispatcher, triggerSearchFor: SearchForQuery = SearchForQuery.All, - isAutoSendingHitsViewEvents: Boolean = true, + isAutoSendingHitsViewEvents: Boolean = false, userToken: UserToken = UserToken.anonymous(), ): HitsSearcher = DefaultHitsSearcher( searchService = DefaultHitsSearchService(client), @@ -117,7 +117,7 @@ public fun HitsSearcher( coroutineScope: CoroutineScope = SearcherScope(), coroutineDispatcher: CoroutineDispatcher = defaultDispatcher, triggerSearchFor: SearchForQuery = SearchForQuery.All, - isAutoSendingHitsViewEvents: Boolean = true, + isAutoSendingHitsViewEvents: Boolean = false, userToken: UserToken = UserToken.anonymous(), ): HitsSearcher = HitsSearcher( client = ClientSearch(applicationID, apiKey), @@ -149,7 +149,7 @@ public fun MultiSearcher.addHitsSearcher( requestOptions: RequestOptions? = null, isDisjunctiveFacetingEnabled: Boolean = true, triggerSearchFor: SearchForQuery = SearchForQuery.All, - isAutoSendingHitsViewEvents: Boolean = true, + isAutoSendingHitsViewEvents: Boolean = false, userToken: UserToken = UserToken.anonymous(), ): HitsSearcher { return DefaultHitsSearcher( From 79014c3ee024f411c1307e97c360181ac3c824a8 Mon Sep 17 00:00:00 2001 From: Mouaad Aallam Date: Thu, 16 May 2024 11:01:55 +0200 Subject: [PATCH 2/2] fix tests --- .../commonTest/kotlin/searcher/Extensions.kt | 4 ++- .../searcher/TestSearcherSingleIndex.kt | 33 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/instantsearch/src/commonTest/kotlin/searcher/Extensions.kt b/instantsearch/src/commonTest/kotlin/searcher/Extensions.kt index a71adab0f..5a45ca90f 100644 --- a/instantsearch/src/commonTest/kotlin/searcher/Extensions.kt +++ b/instantsearch/src/commonTest/kotlin/searcher/Extensions.kt @@ -22,12 +22,14 @@ fun TestSearcherSingle( indexName: IndexName, insights: ClientInsights = ClientInsights(client.applicationID, client.apiKey), coroutineScope: CoroutineScope = TestCoroutineScope, + isAutoSendingHitsViewEvents: Boolean = false, ) = HitsSearcher( client = client, insights = insights, indexName = indexName, isDisjunctiveFacetingEnabled = false, - coroutineScope = coroutineScope + coroutineScope = coroutineScope, + isAutoSendingHitsViewEvents = isAutoSendingHitsViewEvents, ) fun TestSearcherForFacets(client: ClientSearch, indexName: IndexName, attribute: Attribute) = FacetsSearcher( diff --git a/instantsearch/src/commonTest/kotlin/searcher/TestSearcherSingleIndex.kt b/instantsearch/src/commonTest/kotlin/searcher/TestSearcherSingleIndex.kt index 918b12b92..203626d20 100644 --- a/instantsearch/src/commonTest/kotlin/searcher/TestSearcherSingleIndex.kt +++ b/instantsearch/src/commonTest/kotlin/searcher/TestSearcherSingleIndex.kt @@ -98,7 +98,13 @@ class TestSearcherSingleIndex { ) } val searcher = - TestSearcherSingle(mockClient(mockSearchEngine), indexName, mockClientInsights(mockInsightsEngine), this) + TestSearcherSingle( + client = mockClient(mockSearchEngine), + indexName = indexName, + insights = mockClientInsights(mockInsightsEngine), + coroutineScope = this, + isAutoSendingHitsViewEvents = true, + ) searcher.searchAsync().join() userToken.startsWith("anonymous-").shouldBeTrue() fetchedObjectIDs shouldEqual listOf("\"obj1\"", "\"obj2\"", "\"obj3\"") @@ -131,7 +137,13 @@ class TestSearcherSingleIndex { ) } val searcher = - TestSearcherSingle(mockClient(mockSearchEngine), indexName, mockClientInsights(mockInsightsEngine), this) + TestSearcherSingle( + client = mockClient(mockSearchEngine), + indexName = indexName, + insights = mockClientInsights(mockInsightsEngine), + coroutineScope = this, + isAutoSendingHitsViewEvents = true, + ) searcher.searchAsync().join() eventsCount shouldEqual 2 @@ -163,7 +175,13 @@ class TestSearcherSingleIndex { ) } val searcher = - TestSearcherSingle(mockClient(mockSearchEngine), indexName, mockClientInsights(mockInsightsEngine), this) + TestSearcherSingle( + client = mockClient(mockSearchEngine), + indexName = indexName, + insights = mockClientInsights(mockInsightsEngine), + coroutineScope = this, + isAutoSendingHitsViewEvents = true, + ) searcher.isAutoSendingHitsViewEvents = false searcher.searchAsync().join() calledInsights.shouldBeFalse() @@ -197,11 +215,16 @@ class TestSearcherSingleIndex { ) } val searcher = - TestSearcherSingle(mockClient(mockSearchEngine), indexName, mockClientInsights(mockInsightsEngine), this) + TestSearcherSingle( + client = mockClient(mockSearchEngine), + indexName = indexName, + insights = mockClientInsights(mockInsightsEngine), + coroutineScope = this, + isAutoSendingHitsViewEvents = true, + ) searcher.userToken = UserToken("my-user-token"); searcher.searchAsync().join() userToken shouldEqual "my-user-token" } - }