11import { describe , it , expect , vi , beforeEach } from 'vitest' ;
22import { EQP } from '../index' ;
3+ import { FetchAdapter } from '../FetchAdapter' ;
34import { FileService } from '../services/FileService' ;
45import { UserService } from '../services/UserService' ;
56import { KeyService } from '../services/KeyService' ;
67import { CallbackService } from '../services/CallbackService' ;
78import { ReportService } from '../services/ReportService' ;
89import { PackageService } from '../services/PackageService' ;
910
10- // Mock global fetch to prevent real requests during EQP construction
11- vi . stubGlobal ( 'fetch' , vi . fn ( ) ) ;
11+ vi . mock ( '../FetchAdapter' , ( ) => ( {
12+ FetchAdapter : vi . fn ( )
13+ } ) ) ;
1214
1315describe ( 'EQP' , ( ) => {
1416 const defaultOptions = {
1517 appId : 'test-app-id' ,
1618 appSecret : 'test-app-secret'
1719 } ;
1820
21+ beforeEach ( ( ) => {
22+ vi . clearAllMocks ( ) ;
23+ } ) ;
24+
1925 describe ( 'environment URLs' , ( ) => {
2026 it ( 'should use production URL by default' , ( ) => {
21- const eqp = new EQP ( defaultOptions ) ;
27+ new EQP ( defaultOptions ) ;
2228
23- expect ( eqp ) . toBeDefined ( ) ;
29+ expect ( FetchAdapter ) . toHaveBeenCalledWith ( 'https://commercedeveloper-api.adobe.com/rest/v1' ) ;
2430 } ) ;
2531
2632 it ( 'should use production URL when environment is "production"' , ( ) => {
27- const eqp = new EQP ( { ...defaultOptions , environment : 'production' } ) ;
33+ new EQP ( { ...defaultOptions , environment : 'production' } ) ;
2834
29- expect ( eqp ) . toBeDefined ( ) ;
35+ expect ( FetchAdapter ) . toHaveBeenCalledWith ( 'https://commercedeveloper-api.adobe.com/rest/v1' ) ;
3036 } ) ;
3137
3238 it ( 'should use sandbox URL when environment is "sandbox"' , ( ) => {
33- const eqp = new EQP ( { ...defaultOptions , environment : 'sandbox' } ) ;
39+ new EQP ( { ...defaultOptions , environment : 'sandbox' } ) ;
3440
35- expect ( eqp ) . toBeDefined ( ) ;
41+ expect ( FetchAdapter ) . toHaveBeenCalledWith ( 'https://commercedeveloper-sandbox-api.adobe.com/rest/v1' ) ;
3642 } ) ;
3743 } ) ;
3844
@@ -46,9 +52,9 @@ describe('EQP', () => {
4652 delete : vi . fn ( )
4753 } ;
4854
49- const eqp = new EQP ( { ...defaultOptions , adapter : customAdapter } ) ;
55+ new EQP ( { ...defaultOptions , adapter : customAdapter } ) ;
5056
51- expect ( eqp ) . toBeDefined ( ) ;
57+ expect ( FetchAdapter ) . not . toHaveBeenCalled ( ) ;
5258 } ) ;
5359 } ) ;
5460
0 commit comments