2019-06-11 12:47:53 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { formatParams, getStatus } from '../utils';
|
|
|
|
|
|
|
|
describe( 'formatParams', () => {
|
|
|
|
it( 'returns empty object when skipChecked is false and period is all', () => {
|
2020-02-14 02:23:21 +00:00
|
|
|
expect( formatParams( 'YYYY-MM-DD', { label: 'all' }, false ) ).toEqual(
|
|
|
|
{}
|
|
|
|
);
|
2019-06-11 12:47:53 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns skip_existing param', () => {
|
2020-02-14 02:23:21 +00:00
|
|
|
expect( formatParams( 'YYYY-MM-DD', { label: 'all' }, true ) ).toEqual(
|
|
|
|
{
|
|
|
|
skip_existing: true,
|
|
|
|
}
|
|
|
|
);
|
2019-06-11 12:47:53 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns correct days param based on period label', () => {
|
2022-06-21 08:37:34 +00:00
|
|
|
expect( formatParams( 'YYYY-MM-DD', { label: '30' }, false ) ).toEqual(
|
|
|
|
{ days: 30 }
|
|
|
|
);
|
2019-06-11 12:47:53 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns correct days param based on period date', () => {
|
|
|
|
const date = '2018-01-01';
|
2020-02-14 02:23:21 +00:00
|
|
|
const days = Math.floor(
|
|
|
|
moment().diff( moment( date, 'YYYY-MM-DD' ), 'days', true )
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
formatParams( 'YYYY-MM-DD', { label: 'custom', date }, false )
|
|
|
|
).toEqual( { days } );
|
2019-06-11 12:47:53 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns both params', () => {
|
|
|
|
expect( formatParams( 'YYYY-MM-DD', { label: '30' }, true ) ).toEqual( {
|
|
|
|
skip_existing: true,
|
|
|
|
days: 30,
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
describe( 'getStatus', () => {
|
|
|
|
it( 'returns `initializing` when no progress numbers are defined', () => {
|
|
|
|
expect(
|
|
|
|
getStatus( {
|
|
|
|
customersTotal: 1,
|
|
|
|
inProgress: true,
|
|
|
|
ordersTotal: 1,
|
|
|
|
} )
|
|
|
|
).toEqual( 'initializing' );
|
|
|
|
} );
|
2020-09-01 13:21:31 +00:00
|
|
|
it( 'returns `initializing` when the process is "inProgress" and the cache is not clear', () => {
|
|
|
|
expect(
|
|
|
|
getStatus( {
|
|
|
|
cacheNeedsClearing: true,
|
|
|
|
customersProgress: 1,
|
|
|
|
customersTotal: 1,
|
|
|
|
inProgress: true,
|
|
|
|
ordersProgress: 1,
|
|
|
|
ordersTotal: 1,
|
|
|
|
} )
|
|
|
|
).toEqual( 'initializing' );
|
|
|
|
} );
|
2019-06-11 12:47:53 +00:00
|
|
|
|
|
|
|
it( 'returns `customers` when importing customers', () => {
|
|
|
|
expect(
|
|
|
|
getStatus( {
|
|
|
|
customersProgress: 0,
|
|
|
|
customersTotal: 1,
|
|
|
|
inProgress: true,
|
|
|
|
ordersProgress: 0,
|
|
|
|
ordersTotal: 1,
|
|
|
|
} )
|
|
|
|
).toEqual( 'customers' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns `orders` when importing orders', () => {
|
|
|
|
expect(
|
|
|
|
getStatus( {
|
|
|
|
customersProgress: 1,
|
|
|
|
customersTotal: 1,
|
|
|
|
inProgress: true,
|
|
|
|
ordersProgress: 0,
|
|
|
|
ordersTotal: 1,
|
|
|
|
} )
|
|
|
|
).toEqual( 'orders' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns `finalizing` when customers and orders are already imported', () => {
|
|
|
|
expect(
|
|
|
|
getStatus( {
|
|
|
|
customersProgress: 1,
|
|
|
|
customersTotal: 1,
|
|
|
|
inProgress: true,
|
|
|
|
ordersProgress: 1,
|
|
|
|
ordersTotal: 1,
|
|
|
|
} )
|
|
|
|
).toEqual( 'finalizing' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns `finished` when customers and orders are already imported and inProgress is false', () => {
|
|
|
|
expect(
|
|
|
|
getStatus( {
|
|
|
|
customersProgress: 1,
|
|
|
|
customersTotal: 1,
|
|
|
|
inProgress: false,
|
|
|
|
ordersProgress: 1,
|
|
|
|
ordersTotal: 1,
|
|
|
|
} )
|
|
|
|
).toEqual( 'finished' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns `ready` when there are customers or orders to import', () => {
|
|
|
|
expect(
|
|
|
|
getStatus( {
|
|
|
|
customersProgress: 0,
|
|
|
|
customersTotal: 1,
|
|
|
|
inProgress: false,
|
|
|
|
ordersProgress: 0,
|
|
|
|
ordersTotal: 1,
|
|
|
|
} )
|
|
|
|
).toEqual( 'ready' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'returns `nothing` when there are no customers or orders to import', () => {
|
|
|
|
expect(
|
|
|
|
getStatus( {
|
|
|
|
customersProgress: 0,
|
|
|
|
customersTotal: 0,
|
|
|
|
inProgress: false,
|
|
|
|
ordersProgress: 0,
|
|
|
|
ordersTotal: 0,
|
|
|
|
} )
|
|
|
|
).toEqual( 'nothing' );
|
|
|
|
} );
|
|
|
|
} );
|