11import { rest } from 'msw' ;
22import { createApi } from './index' ;
3- import { server } from './mocks' ;
3+ import { server } from './mocks/server ' ;
44
55describe ( 'API integration' , ( ) => {
66 it ( 'runs the documented happy path against mocked endpoints' , async ( ) => {
@@ -21,21 +21,21 @@ describe('API integration', () => {
2121 id : '1' ,
2222 status : 'funded' ,
2323 } ) ;
24- await expect ( api . trades . deleteTrade ( '1' ) ) . resolves . toBeUndefined ( ) ;
24+ await expect ( api . trades . deleteTrade ( '1' ) ) . resolves . toEqual ( '' ) ;
2525
26- await expect ( api . events . getEvents ( 100 ) ) . resolves . toHaveLength ( 1 ) ;
27- await expect ( api . events . getEvents ( 100 , '1' ) ) . resolves . toHaveLength ( 1 ) ;
26+ await expect ( api . events . getEvents ( { limit : 100 } ) ) . resolves . toHaveLength ( 1 ) ;
27+ await expect ( api . events . getEvents ( { limit : 100 , trade_id : '1' } ) ) . resolves . toHaveLength ( 1 ) ;
2828 await expect ( api . events . getEventsByTrade ( '1' ) ) . resolves . toHaveLength ( 1 ) ;
2929 await expect ( api . events . getEvent ( '1' ) ) . resolves . toMatchObject ( { id : '1' , tradeId : '1' } ) ;
3030
3131 await expect ( api . blockchain . fundTrade ( '1' , '100' ) ) . resolves . toMatchObject ( {
32- txHash : '0xtx0001' ,
32+ txHash : expect . any ( String ) ,
3333 } ) ;
3434 await expect ( api . blockchain . completeTrade ( '1' ) ) . resolves . toMatchObject ( {
35- txHash : '0xtx0002' ,
35+ txHash : expect . any ( String ) ,
3636 } ) ;
3737 await expect ( api . blockchain . resolveDispute ( '1' , 'release_to_buyer' ) ) . resolves . toMatchObject ( {
38- txHash : '0xtx0003' ,
38+ txHash : expect . any ( String ) ,
3939 } ) ;
4040 await expect ( api . blockchain . getTransactionStatus ( '0xtx0003' ) ) . resolves . toEqual ( {
4141 status : 'confirmed' ,
@@ -48,7 +48,7 @@ describe('API integration', () => {
4848 let authorizationHeader : string | null = null ;
4949
5050 server . use (
51- rest . get ( '/api/trades' , ( req , res , ctx ) => {
51+ rest . get ( 'http://localhost:3000 /api/trades' , ( req , res , ctx ) => {
5252 authorizationHeader = req . headers . get ( 'authorization' ) ;
5353 return res ( ctx . json ( [ ] ) ) ;
5454 } )
@@ -61,13 +61,13 @@ describe('API integration', () => {
6161 } ) ;
6262
6363 it ( 'invokes registered error handlers and rethrows the original failure' , async ( ) => {
64- const api = createApi ( 'http://localhost:3000' ) ;
64+ const api = createApi ( 'http://localhost:3000' , { retryMax : 0 } ) ;
6565 const handler = jest . fn ( ) ;
6666
6767 server . use (
68- rest . get ( '/ api/trades' , ( _req , res , ctx ) =>
69- res ( ctx . status ( 500 ) , ctx . json ( { error : 'temporary outage' } ) )
70- )
68+ rest . get ( 'http://localhost:3000/ api/trades' , ( _req , res , ctx ) => {
69+ return res ( ctx . status ( 500 ) , ctx . json ( { error : 'temporary outage' } ) ) ;
70+ } )
7171 ) ;
7272
7373 api . addErrorHandler ( handler ) ;
@@ -80,11 +80,11 @@ describe('API integration', () => {
8080 } ) ;
8181
8282 it ( 'retries transient failures before returning a successful response' , async ( ) => {
83- const api = createApi ( 'http://localhost:3000' ) ;
83+ const api = createApi ( 'http://localhost:3000' , { retryDelayMs : 0 } ) ;
8484 let attempts = 0 ;
85-
85+
8686 server . use (
87- rest . get ( '/api/trades' , ( _req , res , ctx ) => {
87+ rest . get ( 'http://localhost:3000 /api/trades' , ( _req , res , ctx ) => {
8888 attempts += 1 ;
8989 if ( attempts === 1 ) {
9090 return res ( ctx . status ( 503 ) , ctx . json ( { error : 'retry me' } ) ) ;
0 commit comments