@@ -927,7 +927,7 @@ describe('insights', () => {
927
927
928
928
describe ( 'authenticatedUserToken' , ( ) => {
929
929
describe ( 'before `init`' , ( ) => {
930
- it ( 'uses the `authenticatedUserToken` as the `userToken` when defined' , ( ) => {
930
+ it ( 'does not use `authenticatedUserToken` as the `userToken` when defined' , ( ) => {
931
931
const { insightsClient, instantSearchInstance, getUserToken } =
932
932
createTestEnvironment ( ) ;
933
933
@@ -937,10 +937,10 @@ describe('insights', () => {
937
937
createInsightsMiddleware ( { insightsClient } )
938
938
) ;
939
939
940
- expect ( getUserToken ( ) ) . toEqual ( 'abc' ) ;
940
+ expect ( getUserToken ( ) ) . toEqual ( expect . stringMatching ( / ^ a n o n y m o u s - / ) ) ;
941
941
} ) ;
942
942
943
- it ( 'uses the `authenticatedUserToken` as the `userToken` when both are defined' , ( ) => {
943
+ it ( 'does not use `authenticatedUserToken` as the `userToken` when both are defined' , ( ) => {
944
944
const { insightsClient, instantSearchInstance, getUserToken } =
945
945
createTestEnvironment ( ) ;
946
946
@@ -951,60 +951,60 @@ describe('insights', () => {
951
951
createInsightsMiddleware ( { insightsClient } )
952
952
) ;
953
953
954
- expect ( getUserToken ( ) ) . toEqual ( 'def ' ) ;
954
+ expect ( getUserToken ( ) ) . toEqual ( 'abc ' ) ;
955
955
} ) ;
956
956
957
- it ( 'reverts to the `userToken ` when unsetting the `authenticatedUserToken` ' , ( ) => {
957
+ it ( 'does not use `authenticatedUserToken ` when a `userToken` is set after ' , ( ) => {
958
958
const { insightsClient, instantSearchInstance, getUserToken } =
959
959
createTestEnvironment ( ) ;
960
960
961
- insightsClient ( 'setUserToken' , 'abc' ) ;
962
961
insightsClient ( 'setAuthenticatedUserToken' , 'def' ) ;
963
- insightsClient ( 'setAuthenticatedUserToken' , undefined ) ;
964
962
965
963
instantSearchInstance . use (
966
964
createInsightsMiddleware ( { insightsClient } )
967
965
) ;
968
966
967
+ insightsClient ( 'setUserToken' , 'abc' ) ;
968
+
969
969
expect ( getUserToken ( ) ) . toEqual ( 'abc' ) ;
970
970
} ) ;
971
+ } ) ;
971
972
972
- it ( 'uses the `authenticatedUserToken` when a `userToken` is set after' , ( ) => {
973
+ describe ( 'from `init` props' , ( ) => {
974
+ it ( 'does not use `authenticatedUserToken` as the `userToken` when defined' , ( ) => {
973
975
const { insightsClient, instantSearchInstance, getUserToken } =
974
976
createTestEnvironment ( ) ;
975
977
976
- insightsClient ( 'setAuthenticatedUserToken' , 'def' ) ;
977
-
978
978
instantSearchInstance . use (
979
- createInsightsMiddleware ( { insightsClient } )
979
+ createInsightsMiddleware ( {
980
+ insightsClient,
981
+ insightsInitParams : { authenticatedUserToken : 'abc' } ,
982
+ } )
980
983
) ;
981
984
982
- insightsClient ( 'setUserToken' , 'abc' ) ;
983
-
984
- expect ( getUserToken ( ) ) . toEqual ( 'def' ) ;
985
+ expect ( getUserToken ( ) ) . toEqual ( expect . stringMatching ( / ^ a n o n y m o u s - / ) ) ;
985
986
} ) ;
986
987
987
- it ( 'resets the token to the `userToken` when `authenticatedUserToken` is set as undefined ' , ( ) => {
988
+ it ( 'does not use `authenticatedUserToken` as the `userToken` when both are defined ' , ( ) => {
988
989
const { insightsClient, instantSearchInstance, getUserToken } =
989
990
createTestEnvironment ( ) ;
990
991
991
- insightsClient ( 'setUserToken' , 'abc' ) ;
992
- insightsClient ( 'setAuthenticatedUserToken' , 'def' ) ;
993
-
994
992
instantSearchInstance . use (
995
- createInsightsMiddleware ( { insightsClient } )
993
+ createInsightsMiddleware ( {
994
+ insightsClient,
995
+ insightsInitParams : {
996
+ authenticatedUserToken : 'abc' ,
997
+ userToken : 'def' ,
998
+ } ,
999
+ } )
996
1000
) ;
997
1001
998
1002
expect ( getUserToken ( ) ) . toEqual ( 'def' ) ;
999
-
1000
- insightsClient ( 'setAuthenticatedUserToken' , undefined ) ;
1001
-
1002
- expect ( getUserToken ( ) ) . toEqual ( 'abc' ) ;
1003
1003
} ) ;
1004
1004
} ) ;
1005
1005
1006
1006
describe ( 'after `init`' , ( ) => {
1007
- it ( 'uses the `authenticatedUserToken` as the `userToken` when defined' , async ( ) => {
1007
+ it ( 'does not use `authenticatedUserToken` as the `userToken` when defined' , async ( ) => {
1008
1008
const { insightsClient, instantSearchInstance, getUserToken } =
1009
1009
createTestEnvironment ( ) ;
1010
1010
instantSearchInstance . use (
@@ -1015,25 +1015,10 @@ describe('insights', () => {
1015
1015
1016
1016
await wait ( 0 ) ;
1017
1017
1018
- expect ( getUserToken ( ) ) . toEqual ( 'abc' ) ;
1019
- } ) ;
1020
-
1021
- it ( 'uses the `authenticatedUserToken` as the `userToken` when both are defined' , async ( ) => {
1022
- const { insightsClient, instantSearchInstance, getUserToken } =
1023
- createTestEnvironment ( ) ;
1024
- instantSearchInstance . use (
1025
- createInsightsMiddleware ( { insightsClient } )
1026
- ) ;
1027
-
1028
- insightsClient ( 'setUserToken' , 'abc' ) ;
1029
- insightsClient ( 'setAuthenticatedUserToken' , 'def' ) ;
1030
-
1031
- await wait ( 0 ) ;
1032
-
1033
- expect ( getUserToken ( ) ) . toEqual ( 'def' ) ;
1018
+ expect ( getUserToken ( ) ) . toEqual ( expect . stringMatching ( / ^ a n o n y m o u s - / ) ) ;
1034
1019
} ) ;
1035
1020
1036
- it ( 'reverts to the `userToken` when unsetting the `authenticatedUserToken` ' , async ( ) => {
1021
+ it ( 'does not use `authenticatedUserToken` as the `userToken` when both are defined ' , async ( ) => {
1037
1022
const { insightsClient, instantSearchInstance, getUserToken } =
1038
1023
createTestEnvironment ( ) ;
1039
1024
instantSearchInstance . use (
@@ -1042,7 +1027,6 @@ describe('insights', () => {
1042
1027
1043
1028
insightsClient ( 'setUserToken' , 'abc' ) ;
1044
1029
insightsClient ( 'setAuthenticatedUserToken' , 'def' ) ;
1045
- insightsClient ( 'setAuthenticatedUserToken' , undefined ) ;
1046
1030
1047
1031
await wait ( 0 ) ;
1048
1032
@@ -1051,7 +1035,7 @@ describe('insights', () => {
1051
1035
} ) ;
1052
1036
1053
1037
describe ( 'from queue' , ( ) => {
1054
- it ( 'uses the `authenticatedUserToken` as the `userToken` when defined' , ( ) => {
1038
+ it ( 'does not use `authenticatedUserToken` as the `userToken` when defined' , ( ) => {
1055
1039
const {
1056
1040
insightsClient,
1057
1041
libraryLoadedAndProcessQueue,
@@ -1069,10 +1053,10 @@ describe('insights', () => {
1069
1053
) ;
1070
1054
libraryLoadedAndProcessQueue ( ) ;
1071
1055
1072
- expect ( getUserToken ( ) ) . toEqual ( 'abc' ) ;
1056
+ expect ( getUserToken ( ) ) . toEqual ( expect . stringMatching ( / ^ a n o n y m o u s - / ) ) ;
1073
1057
} ) ;
1074
1058
1075
- it ( 'uses the `authenticatedUserToken` as the `userToken` when both are defined' , ( ) => {
1059
+ it ( 'does not use `authenticatedUserToken` as the `userToken` when both are defined' , ( ) => {
1076
1060
const {
1077
1061
insightsClient,
1078
1062
libraryLoadedAndProcessQueue,
@@ -1091,28 +1075,6 @@ describe('insights', () => {
1091
1075
) ;
1092
1076
libraryLoadedAndProcessQueue ( ) ;
1093
1077
1094
- expect ( getUserToken ( ) ) . toEqual ( 'def' ) ;
1095
- } ) ;
1096
-
1097
- it ( 'reverts to the `userToken` when unsetting the `authenticatedUserToken`' , ( ) => {
1098
- const {
1099
- insightsClient,
1100
- libraryLoadedAndProcessQueue,
1101
- instantSearchInstance,
1102
- getUserToken,
1103
- } = createUmdTestEnvironment ( ) ;
1104
-
1105
- insightsClient ( 'setUserToken' , 'abc' ) ;
1106
- insightsClient ( 'setAuthenticatedUserToken' , 'def' ) ;
1107
- insightsClient ( 'setAuthenticatedUserToken' , undefined ) ;
1108
-
1109
- instantSearchInstance . use (
1110
- createInsightsMiddleware ( {
1111
- insightsClient,
1112
- } )
1113
- ) ;
1114
- libraryLoadedAndProcessQueue ( ) ;
1115
-
1116
1078
expect ( getUserToken ( ) ) . toEqual ( 'abc' ) ;
1117
1079
} ) ;
1118
1080
} ) ;
0 commit comments