@@ -92,7 +92,7 @@ describe('createAlgoliaInsightsPlugin', () => {
92
92
93
93
createPlayground ( createAutocomplete , { plugins : [ insightsPlugin ] } ) ;
94
94
95
- expect ( insightsClient ) . toHaveBeenCalledTimes ( 5 ) ;
95
+ expect ( insightsClient ) . toHaveBeenCalledTimes ( 3 ) ;
96
96
expect ( insightsClient ) . toHaveBeenCalledWith (
97
97
'addAlgoliaAgent' ,
98
98
'insights-plugin'
@@ -256,7 +256,7 @@ describe('createAlgoliaInsightsPlugin', () => {
256
256
] ) ;
257
257
} ) ;
258
258
259
- test ( 'forwards `authenticatedUserToken` from Search Insights to Algolia API requests' , async ( ) => {
259
+ test ( 'does not forward `authenticatedUserToken` from Search Insights to Algolia API requests' , async ( ) => {
260
260
const insightsPlugin = createAlgoliaInsightsPlugin ( { insightsClient } ) ;
261
261
262
262
const searchClient = createSearchClient ( {
@@ -299,89 +299,9 @@ describe('createAlgoliaInsightsPlugin', () => {
299
299
expect ( searchClient . search ) . toHaveBeenCalledTimes ( 1 ) ;
300
300
expect ( searchClient . search ) . toHaveBeenCalledWith ( [
301
301
expect . objectContaining ( {
302
- params : expect . objectContaining ( { userToken : 'customAuthUserToken' } ) ,
303
- } ) ,
304
- ] ) ;
305
- } ) ;
306
-
307
- test ( 'uses `authenticatedUserToken` in priority over `userToken`' , async ( ) => {
308
- const insightsPlugin = createAlgoliaInsightsPlugin ( {
309
- insightsClient,
310
- insightsInitParams : {
311
- userToken : 'customUserToken' ,
312
- } ,
313
- } ) ;
314
-
315
- const searchClient = createSearchClient ( {
316
- search : jest . fn ( ( ) =>
317
- Promise . resolve (
318
- createMultiSearchResponse ( {
319
- hits : [ { objectID : '1' } ] ,
320
- } )
321
- )
322
- ) ,
323
- } ) ;
324
-
325
- // Setting an authenticated user token should replace the user token
326
- insightsClient ( 'setAuthenticatedUserToken' , 'customAuthUserToken' ) ;
327
-
328
- const playground = createPlayground ( createAutocomplete , {
329
- plugins : [ insightsPlugin ] ,
330
- getSources ( { query } ) {
331
- return [
332
- {
333
- sourceId : 'hits' ,
334
- getItems ( ) {
335
- return getAlgoliaResults ( {
336
- searchClient,
337
- queries : [ { indexName : 'indexName' , query } ] ,
338
- } ) ;
339
- } ,
340
- templates : {
341
- item ( { item } ) {
342
- return item . objectID ;
343
- } ,
344
- } ,
345
- } ,
346
- ] ;
347
- } ,
348
- } ) ;
349
-
350
- userEvent . type ( playground . inputElement , 'a' ) ;
351
- await runAllMicroTasks ( ) ;
352
-
353
- expect ( searchClient . search ) . toHaveBeenCalledTimes ( 1 ) ;
354
- expect ( searchClient . search ) . toHaveBeenCalledWith ( [
355
- expect . objectContaining ( {
356
- params : expect . objectContaining ( { userToken : 'customAuthUserToken' } ) ,
357
- } ) ,
358
- ] ) ;
359
-
360
- // Updating a user token should have no effect if there is
361
- // an authenticated user token already set
362
- insightsClient ( 'setUserToken' , 'customUserToken2' ) ;
363
-
364
- userEvent . type ( playground . inputElement , 'b' ) ;
365
- await runAllMicroTasks ( ) ;
366
-
367
- expect ( searchClient . search ) . toHaveBeenCalledTimes ( 2 ) ;
368
- expect ( searchClient . search ) . toHaveBeenLastCalledWith ( [
369
- expect . objectContaining ( {
370
- params : expect . objectContaining ( { userToken : 'customAuthUserToken' } ) ,
371
- } ) ,
372
- ] ) ;
373
-
374
- // Removing the authenticated user token should revert to
375
- // the latest user token set
376
- insightsClient ( 'setAuthenticatedUserToken' , undefined ) ;
377
-
378
- userEvent . type ( playground . inputElement , 'c' ) ;
379
- await runAllMicroTasks ( ) ;
380
-
381
- expect ( searchClient . search ) . toHaveBeenCalledTimes ( 3 ) ;
382
- expect ( searchClient . search ) . toHaveBeenLastCalledWith ( [
383
- expect . objectContaining ( {
384
- params : expect . objectContaining ( { userToken : 'customUserToken2' } ) ,
302
+ params : expect . not . objectContaining ( {
303
+ userToken : 'customAuthUserToken' ,
304
+ } ) ,
385
305
} ) ,
386
306
] ) ;
387
307
} ) ;
0 commit comments