@@ -67,8 +67,8 @@ describe.runIf(global.window !== undefined)("getUrlToken", () => {
6767 walletId : "123" ,
6868 } ) ;
6969
70- // Check if URL has been updated correctly
71- expect ( window . location . search ) . toBe ( "?walletId=123&authCookie=myCookie " ) ;
70+ // Check if URL has been updated correctly (should remove thirdweb params)
71+ expect ( window . location . search ) . toBe ( "" ) ;
7272 } ) ;
7373
7474 it ( "should handle all parameters correctly" , ( ) => {
@@ -84,9 +84,52 @@ describe.runIf(global.window !== undefined)("getUrlToken", () => {
8484 walletId : "123" ,
8585 } ) ;
8686
87- // Check if URL has been updated correctly
88- expect ( window . location . search ) . toBe (
89- "?walletId=123&authResult=%7B%22token%22%3A%22xyz%22%7D&authProvider=provider1&authCookie=myCookie" ,
90- ) ;
87+ // Check if URL has been updated correctly (should remove all thirdweb params)
88+ expect ( window . location . search ) . toBe ( "" ) ;
89+ } ) ;
90+
91+ it ( "should preserve custom parameters while removing thirdweb ones" , ( ) => {
92+ window . location . search =
93+ "?custom_param=value&walletId=123&another_custom=test&authCookie=myCookie&user_id=456" ;
94+
95+ const result = getUrlToken ( ) ;
96+
97+ expect ( result ) . toEqual ( {
98+ authCookie : "myCookie" ,
99+ authProvider : null ,
100+ authResult : undefined ,
101+ walletId : "123" ,
102+ } ) ;
103+
104+ // Check if custom parameters are preserved while thirdweb ones are removed
105+ expect ( window . location . search ) . toBe ( "?custom_param=value&another_custom=test&user_id=456" ) ;
106+ } ) ;
107+
108+ it ( "should preserve custom parameters with all thirdweb parameters" , ( ) => {
109+ window . location . search =
110+ "?utm_source=google&walletId=123&authResult=%7B%22token%22%3A%22xyz%22%7D&authProvider=provider1&authCookie=myCookie&ref=homepage" ;
111+
112+ const result = getUrlToken ( ) ;
113+
114+ expect ( result ) . toEqual ( {
115+ authCookie : "myCookie" ,
116+ authProvider : "provider1" ,
117+ authResult : { token : "xyz" } ,
118+ walletId : "123" ,
119+ } ) ;
120+
121+ // Check if custom parameters (utm_source, ref) are preserved
122+ expect ( window . location . search ) . toBe ( "?utm_source=google&ref=homepage" ) ;
123+ } ) ;
124+
125+ it ( "should handle case where only custom parameters exist" , ( ) => {
126+ window . location . search = "?custom_param=value&another_param=test" ;
127+
128+ const result = getUrlToken ( ) ;
129+
130+ expect ( result ) . toEqual ( undefined ) ;
131+
132+ // URL should remain unchanged when no thirdweb params are present
133+ expect ( window . location . search ) . toBe ( "?custom_param=value&another_param=test" ) ;
91134 } ) ;
92135} ) ;
0 commit comments