@@ -3,10 +3,11 @@ import { apiRequest, apiRequestAuth } from './api-requests';
33
44jest . mock ( 'axios' ) ;
55
6+ const url = 'https://example.com' ;
7+ const method = 'get' ;
8+
69describe ( 'apiRequest' , ( ) => {
710 it ( 'should make a request with the correct parameters' , async ( ) => {
8- const url = 'https://example.com' ;
9- const method = 'get' ;
1011 const data = { key : 'value' } ;
1112
1213 await apiRequest ( url , method , data ) ;
@@ -19,13 +20,25 @@ describe('apiRequest', () => {
1920
2021 expect ( axios . defaults . headers . common ) . toMatchSnapshot ( ) ;
2122 } ) ;
23+
24+ it ( 'should make a request with the correct parameters and default data' , async ( ) => {
25+ const data = { } ;
26+ await apiRequest ( url , method ) ;
27+
28+ expect ( axios ) . toHaveBeenCalledWith ( {
29+ method,
30+ url,
31+ data,
32+ } ) ;
33+
34+ expect ( axios . defaults . headers . common ) . toMatchSnapshot ( ) ;
35+ } ) ;
2236} ) ;
2337
2438describe ( 'apiRequestAuth' , ( ) => {
39+ const token = 'yourAuthToken' ;
40+
2541 it ( 'should make an authenticated request with the correct parameters' , async ( ) => {
26- const url = 'https://example.com' ;
27- const method = 'get' ;
28- const token = 'yourAuthToken' ;
2942 const data = { key : 'value' } ;
3043
3144 await apiRequestAuth ( url , method , token , data ) ;
@@ -38,4 +51,18 @@ describe('apiRequestAuth', () => {
3851
3952 expect ( axios . defaults . headers . common ) . toMatchSnapshot ( ) ;
4053 } ) ;
54+
55+ it ( 'should make an authenticated request with the correct parameters and default data' , async ( ) => {
56+ const data = { } ;
57+
58+ await apiRequestAuth ( url , method , token ) ;
59+
60+ expect ( axios ) . toHaveBeenCalledWith ( {
61+ method,
62+ url,
63+ data,
64+ } ) ;
65+
66+ expect ( axios . defaults . headers . common ) . toMatchSnapshot ( ) ;
67+ } ) ;
4168} ) ;
0 commit comments