@@ -64,7 +64,7 @@ describe('Client Creation', () => {
6464 serviceToken : 'service-token-123' ,
6565 requiresAuth : true ,
6666 } ) ;
67-
67+
6868 expect ( client ) . toBeDefined ( ) ;
6969 expect ( client . entities ) . toBeDefined ( ) ;
7070 expect ( client . integrations ) . toBeDefined ( ) ;
@@ -78,6 +78,59 @@ describe('Client Creation', () => {
7878
7979} ) ;
8080
81+ describe ( 'appBaseUrl Normalization' , ( ) => {
82+ test ( 'should use appBaseUrl when provided as a string' , ( ) => {
83+ const customAppBaseUrl = 'https://custom-app.example.com' ;
84+ const client = createClient ( {
85+ appId : 'test-app-id' ,
86+ appBaseUrl : customAppBaseUrl ,
87+ } ) ;
88+
89+ // Mock window.location
90+ const originalWindow = global . window ;
91+ const mockLocation = { href : '' , origin : 'https://current-app.com' } ;
92+ global . window = {
93+ location : mockLocation
94+ } ;
95+
96+ const nextUrl = 'https://example.com/dashboard' ;
97+ client . auth . redirectToLogin ( nextUrl ) ;
98+
99+ // Verify the redirect URL uses the custom appBaseUrl
100+ expect ( mockLocation . href ) . toBe (
101+ `${ customAppBaseUrl } /login?from_url=${ encodeURIComponent ( nextUrl ) } `
102+ ) ;
103+
104+ // Restore window
105+ global . window = originalWindow ;
106+ } ) ;
107+
108+ test ( 'should normalize appBaseUrl to empty string when not provided' , ( ) => {
109+ const client = createClient ( {
110+ appId : 'test-app-id' ,
111+ // appBaseUrl not provided
112+ } ) ;
113+
114+ // Mock window.location
115+ const originalWindow = global . window ;
116+ const mockLocation = { href : '' , origin : 'https://current-app.com' } ;
117+ global . window = {
118+ location : mockLocation
119+ } ;
120+
121+ const nextUrl = 'https://example.com/dashboard' ;
122+ client . auth . redirectToLogin ( nextUrl ) ;
123+
124+ // Verify the redirect URL uses empty string (relative path)
125+ expect ( mockLocation . href ) . toBe (
126+ `/login?from_url=${ encodeURIComponent ( nextUrl ) } `
127+ ) ;
128+
129+ // Restore window
130+ global . window = originalWindow ;
131+ } ) ;
132+ } ) ;
133+
81134describe ( 'createClientFromRequest' , ( ) => {
82135 test ( 'should create client from request with all headers' , ( ) => {
83136 const mockRequest = {
0 commit comments