2021-11-11 11:39:40 +00:00
|
|
|
const { shippingZonesApi } = require( '../../endpoints' );
|
|
|
|
const { getShippingZoneExample } = require( '../../data' );
|
|
|
|
|
|
|
|
/**
|
2021-11-11 11:47:40 +00:00
|
|
|
* Shipping zone to be created, retrieved, updated, and deleted by the tests.
|
2021-11-11 11:39:40 +00:00
|
|
|
*/
|
|
|
|
const shippingZone = getShippingZoneExample();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for the WooCommerce Shipping zones API.
|
|
|
|
*
|
|
|
|
* @group api
|
|
|
|
* @group shipping-zone
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
describe( 'Shipping zones API tests', () => {
|
|
|
|
it( 'can create a shipping zone', async () => {
|
|
|
|
const { status, body } = await shippingZonesApi.create.shippingZone(
|
|
|
|
shippingZone
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( status ).toEqual( shippingZonesApi.create.responseCode );
|
|
|
|
expect( typeof body.id ).toEqual( 'number' );
|
|
|
|
expect( body.name ).toEqual( shippingZone.name );
|
|
|
|
|
2021-11-11 11:47:40 +00:00
|
|
|
// Save the shipping zone ID. It will be used by other tests.
|
2021-11-11 11:39:40 +00:00
|
|
|
shippingZone.id = body.id;
|
|
|
|
} );
|
|
|
|
|
2021-11-11 11:47:40 +00:00
|
|
|
it( 'can retrieve a shipping zone', async () => {
|
|
|
|
const { status, body } = await shippingZonesApi.retrieve.shippingZone(
|
|
|
|
shippingZone.id
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( status ).toEqual( shippingZonesApi.retrieve.responseCode );
|
|
|
|
expect( body.id ).toEqual( shippingZone.id );
|
|
|
|
} );
|
|
|
|
|
2021-11-11 12:02:30 +00:00
|
|
|
it( 'can list all shipping zones', async () => {
|
|
|
|
const param = {
|
|
|
|
_fields: 'id',
|
|
|
|
};
|
|
|
|
const { status, body } = await shippingZonesApi.listAll.shippingZones(
|
|
|
|
param
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( status ).toEqual( shippingZonesApi.listAll.responseCode );
|
|
|
|
expect( body ).toHaveLength( 2 ); // the test shipping zone, and the default 'Locations not covered by your other zones'
|
|
|
|
expect( body ).toEqual(
|
|
|
|
expect.arrayContaining( [ { id: shippingZone.id } ] )
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2021-11-11 11:47:40 +00:00
|
|
|
it( 'can update a shipping zone', async () => {
|
|
|
|
const updatedShippingZone = {
|
|
|
|
name: 'United States (Domestic)',
|
|
|
|
};
|
|
|
|
|
|
|
|
const { status, body } = await shippingZonesApi.update.shippingZone(
|
|
|
|
shippingZone.id,
|
|
|
|
updatedShippingZone
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( status ).toEqual( shippingZonesApi.retrieve.responseCode );
|
|
|
|
expect( body.id ).toEqual( shippingZone.id );
|
|
|
|
expect( body.name ).toEqual( updatedShippingZone.name );
|
|
|
|
} );
|
|
|
|
|
2021-11-11 11:39:40 +00:00
|
|
|
it( 'can delete a shipping zone', async () => {
|
|
|
|
const { status, body } = await shippingZonesApi.delete.shippingZone(
|
|
|
|
shippingZone.id,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( status ).toEqual( shippingZonesApi.delete.responseCode );
|
|
|
|
expect( body.id ).toEqual( shippingZone.id );
|
|
|
|
|
|
|
|
// Verify that the shipping zone can no longer be retrieved
|
|
|
|
const {
|
|
|
|
status: retrieveStatus,
|
|
|
|
} = await shippingZonesApi.retrieve.shippingZone( shippingZone.id );
|
|
|
|
expect( retrieveStatus ).toEqual( 404 );
|
|
|
|
} );
|
|
|
|
} );
|