@@ -61,4 +61,172 @@ describe('Feature - Request - Base', () => {
61
61
62
62
expect ( store . state . entities ) . toEqual ( expected )
63
63
} )
64
+
65
+ it ( '`post` can perform a post request' , async ( ) => {
66
+ mock . onPost ( '/api/users' ) . reply ( 200 , [
67
+ { id : 1 , name : 'John Doe' } ,
68
+ { id : 2 , name : 'Jane Doe' }
69
+ ] )
70
+
71
+ const store = createStore ( [ User ] )
72
+
73
+ await User . api ( ) . post ( '/api/users' )
74
+
75
+ const expected = createState ( {
76
+ users : {
77
+ 1 : { $id : 1 , id : 1 , name : 'John Doe' } ,
78
+ 2 : { $id : 2 , id : 2 , name : 'Jane Doe' }
79
+ }
80
+ } )
81
+
82
+ expect ( store . state . entities ) . toEqual ( expected )
83
+ } )
84
+
85
+ it ( '`post` can perform a post request with additional config' , async ( ) => {
86
+ mock . onPost ( '/api/users' ) . reply ( 200 , {
87
+ data : [
88
+ { id : 1 , name : 'John Doe' } ,
89
+ { id : 2 , name : 'Jane Doe' }
90
+ ]
91
+ } )
92
+
93
+ const store = createStore ( [ User ] )
94
+
95
+ await User . api ( ) . post ( '/api/users' , { } , { dataKey : 'data' } )
96
+
97
+ const expected = createState ( {
98
+ users : {
99
+ 1 : { $id : 1 , id : 1 , name : 'John Doe' } ,
100
+ 2 : { $id : 2 , id : 2 , name : 'Jane Doe' }
101
+ }
102
+ } )
103
+
104
+ expect ( store . state . entities ) . toEqual ( expected )
105
+ } )
106
+
107
+ it ( '`put` can perform a put request' , async ( ) => {
108
+ mock . onPut ( '/api/users' ) . reply ( 200 , [
109
+ { id : 1 , name : 'John Doe' } ,
110
+ { id : 2 , name : 'Jane Doe' }
111
+ ] )
112
+
113
+ const store = createStore ( [ User ] )
114
+
115
+ await User . api ( ) . put ( '/api/users' )
116
+
117
+ const expected = createState ( {
118
+ users : {
119
+ 1 : { $id : 1 , id : 1 , name : 'John Doe' } ,
120
+ 2 : { $id : 2 , id : 2 , name : 'Jane Doe' }
121
+ }
122
+ } )
123
+
124
+ expect ( store . state . entities ) . toEqual ( expected )
125
+ } )
126
+
127
+ it ( '`put` can perform a put request with additional config' , async ( ) => {
128
+ mock . onPut ( '/api/users' ) . reply ( 200 , {
129
+ data : [
130
+ { id : 1 , name : 'John Doe' } ,
131
+ { id : 2 , name : 'Jane Doe' }
132
+ ]
133
+ } )
134
+
135
+ const store = createStore ( [ User ] )
136
+
137
+ await User . api ( ) . put ( '/api/users' , { } , { dataKey : 'data' } )
138
+
139
+ const expected = createState ( {
140
+ users : {
141
+ 1 : { $id : 1 , id : 1 , name : 'John Doe' } ,
142
+ 2 : { $id : 2 , id : 2 , name : 'Jane Doe' }
143
+ }
144
+ } )
145
+
146
+ expect ( store . state . entities ) . toEqual ( expected )
147
+ } )
148
+
149
+ it ( '`patch` can perform a patch request' , async ( ) => {
150
+ mock . onPatch ( '/api/users' ) . reply ( 200 , [
151
+ { id : 1 , name : 'John Doe' } ,
152
+ { id : 2 , name : 'Jane Doe' }
153
+ ] )
154
+
155
+ const store = createStore ( [ User ] )
156
+
157
+ await User . api ( ) . patch ( '/api/users' )
158
+
159
+ const expected = createState ( {
160
+ users : {
161
+ 1 : { $id : 1 , id : 1 , name : 'John Doe' } ,
162
+ 2 : { $id : 2 , id : 2 , name : 'Jane Doe' }
163
+ }
164
+ } )
165
+
166
+ expect ( store . state . entities ) . toEqual ( expected )
167
+ } )
168
+
169
+ it ( '`patch` can perform a patch request with additional config' , async ( ) => {
170
+ mock . onPatch ( '/api/users' ) . reply ( 200 , {
171
+ data : [
172
+ { id : 1 , name : 'John Doe' } ,
173
+ { id : 2 , name : 'Jane Doe' }
174
+ ]
175
+ } )
176
+
177
+ const store = createStore ( [ User ] )
178
+
179
+ await User . api ( ) . patch ( '/api/users' , { } , { dataKey : 'data' } )
180
+
181
+ const expected = createState ( {
182
+ users : {
183
+ 1 : { $id : 1 , id : 1 , name : 'John Doe' } ,
184
+ 2 : { $id : 2 , id : 2 , name : 'Jane Doe' }
185
+ }
186
+ } )
187
+
188
+ expect ( store . state . entities ) . toEqual ( expected )
189
+ } )
190
+
191
+ it ( '`delete` can perform a delete request' , async ( ) => {
192
+ mock . onDelete ( '/api/users' ) . reply ( 200 , [
193
+ { id : 1 , name : 'John Doe' } ,
194
+ { id : 2 , name : 'Jane Doe' }
195
+ ] )
196
+
197
+ const store = createStore ( [ User ] )
198
+
199
+ await User . api ( ) . delete ( '/api/users' )
200
+
201
+ const expected = createState ( {
202
+ users : {
203
+ 1 : { $id : 1 , id : 1 , name : 'John Doe' } ,
204
+ 2 : { $id : 2 , id : 2 , name : 'Jane Doe' }
205
+ }
206
+ } )
207
+
208
+ expect ( store . state . entities ) . toEqual ( expected )
209
+ } )
210
+
211
+ it ( '`delete` can perform a delete request with additional config' , async ( ) => {
212
+ mock . onDelete ( '/api/users' ) . reply ( 200 , {
213
+ data : [
214
+ { id : 1 , name : 'John Doe' } ,
215
+ { id : 2 , name : 'Jane Doe' }
216
+ ]
217
+ } )
218
+
219
+ const store = createStore ( [ User ] )
220
+
221
+ await User . api ( ) . delete ( '/api/users' , { dataKey : 'data' } )
222
+
223
+ const expected = createState ( {
224
+ users : {
225
+ 1 : { $id : 1 , id : 1 , name : 'John Doe' } ,
226
+ 2 : { $id : 2 , id : 2 , name : 'Jane Doe' }
227
+ }
228
+ } )
229
+
230
+ expect ( store . state . entities ) . toEqual ( expected )
231
+ } )
64
232
} )
0 commit comments