@@ -59,46 +59,56 @@ describe('Request tests', () => {
59
59
} ) ;
60
60
61
61
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
+ } ) ;
63
65
const mock = new MockAdapter ( client as any ) ;
64
66
const url = '/your-api-endpoint' ;
67
+ const livePreviewURL = 'https://rest-preview.com' + url ;
65
68
const mockResponse = { data : 'mocked' } ;
66
69
67
70
client . stackConfig = {
68
71
live_preview : {
69
72
enable : true ,
70
73
preview_token : 'someToken' ,
71
74
live_preview : 'someHash' ,
72
- host : 'example .com' ,
75
+ host : 'rest-preview .com' ,
73
76
} ,
74
77
} ;
75
78
76
- mock . onGet ( url ) . reply ( 200 , mockResponse ) ;
79
+ mock . onGet ( livePreviewURL ) . reply ( 200 , mockResponse ) ;
77
80
78
81
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 ) ;
80
85
expect ( result ) . toEqual ( mockResponse ) ;
81
86
} ) ;
82
87
83
88
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
+ } ) ;
85
92
const mock = new MockAdapter ( client as any ) ;
86
93
const url = '/your-api-endpoint' ;
94
+ const livePreviewURL = 'https://rest-preview.com' + url ;
87
95
const mockResponse = { data : 'mocked' } ;
88
96
89
97
client . stackConfig = {
90
98
live_preview : {
91
99
enable : true ,
92
100
preview_token : 'someToken' ,
93
101
live_preview : 'someHash' ,
94
- host : 'https://example .com' ,
102
+ host : 'https://rest-preview .com' ,
95
103
} ,
96
104
} ;
97
105
98
- mock . onGet ( url ) . reply ( 200 , mockResponse ) ;
106
+ mock . onGet ( livePreviewURL ) . reply ( 200 , mockResponse ) ;
99
107
100
108
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 ) ;
102
112
expect ( result ) . toEqual ( mockResponse ) ;
103
113
} ) ;
104
114
} ) ;
0 commit comments