@@ -59,46 +59,56 @@ describe('Request tests', () => {
5959 } ) ;
6060
6161 it ( 'should set baseURL correctly when host is provided without https://' , async ( ) => {
62- const client = httpClient ( { } ) ;
62+ const client = httpClient ( {
63+ defaultHostname : 'example.com' ,
64+ } ) ;
6365 const mock = new MockAdapter ( client as any ) ;
6466 const url = '/your-api-endpoint' ;
67+ const livePreviewURL = 'https://rest-preview.com' + url ;
6568 const mockResponse = { data : 'mocked' } ;
6669
6770 client . stackConfig = {
6871 live_preview : {
6972 enable : true ,
7073 preview_token : 'someToken' ,
7174 live_preview : 'someHash' ,
72- host : 'example .com' ,
75+ host : 'rest-preview .com' ,
7376 } ,
7477 } ;
7578
76- mock . onGet ( url ) . reply ( 200 , mockResponse ) ;
79+ mock . onGet ( livePreviewURL ) . reply ( 200 , mockResponse ) ;
7780
7881 const result = await getData ( client , url , { } ) ;
79- expect ( client . defaults . baseURL ) . toBe ( 'https://example.com' ) ;
82+ expect ( client . defaults . baseURL ) . toBe ( 'https://example.com:443/v3' ) ;
83+ expect ( client . stackConfig . live_preview . host ) . toBe ( 'rest-preview.com' ) ;
84+ expect ( mock . history . get [ 0 ] . url ) . toBe ( livePreviewURL ) ;
8085 expect ( result ) . toEqual ( mockResponse ) ;
8186 } ) ;
8287
8388 it ( 'should not modify baseURL when host is already prefixed with https://' , async ( ) => {
84- const client = httpClient ( { } ) ;
89+ const client = httpClient ( {
90+ defaultHostname : 'example.com' ,
91+ } ) ;
8592 const mock = new MockAdapter ( client as any ) ;
8693 const url = '/your-api-endpoint' ;
94+ const livePreviewURL = 'https://rest-preview.com' + url ;
8795 const mockResponse = { data : 'mocked' } ;
8896
8997 client . stackConfig = {
9098 live_preview : {
9199 enable : true ,
92100 preview_token : 'someToken' ,
93101 live_preview : 'someHash' ,
94- host : 'https://example .com' ,
102+ host : 'https://rest-preview .com' ,
95103 } ,
96104 } ;
97105
98- mock . onGet ( url ) . reply ( 200 , mockResponse ) ;
106+ mock . onGet ( livePreviewURL ) . reply ( 200 , mockResponse ) ;
99107
100108 const result = await getData ( client , url , { } ) ;
101- expect ( client . stackConfig . live_preview . host ) . toBe ( 'https://example.com' ) ;
109+ expect ( client . defaults . baseURL ) . toBe ( 'https://example.com:443/v3' ) ;
110+ expect ( client . stackConfig . live_preview . host ) . toBe ( 'https://rest-preview.com' ) ;
111+ expect ( mock . history . get [ 0 ] . url ) . toBe ( livePreviewURL ) ;
102112 expect ( result ) . toEqual ( mockResponse ) ;
103113 } ) ;
104114} ) ;
0 commit comments