1- import { http , HttpResponse } from 'msw'
2- import { setupServer } from 'msw/node'
1+ import { useApi } from '.'
32import {
4- useApi ,
5- createApi ,
6- setApi ,
7- } from '.'
8- import {
9- beforeAll ,
10- afterEach ,
113 describe ,
124 it ,
135 expect ,
14- afterAll ,
156} from 'vitest'
167
17- const BASE_URL = 'http://localhost:3000'
18-
19- const server = setupServer (
20- http . get ( `${ BASE_URL } /api/ping` , ( ) => {
21- return HttpResponse . json ( { message : 'Pong' } )
22- } ) ,
23- )
24-
25- beforeAll ( ( ) => {
26- server . listen ( )
27-
28- setApi ( createApi ( { baseURL : BASE_URL } ) )
29- } )
30-
31- afterEach ( ( ) => {
32- server . resetHandlers ( )
33- } )
34-
35- afterAll ( ( ) => {
36- server . close ( )
37- } )
38-
398describe ( 'DedupeAdapter' , ( ) => {
40- it ( 'should cancel previous request with same requestId ' , async ( ) => {
9+ it ( 'should cancel previous request with same requestKey ' , async ( ) => {
4110 const api = useApi ( )
42- const a = api . get ( '/api/ping' , { requestId : 'ping' } )
43- const b = api . get ( '/api/ping' , { requestId : 'ping' } )
11+ const a = api . get ( '/api/ping' , { requestKey : 'ping' } )
12+ const b = api . get ( '/api/ping' , { requestKey : 'ping' } )
4413 const result = await Promise . allSettled ( [ a , b ] )
4514
4615 expect ( result [ 0 ] . status ) . toBe ( 'rejected' )
4716 expect ( result [ 1 ] . status ) . toBe ( 'fulfilled' )
4817 } )
4918
50- it ( 'should do nothing if requestId is different' , async ( ) => {
19+ it ( 'should do nothing if requestKey is different' , async ( ) => {
5120 const api = useApi ( )
52- const a = api . get ( '/api/ping' , { requestId : 'ping/a' } )
53- const b = api . get ( '/api/ping' , { requestId : 'ping/b' } )
21+ const a = api . get ( '/api/ping' , { requestKey : 'ping/a' } )
22+ const b = api . get ( '/api/ping' , { requestKey : 'ping/b' } )
5423 const result = await Promise . allSettled ( [ a , b ] )
5524
5625 expect ( result [ 0 ] . status ) . toBe ( 'fulfilled' )
@@ -62,8 +31,8 @@ describe('DedupeAdapter', () => {
6231 const controller = new AbortController ( )
6332 const signal = controller . signal
6433
65- const a = api . get ( '/api/ping' , { requestId : 'ping/d' , signal } )
66- const b = api . get ( '/api/ping' , { requestId : 'ping/e' } )
34+ const a = api . get ( '/api/ping' , { requestKey : 'ping/d' , signal } )
35+ const b = api . get ( '/api/ping' , { requestKey : 'ping/e' } )
6736
6837 controller . abort ( )
6938
@@ -75,10 +44,10 @@ describe('DedupeAdapter', () => {
7544} )
7645
7746describe ( 'cancel' , ( ) => {
78- it ( 'should be cancel request only specific requestId ' , async ( ) => {
47+ it ( 'should be cancel request only specific requestKey ' , async ( ) => {
7948 const api = useApi ( )
80- const a = api . get ( '/api/ping' , { requestId : 'ping/i' } )
81- const b = api . get ( '/api/ping' , { requestId : 'ping/j' } )
49+ const a = api . get ( '/api/ping' , { requestKey : 'ping/i' } )
50+ const b = api . get ( '/api/ping' , { requestKey : 'ping/j' } )
8251
8352 api . cancel ( 'ping/i' )
8453
@@ -92,8 +61,8 @@ describe('cancel', () => {
9261describe ( 'cancelAll' , ( ) => {
9362 it ( 'should be cancel all active request' , async ( ) => {
9463 const api = useApi ( )
95- const a = api . get ( '/api/ping' , { requestId : 'ping/x' } )
96- const b = api . get ( '/api/ping' , { requestId : 'ping/y' } )
64+ const a = api . get ( '/api/ping' , { requestKey : 'ping/x' } )
65+ const b = api . get ( '/api/ping' , { requestKey : 'ping/y' } )
9766
9867 api . cancelAll ( )
9968
0 commit comments