8
8
getResponseHeaderMap ,
9
9
defaultResponseHeaders ,
10
10
} from './headers' ;
11
- import { arrayEquals } from './array' ;
12
11
import { getNormalizedUrl } from './url' ;
13
12
14
13
let global =
@@ -34,9 +33,9 @@ export class Faker {
34
33
35
34
getRequests = ( ) => Object . values ( this . requestMap ) ;
36
35
37
- getKey = ( url = '' , searchParamKeys = [ ] , method = 'GET' ) =>
36
+ getKey = ( url = '' , method = 'GET' ) =>
38
37
url && method
39
- ? [ url , ... searchParamKeys , method . toLowerCase ( ) ] . join ( '_' )
38
+ ? [ url , method . toLowerCase ( ) ] . join ( '_' )
40
39
: '' ;
41
40
42
41
makeInitialRequestMap = ( requests ) => {
@@ -51,12 +50,9 @@ export class Faker {
51
50
} ;
52
51
53
52
add = ( request ) => {
54
- const { path, searchParamKeys } = getNormalizedUrl ( request . url ) ;
55
- const key = this . getKey ( path , searchParamKeys , request . method ) ;
53
+ const key = this . getKey ( request . url , request . method ) ;
56
54
this . requestMap [ key ] = {
57
55
...request ,
58
- path,
59
- searchParamKeys,
60
56
method : request . method || 'GET' ,
61
57
status : request . status || 200 ,
62
58
delay : request . delay || 0 ,
@@ -66,8 +62,7 @@ export class Faker {
66
62
67
63
update = ( item , fieldKey , value ) => {
68
64
const { url, method } = item ;
69
- const { path, searchParamKeys } = getNormalizedUrl ( url ) ;
70
- const itemKey = this . getKey ( path , searchParamKeys , method ) ;
65
+ const itemKey = this . getKey ( url , method ) ;
71
66
72
67
if (
73
68
// eslint-disable-next-line no-prototype-builtins
@@ -80,17 +75,17 @@ export class Faker {
80
75
} ;
81
76
82
77
matchMock = ( url , method = 'GET' ) => {
83
- const { path , searchParamKeys } = getNormalizedUrl ( url ) ;
78
+ const { fullUrl } = getNormalizedUrl ( url ) ;
84
79
85
80
for ( let key in this . requestMap ) {
86
81
const { url : requestUrl , method : requestMethod } =
87
82
this . requestMap [ key ] ;
88
- const { path : requestPath , searchParamKeys : requestSearchKeys } =
83
+ const { fullUrlEscaped } =
89
84
getNormalizedUrl ( requestUrl ) ;
85
+
90
86
if (
91
- match ( requestPath ) ( path ) &&
87
+ match ( fullUrlEscaped ) ( fullUrl ) &&
92
88
method == requestMethod &&
93
- arrayEquals ( searchParamKeys , requestSearchKeys ) &&
94
89
! this . requestMap [ key ] . skip
95
90
) {
96
91
return this . requestMap [ key ] ;
0 commit comments