2018-10-16 08:50:07 +00:00
|
|
|
/*
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
2018-10-24 14:25:42 +00:00
|
|
|
import { dispatch } from '@wordpress/data';
|
2018-10-16 08:50:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import resolvers from '../resolvers';
|
|
|
|
|
|
|
|
const { getOrders } = resolvers;
|
|
|
|
|
2018-10-24 14:25:42 +00:00
|
|
|
jest.mock( '@wordpress/data', () => ( {
|
|
|
|
dispatch: jest.fn().mockReturnValue( {
|
|
|
|
setOrders: jest.fn(),
|
|
|
|
} ),
|
|
|
|
} ) );
|
2018-10-16 08:50:07 +00:00
|
|
|
jest.mock( '@wordpress/api-fetch', () => jest.fn() );
|
|
|
|
|
|
|
|
describe( 'getOrders', () => {
|
|
|
|
const ORDERS_1 = [ { id: 1214 }, { id: 1215 }, { id: 1216 } ];
|
|
|
|
|
|
|
|
const ORDERS_2 = [ { id: 1 }, { id: 2 }, { id: 3 } ];
|
|
|
|
|
|
|
|
beforeAll( () => {
|
|
|
|
apiFetch.mockImplementation( options => {
|
|
|
|
if ( options.path === '/wc/v3/orders' ) {
|
|
|
|
return Promise.resolve( ORDERS_1 );
|
|
|
|
}
|
2018-10-24 14:25:42 +00:00
|
|
|
if ( options.path === '/wc/v3/orders?orderby=id' ) {
|
2018-10-16 08:50:07 +00:00
|
|
|
return Promise.resolve( ORDERS_2 );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns requested report data', async () => {
|
2018-10-24 14:25:42 +00:00
|
|
|
expect.assertions( 1 );
|
2018-11-05 23:30:32 +00:00
|
|
|
await getOrders();
|
2018-10-24 14:25:42 +00:00
|
|
|
expect( dispatch().setOrders ).toHaveBeenCalledWith( ORDERS_1, undefined );
|
2018-10-16 08:50:07 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns requested report data for a specific query', async () => {
|
2018-10-24 14:25:42 +00:00
|
|
|
expect.assertions( 1 );
|
2018-11-05 23:30:32 +00:00
|
|
|
await getOrders( { orderby: 'id' } );
|
2018-10-24 14:25:42 +00:00
|
|
|
expect( dispatch().setOrders ).toHaveBeenCalledWith( ORDERS_2, { orderby: 'id' } );
|
2018-10-16 08:50:07 +00:00
|
|
|
} );
|
|
|
|
} );
|