@@ -75,6 +75,44 @@ describe('Cart Api Class', () => {
7575 expect ( cart . makeRequest ) . toHaveBeenCalled ( ) ;
7676 } ) ;
7777
78+ it ( 'should pass requestOptions baseUrl to makeRequest when provided to itemAdd' , ( ) => {
79+ const baseUrl = 'https://site.com/es' ;
80+ cart . itemAdd ( { } , jest . fn ( ) , { baseUrl } ) ;
81+
82+ expect ( cart . makeRequest ) . toHaveBeenCalledWith (
83+ expect . stringContaining ( '/cart/add' ) ,
84+ 'POST' ,
85+ expect . objectContaining ( { baseUrl } ) ,
86+ true ,
87+ expect . any ( Function ) ,
88+ ) ;
89+ } ) ;
90+
91+ it ( 'should pass requestOptions baseUrl to makeRequest when provided to handleItemAdd' , ( ) => {
92+ const baseUrl = 'https://site.com/fr' ;
93+ cart . handleItemAdd ( { } , jest . fn ( ) , { baseUrl } ) ;
94+
95+ expect ( cart . makeRequest ) . toHaveBeenCalledWith (
96+ expect . stringContaining ( '/cart/add' ) ,
97+ 'POST' ,
98+ expect . objectContaining ( { baseUrl } ) ,
99+ true ,
100+ expect . any ( Function ) ,
101+ ) ;
102+ } ) ;
103+
104+ it ( 'should work without requestOptions (backward compatibility)' , ( ) => {
105+ cart . itemAdd ( { } , jest . fn ( ) ) ;
106+
107+ expect ( cart . makeRequest ) . toHaveBeenCalledWith (
108+ expect . stringContaining ( '/cart/add' ) ,
109+ 'POST' ,
110+ expect . not . objectContaining ( { baseUrl : expect . anything ( ) } ) ,
111+ true ,
112+ expect . any ( Function ) ,
113+ ) ;
114+ } ) ;
115+
78116 it ( 'should be able to call api on item remove' , ( ) => {
79117 cart . itemRemove ( 1 , jest . fn ( ) ) ;
80118
0 commit comments