@@ -12,9 +12,8 @@ import {
1212 LocationType ,
1313 Region ,
1414} from "../src/types" ;
15- import { ApiRequestProps } from '../src/types/stack.types' ;
16- import { dispatchPostRobotRequest } from '../src/utils/adapter' ;
17- import { onData , onError } from '../src/utils/utils' ;
15+ import { RequestOption } from '../src/types/common.types' ;
16+ import { ApiRequestParams } from '../src/types/api.type' ;
1817
1918jest . mock ( "post-robot" ) ;
2019jest . mock ( "wolfy87-eventemitter" ) ;
@@ -136,41 +135,35 @@ describe("UI Location", () => {
136135
137136 describe ( 'dispatchPostRobotRequest' , ( ) => {
138137 let mockPostRobot : typeof postRobot ;
139- let opts : ApiRequestProps ;
138+ let opts : RequestOption ;
140139 let uiLocationInstance : UiLocation ;
141140 let onError : jest . Mock ;
142141
143142 beforeEach ( ( ) => {
144143 mockPostRobot = postRobot ;
145- opts = { method : 'GET' , url : '/test' } ;
144+ opts = { method : 'GET' } ;
146145 uiLocationInstance = new UiLocation ( initData ) ;
147146 onError = jest . fn ( ) ;
148147 uiLocationInstance . api = jest . fn ( ) . mockResolvedValue ( {
149148 method : 'GET' ,
150- url : '/test?limit=10&skip=0' ,
151- body : { }
149+ url : "https://test.com/test?limit=10&skip=0"
152150 } ) ;
153151 } ) ;
154152
155153 it ( 'should call sendToParent with the correct arguments and resolve with data' , async ( ) => {
156154 const mockData = { success : true } ;
157155 // Call the method that uses uiLocationInstance.api
158- const result = await uiLocationInstance . api ( {
159- method : 'GET' ,
160- url : '/test?limit=10&skip=0' ,
161- body : { }
156+ const result = await uiLocationInstance . api ( "https://test.com/test?limit=10&skip=0" , {
157+ method : 'GET'
162158 } ) ;
163159
164160 // Assertions
165- expect ( uiLocationInstance . api ) . toHaveBeenCalledWith ( {
166- method : 'GET' ,
167- url : '/test?limit=10&skip=0' ,
168- body : { }
161+ expect ( uiLocationInstance . api ) . toHaveBeenCalledWith ( 'https://test.com/test?limit=10&skip=0' , {
162+ method : 'GET'
169163 } ) ;
170164 expect ( result ) . toEqual ( {
171165 method : 'GET' ,
172- url : '/test?limit=10&skip=0' ,
173- body : { }
166+ url : 'https://test.com/test?limit=10&skip=0' ,
174167 } ) ;
175168
176169 } ) ;
@@ -187,28 +180,27 @@ describe("UI Location", () => {
187180 } ) ;
188181
189182 // Call the method that uses uiLocationInstance.api and expect it to throw an error
190- await expect ( uiLocationInstance . api ( {
191- method : 'GET' ,
192- url : '/test?limit=10&skip=0' ,
193- body : { }
183+ await expect ( uiLocationInstance . api ( "https://test.com/test?limit=10&skip=0" , {
184+ method : 'GET'
194185 } ) ) . rejects . toThrow ( 'Test error' ) ;
195186 } ) ;
196187 } ) ;
197188
198189
199190 describe ( "createSDKAdapter" , ( ) => {
200191 let mockPostRobot : typeof postRobot ;
201- let opts : ApiRequestProps ;
192+ let opts : ApiRequestParams ;
202193 let uiLocationInstance : UiLocation ;
203194 let onError : jest . Mock ;
204195 beforeEach ( ( ) => {
205196 mockPostRobot = postRobot ;
206- opts = { method : 'GET' , url : ' /test' } ;
197+ opts = { method : 'GET' , baseURL : "https://test.com" , url : " /test?limit10&skip=0" } ;
207198 uiLocationInstance = new UiLocation ( initData ) ;
208199 onError = jest . fn ( ) ;
209200 uiLocationInstance . createAdapter = jest . fn ( ) . mockResolvedValue ( {
210201 method : 'GET' ,
211202 url : '/test?limit=10&skip=0' ,
203+ baseURL : 'https://test.com' ,
212204 data : { }
213205 } ) ;
214206 } ) ;
@@ -228,18 +220,21 @@ describe("UI Location", () => {
228220 const result = await uiLocationInstance . createAdapter ( {
229221 method : 'GET' ,
230222 url : '/test?limit=10&skip=0' ,
223+ baseURL : 'https://test.com' ,
231224 data : { }
232225 } ) ;
233226
234227 // Assertions
235228 expect ( uiLocationInstance . createAdapter ) . toHaveBeenCalledWith ( {
236229 method : 'GET' ,
237230 url : '/test?limit=10&skip=0' ,
231+ baseURL : 'https://test.com' ,
238232 data : { }
239233 } ) ;
240234 expect ( result ) . toEqual ( {
241235 method : 'GET' ,
242236 url : '/test?limit=10&skip=0' ,
237+ baseURL : 'https://test.com' ,
243238 data : { }
244239 } ) ;
245240 } )
@@ -259,6 +254,7 @@ describe("UI Location", () => {
259254 await expect ( uiLocationInstance . createAdapter ( {
260255 method : 'GET' ,
261256 url : '/test?limit=10&skip=0' ,
257+ baseURL : 'https://test.com' ,
262258 data : { }
263259 } ) ) . rejects . toThrow ( 'Test error' ) ;
264260 } )
0 commit comments