@@ -6,7 +6,7 @@ import type { ValidatorType } from '../core/Validator'
66import Validator from '../core/Validator'
77import { merge } from '../util'
88
9- let proxy : PostService
9+ let service : PostService
1010let mockAdapter : MockAdapter
1111let validator : ValidatorType
1212
@@ -16,15 +16,15 @@ describe('BaseService', () => {
1616 const axios = Axios . create ( { baseURL : 'https://mock-api.test' } )
1717 BaseService . $http = axios
1818 BaseService . $errorProperty = 'message'
19- proxy = new PostService ( )
19+ service = new PostService ( )
2020 mockAdapter = new MockAdapter ( axios )
2121 mockAdapter . reset ( )
2222 } )
2323
2424 it ( 'check if http was installed' , async ( ) => {
2525 BaseService . $http = undefined as any
2626 try {
27- await proxy . all ( )
27+ await service . all ( )
2828 } catch ( e ) {
2929 const { message } = e as any
3030 expect ( message ) . toBe ( 'Vue Axios Http, No http library provided.' )
@@ -37,7 +37,7 @@ describe('BaseService', () => {
3737 pagination : { count : 1 , page : 1 , perPage : 20 } ,
3838 }
3939 mockAdapter . onGet ( '/posts' ) . reply ( 200 , items )
40- const { data, pagination } = await proxy . removeParameters ( ) . all ( )
40+ const { data, pagination } = await service . removeParameters ( ) . all ( )
4141 const all = {
4242 pagination,
4343 items : data ,
@@ -56,7 +56,7 @@ describe('BaseService', () => {
5656 } ,
5757 }
5858 mockAdapter . onGet ( '/posts' ) . reply ( 200 , items )
59- const { data, meta } = await proxy . removeParameters ( ) . all ( )
59+ const { data, meta } = await service . removeParameters ( ) . all ( )
6060 const item = {
6161 items : data ,
6262 pagination : meta . pagination ,
@@ -69,14 +69,14 @@ describe('BaseService', () => {
6969 it ( 'will fetch all records' , async ( ) => {
7070 const items = [ { first_name : 'Chantouch' , last_name : 'Sek' } ]
7171 mockAdapter . onGet ( '/posts' ) . reply ( 200 , { data : items } )
72- const { data } = await proxy . removeParameters ( ) . all ( )
72+ const { data } = await service . removeParameters ( ) . all ( )
7373 expect ( data ) . toEqual ( items )
7474 } )
7575
7676 it ( 'Check network server return 500' , async ( ) => {
7777 mockAdapter . onGet ( '/posts' ) . networkError ( )
7878 try {
79- await proxy . all ( )
79+ await service . all ( )
8080 } catch ( e ) {
8181 const { message } = e as any
8282 expect ( message ) . toBe ( 'Network Error' )
@@ -89,7 +89,7 @@ describe('BaseService', () => {
8989 { first_name : 'Chantouch' , last_name : 'Sek' , id : 2 } ,
9090 ]
9191 mockAdapter . onGet ( '/posts?id=1&first_name=Dara' ) . reply ( 200 , { data : items } )
92- const { data } = await proxy
92+ const { data } = await service
9393 . setParameter ( 'id' , 1 )
9494 . setParameters ( { first_name : 'Dara' } )
9595 . all ( )
@@ -113,11 +113,11 @@ describe('BaseService', () => {
113113 mockAdapter
114114 . onGet ( '/posts?id=1&last_name=Hok&search[name]=hello&first_name=Dara' )
115115 . reply ( 200 , { data : items } )
116- const { data } = await proxy
116+ const { data } = await service
117117 . setParameter ( 'id=1&last_name=Hok&search[name]=hello' )
118118 . setParameters ( { first_name : 'Dara' } )
119119 . all ( )
120- expect ( proxy . parameters ) . toEqual ( {
120+ expect ( service . parameters ) . toEqual ( {
121121 id : '1' ,
122122 first_name : 'Dara' ,
123123 last_name : 'Hok' ,
@@ -134,7 +134,7 @@ describe('BaseService', () => {
134134 { first_name : 'Chantouch' , last_name : 'Sek' , id : 2 } ,
135135 ]
136136 mockAdapter . onGet ( '/posts?id=1' ) . reply ( 200 , { data : items } )
137- const { data } = await proxy
137+ const { data } = await service
138138 . setParameter ( 'id' , 1 )
139139 . setParameters ( { first_name : 'Dara' , last_name : 'Sek' } )
140140 . removeParameter ( 'first_name' )
@@ -156,25 +156,28 @@ describe('BaseService', () => {
156156 first_name : 'Dara' ,
157157 last_name : 'Hok' ,
158158 }
159- const { data } = await proxy
159+ const { data } = await service
160160 . setParameters ( params )
161161 . removeParameters ( [ 'last_name' ] )
162162 . all ( )
163163 expect ( data ) . toEqual ( items )
164- expect ( proxy . parameters ) . toEqual ( { search : { id : 1 } , first_name : 'Dara' } )
164+ expect ( service . parameters ) . toEqual ( {
165+ search : { id : 1 } ,
166+ first_name : 'Dara' ,
167+ } )
165168 } )
166169
167170 it ( 'it should find an item by id' , async ( ) => {
168171 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
169172 mockAdapter . onGet ( 'posts/1' ) . reply ( 200 , { data : item } )
170- const { data } = await proxy . find ( 1 )
173+ const { data } = await service . find ( 1 )
171174 expect ( data ) . toEqual ( item )
172175 } )
173176
174177 it ( 'it should create a item by post' , async ( ) => {
175178 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
176179 mockAdapter . onPost ( '/posts' ) . reply ( 201 , { data : item } )
177- const { data } = await proxy . post ( item )
180+ const { data } = await service . post ( item )
178181 expect ( data ) . toEqual ( item )
179182 } )
180183
@@ -209,7 +212,7 @@ describe('BaseService', () => {
209212 return [ 200 , { } ]
210213 } )
211214
212- await proxy . store ( form )
215+ await service . store ( form )
213216 } )
214217
215218 it ( 'transforms the data to a FormData object if there is a File with post' , async ( ) => {
@@ -241,7 +244,7 @@ describe('BaseService', () => {
241244 return [ 200 , { } ]
242245 } )
243246
244- await proxy . put ( form . id , form )
247+ await service . put ( form . id , form )
245248 } )
246249
247250 it ( 'transforms the boolean values in FormData object to "1" or "0"' , async ( ) => {
@@ -272,7 +275,7 @@ describe('BaseService', () => {
272275 return [ 200 , { } ]
273276 } )
274277
275- await proxy . post ( form )
278+ await service . post ( form )
276279 } )
277280
278281 it ( 'it should throw errors message when data is not valid' , async ( ) => {
@@ -281,7 +284,7 @@ describe('BaseService', () => {
281284 message : { first_name : 'The first name field is required' } ,
282285 } )
283286 try {
284- await proxy . post ( item )
287+ await service . post ( item )
285288 } catch ( e ) {
286289 const { message } = e as any
287290 expect ( message ) . toBe ( 'Request failed with status code 422' )
@@ -292,65 +295,65 @@ describe('BaseService', () => {
292295 it ( 'it should store the item' , async ( ) => {
293296 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
294297 mockAdapter . onPost ( '/posts' ) . reply ( 201 , { data : item } )
295- const { data } = await proxy . store ( item )
298+ const { data } = await service . store ( item )
296299 expect ( data ) . toEqual ( item )
297300 } )
298301
299302 it ( 'it should be able to put item' , async ( ) => {
300303 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
301304 mockAdapter . onPut ( 'posts/1' ) . reply ( 200 , { data : item } )
302- const { data } = await proxy . put ( item . id , item )
305+ const { data } = await service . put ( item . id , item )
303306 expect ( data ) . toEqual ( item )
304307 } )
305308
306309 it ( 'it should be able to put item without id parameter' , async ( ) => {
307310 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
308311 mockAdapter . onPut ( 'posts' ) . reply ( 200 , { data : item } )
309- const { data } = await proxy . put ( item )
312+ const { data } = await service . put ( item )
310313 expect ( data ) . toEqual ( item )
311314 } )
312315
313316 it ( 'it should be able to patch item' , async ( ) => {
314317 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
315318 mockAdapter . onPatch ( 'posts/1' ) . reply ( 200 , { data : item } )
316- const { data } = await proxy . patch ( item . id , item )
319+ const { data } = await service . patch ( item . id , item )
317320 expect ( data ) . toEqual ( item )
318321 } )
319322
320323 it ( 'it should be able to patch item without id' , async ( ) => {
321324 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
322325 mockAdapter . onPatch ( 'posts' ) . reply ( 200 , { data : item } )
323- const { data } = await proxy . patch ( item )
326+ const { data } = await service . patch ( item )
324327 expect ( data ) . toEqual ( item )
325328 } )
326329
327330 it ( 'it should be able to update an item' , async ( ) => {
328331 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
329332 mockAdapter . onPatch ( 'posts/1' ) . reply ( 200 , { data : item } )
330- const { data } = await proxy . update ( item . id , item )
333+ const { data } = await service . update ( item . id , item )
331334 expect ( data ) . toEqual ( item )
332335 } )
333336
334337 it ( 'it should be able to delete an item' , async ( ) => {
335338 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
336339 mockAdapter . onDelete ( 'posts/1' ) . reply ( 200 , { data : item } )
337- const { data } = await proxy . delete ( item . id )
340+ const { data } = await service . delete ( item . id )
338341 expect ( data ) . toEqual ( item )
339342 } )
340343
341344 it ( 'it should be able to remove an item' , async ( ) => {
342345 const item = { first_name : 'Chantouch' , last_name : 'Sek' , id : 1 }
343346 mockAdapter . onDelete ( 'posts/1' ) . reply ( 200 , { data : item } )
344- const { data } = await proxy . remove ( item . id )
347+ const { data } = await service . remove ( item . id )
345348 expect ( data ) . toEqual ( item )
346349 } )
347350
348351 it ( 'can accept a custom http instance in options' , ( ) => {
349352 BaseService . $http = Axios . create ( { baseURL : 'https://another-example.com' } )
350- expect ( proxy . $http . defaults . baseURL ) . toBe ( 'https://another-example.com' )
353+ expect ( service . $http . defaults . baseURL ) . toBe ( 'https://another-example.com' )
351354
352355 BaseService . $http = Axios . create ( )
353- expect ( proxy . $http . defaults . baseURL ) . toBe ( undefined )
356+ expect ( service . $http . defaults . baseURL ) . toBe ( undefined )
354357 } )
355358} )
356359
0 commit comments