1+ import  test  from  'ava' ; 
2+ import  { 
3+     GET , 
4+     HEAD , 
5+     POST , 
6+     PUT , 
7+     DELETE , 
8+     CONNECT , 
9+     OPTIONS , 
10+     TRACE , 
11+     PATCH 
12+ }  from  '../src/shortcuts' ; 
13+ 
14+ const  dummy  =  { 
15+     path : [ 'path' ,  'to' ,  'resource' ] , 
16+     query : {  param : 'value'  } , 
17+     options : {  credentials : 'include'  } , 
18+     method : 'text' 
19+ } ; 
20+ 
21+ test ( 'should set correct HTTP method' ,  t  =>  { 
22+     t . deepEqual ( GET ( dummy ) ,  { 
23+         path : [ 'path' ,  'to' ,  'resource' ] , 
24+         query : {  param : 'value'  } , 
25+         options : {  credentials : 'include' ,  method : 'GET'  } , 
26+         method : 'text' 
27+     } ,  'GET' ) ; 
28+     t . deepEqual ( HEAD ( dummy ) ,  { 
29+         path : [ 'path' ,  'to' ,  'resource' ] , 
30+         query : {  param : 'value'  } , 
31+         options : {  credentials : 'include' ,  method : 'HEAD'  } , 
32+         method : 'text' 
33+     } ,  'HEAD' ) ; 
34+     t . deepEqual ( POST ( dummy ) ,  { 
35+         path : [ 'path' ,  'to' ,  'resource' ] , 
36+         query : {  param : 'value'  } , 
37+         options : {  credentials : 'include' ,  method : 'POST'  } , 
38+         method : 'text' 
39+     } ,  'POST' ) ; 
40+     t . deepEqual ( PUT ( dummy ) ,  { 
41+         path : [ 'path' ,  'to' ,  'resource' ] , 
42+         query : {  param : 'value'  } , 
43+         options : {  credentials : 'include' ,  method : 'PUT'  } , 
44+         method : 'text' 
45+     } ,  'PUT' ) ; 
46+     t . deepEqual ( DELETE ( dummy ) ,  { 
47+         path : [ 'path' ,  'to' ,  'resource' ] , 
48+         query : {  param : 'value'  } , 
49+         options : {  credentials : 'include' ,  method : 'DELETE'  } , 
50+         method : 'text' 
51+     } ,  'DELETE' ) ; 
52+     t . deepEqual ( CONNECT ( dummy ) ,  { 
53+         path : [ 'path' ,  'to' ,  'resource' ] , 
54+         query : {  param : 'value'  } , 
55+         options : {  credentials : 'include' ,  method : 'CONNECT'  } , 
56+         method : 'text' 
57+     } ,  'CONNECT' ) ; 
58+     t . deepEqual ( OPTIONS ( dummy ) ,  { 
59+         path : [ 'path' ,  'to' ,  'resource' ] , 
60+         query : {  param : 'value'  } , 
61+         options : {  credentials : 'include' ,  method : 'OPTIONS'  } , 
62+         method : 'text' 
63+     } ,  'OPTIONS' ) ; 
64+     t . deepEqual ( TRACE ( dummy ) ,  { 
65+         path : [ 'path' ,  'to' ,  'resource' ] , 
66+         query : {  param : 'value'  } , 
67+         options : {  credentials : 'include' ,  method : 'TRACE'  } , 
68+         method : 'text' 
69+     } ,  'TRACE' ) ; 
70+     t . deepEqual ( PATCH ( dummy ) ,  { 
71+         path : [ 'path' ,  'to' ,  'resource' ] , 
72+         query : {  param : 'value'  } , 
73+         options : {  credentials : 'include' ,  method : 'PATCH'  } , 
74+         method : 'text' 
75+     } ,  'PATCH' ) ; 
76+ } ) ; 
77+ 
78+ test ( 'should add method even when nothing is passed' ,  t  =>  { 
79+     const  result  =  GET ( ) ; 
80+     t . deepEqual ( result ,  {  options : {  method : 'GET' }  } ) ; 
81+ } ) ; 
82+ 
83+ test ( 'should not take precedence over passed params' ,  t  =>  { 
84+     const  result  =  PUT ( {  options : {  method : 'POST'  }  } ) ; 
85+     t . deepEqual ( result ,  {  options : {  method : 'POST' }  } ) ; 
86+ } ) ; 
0 commit comments