@@ -37,4 +37,68 @@ describe('Request tests', () => {
3737 } ;
3838 await expect ( getData ( client , url , { } ) ) . rejects . toThrowError ( 'Host is required for live preview' ) ;
3939 } ) ;
40+
41+ it ( 'should handle live_preview with enable=true and live_preview=init' , async ( ) => {
42+ const client = httpClient ( { } ) ;
43+ const mock = new MockAdapter ( client as any ) ;
44+ const url = '/your-api-endpoint' ;
45+ const mockResponse = { data : 'mocked' } ;
46+
47+ client . stackConfig = {
48+ live_preview : {
49+ enable : true ,
50+ preview_token : 'someToken' ,
51+ live_preview : 'init' ,
52+ } ,
53+ } ;
54+
55+ mock . onGet ( url ) . reply ( 200 , mockResponse ) ;
56+
57+ const result = await getData ( client , url , { } ) ;
58+ expect ( result ) . toEqual ( mockResponse ) ;
59+ } ) ;
60+
61+ it ( 'should set baseURL correctly when host is provided without https://' , async ( ) => {
62+ const client = httpClient ( { } ) ;
63+ const mock = new MockAdapter ( client as any ) ;
64+ const url = '/your-api-endpoint' ;
65+ const mockResponse = { data : 'mocked' } ;
66+
67+ client . stackConfig = {
68+ live_preview : {
69+ enable : true ,
70+ preview_token : 'someToken' ,
71+ live_preview : 'someHash' ,
72+ host : 'example.com' ,
73+ } ,
74+ } ;
75+
76+ mock . onGet ( url ) . reply ( 200 , mockResponse ) ;
77+
78+ const result = await getData ( client , url , { } ) ;
79+ expect ( client . defaults . baseURL ) . toBe ( 'https://example.com' ) ;
80+ expect ( result ) . toEqual ( mockResponse ) ;
81+ } ) ;
82+
83+ it ( 'should not modify baseURL when host is already prefixed with https://' , async ( ) => {
84+ const client = httpClient ( { } ) ;
85+ const mock = new MockAdapter ( client as any ) ;
86+ const url = '/your-api-endpoint' ;
87+ const mockResponse = { data : 'mocked' } ;
88+
89+ client . stackConfig = {
90+ live_preview : {
91+ enable : true ,
92+ preview_token : 'someToken' ,
93+ live_preview : 'someHash' ,
94+ host : 'https://example.com' ,
95+ } ,
96+ } ;
97+
98+ mock . onGet ( url ) . reply ( 200 , mockResponse ) ;
99+
100+ const result = await getData ( client , url , { } ) ;
101+ expect ( client . stackConfig . live_preview . host ) . toBe ( 'https://example.com' ) ;
102+ expect ( result ) . toEqual ( mockResponse ) ;
103+ } ) ;
40104} ) ;
0 commit comments