@@ -124,6 +124,75 @@ describe('mock server auth tests', () => {
124124 await conn . login ( ) . then ( ( key ) => expect ( key ) . toEqual ( apiKey ) ) ;
125125 } ) ;
126126
127+ it ( 'should construct the correct url when host contains scheme' , ( ) => {
128+ const apiKey = 'abcd123' ;
129+
130+ const conn = new Connection ( {
131+ scheme : 'http' ,
132+ host : 'http://localhost:' + server . port ,
133+ apiKey : new ApiKey ( apiKey ) ,
134+ } ) ;
135+ const expectedPath = 'http://localhost:' + server . port ;
136+
137+ expect ( conn . host ) . toEqual ( expectedPath ) ;
138+ } ) ;
139+
140+ it ( 'should construct the correct url when scheme specified and host does not contain scheme' , ( ) => {
141+ const apiKey = 'abcd123' ;
142+
143+ const conn = new Connection ( {
144+ scheme : 'http' ,
145+ host : 'localhost:' + server . port ,
146+ apiKey : new ApiKey ( apiKey ) ,
147+ } ) ;
148+ const expectedPath = 'http://localhost:' + server . port ;
149+
150+ expect ( conn . host ) . toEqual ( expectedPath ) ;
151+ } ) ;
152+
153+ it ( 'should construct the correct url when no scheme is specified but host contains scheme' , ( ) => {
154+ const apiKey = 'abcd123' ;
155+
156+ const conn = new Connection ( {
157+ host : 'http://localhost:' + server . port ,
158+ apiKey : new ApiKey ( apiKey ) ,
159+ } ) ;
160+ const expectedPath = 'http://localhost:' + server . port ;
161+
162+ expect ( conn . host ) . toEqual ( expectedPath ) ;
163+ } ) ;
164+
165+ it ( 'should throw error when host contains different scheme than specified' , ( ) => {
166+ const apiKey = 'abcd123' ;
167+
168+ const createConnection = ( ) => {
169+ return new Connection ( {
170+ scheme : 'https' ,
171+ host : 'http://localhost:' + server . port ,
172+ apiKey : new ApiKey ( apiKey ) ,
173+ } ) ;
174+ } ;
175+
176+ expect ( createConnection ) . toThrow (
177+ 'The host contains a different protocol than specified in the scheme (scheme: https != host: http)'
178+ ) ;
179+ } ) ;
180+
181+ it ( 'should throw error when scheme not specified and included in host' , ( ) => {
182+ const apiKey = 'abcd123' ;
183+
184+ const createConnection = ( ) => {
185+ return new Connection ( {
186+ host : 'localhost:' + server . port ,
187+ apiKey : new ApiKey ( apiKey ) ,
188+ } ) ;
189+ } ;
190+
191+ expect ( createConnection ) . toThrow (
192+ 'The host must start with a recognized protocol (e.g., http or https) if no scheme is provided.'
193+ ) ;
194+ } ) ;
195+
127196 it ( 'shuts down the server' , ( ) => {
128197 return server . close ( ) ;
129198 } ) ;
0 commit comments