@@ -8,6 +8,7 @@ import * as scrapegraphai from "../src/scrapegraphai.js";
88
99const API_KEY = "test-sgai-key-abc123" ;
1010const BASE = "https://api.scrapegraphai.com/v1" ;
11+ const ROOT = "https://api.scrapegraphai.com" ;
1112
1213function json ( body : unknown , status = 200 ) : Response {
1314 return new Response ( JSON . stringify ( body ) , {
@@ -31,9 +32,9 @@ function expectPost(callIndex: number, path: string, body?: object) {
3132 if ( body ) expect ( JSON . parse ( init . body as string ) ) . toEqual ( body ) ;
3233}
3334
34- function expectGet ( callIndex : number , path : string ) {
35+ function expectGet ( callIndex : number , path : string , base = BASE ) {
3536 const [ url , init ] = fetchSpy . mock . calls [ callIndex ] as [ string , RequestInit ] ;
36- expect ( url ) . toBe ( `${ BASE } ${ path } ` ) ;
37+ expect ( url ) . toBe ( `${ base } ${ path } ` ) ;
3738 expect ( init . method ) . toBe ( "GET" ) ;
3839 expect ( ( init . headers as Record < string , string > ) [ "SGAI-APIKEY" ] ) . toBe ( API_KEY ) ;
3940}
@@ -315,7 +316,7 @@ describe("getCredits", () => {
315316
316317 expect ( res . status ) . toBe ( "success" ) ;
317318 expect ( res . data ) . toEqual ( body ) ;
318- expectGet ( 0 , "/credits" ) ;
319+ expectGet ( 0 , "/v2/ credits" , ROOT ) ;
319320 } ) ;
320321} ) ;
321322
@@ -328,8 +329,6 @@ describe("checkHealth", () => {
328329
329330 expect ( res . status ) . toBe ( "success" ) ;
330331 expect ( res . data ) . toEqual ( body ) ;
331- const [ url , init ] = fetchSpy . mock . calls [ 0 ] as [ string , RequestInit ] ;
332- expect ( url ) . toBe ( "https://api.scrapegraphai.com/healthz" ) ;
333- expect ( init . method ) . toBe ( "GET" ) ;
332+ expectGet ( 0 , "/healthz" , ROOT ) ;
334333 } ) ;
335334} ) ;
0 commit comments