woocommerce/packages/js/api-core-tests/tests/shipping/shipping-method.test.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-11-11 13:11:03 +00:00
const { shippingMethodsApi } = require( '../../endpoints' );
const { getShippingMethodExample } = require( '../../data' );
/**
* Shipping zone id for "Locations not covered by your other zones".
*/
const shippingZoneId = 0;
/**
* Data table for shipping methods.
*/
const shippingMethods = [
[ 'Flat rate', 'flat_rate', '10' ],
[ 'Free shipping', 'free_shipping', undefined ],
[ 'Local pickup', 'local_pickup', '30' ],
];
/**
* Tests for the WooCommerce Shipping methods API.
*
* @group api
* @group shipping-methods
*
*/
describe( 'Shipping methods API tests', () => {
it.each( shippingMethods )(
"can add a '%s' shipping method",
async ( methodTitle, methodId, cost ) => {
const shippingMethod = getShippingMethodExample( methodId, cost );
const { status, body } =
await shippingMethodsApi.create.shippingMethod(
shippingZoneId,
shippingMethod
);
2021-11-11 13:11:03 +00:00
expect( status ).toEqual( shippingMethodsApi.create.responseCode );
expect( typeof body.id ).toEqual( 'number' );
expect( body.method_id ).toEqual( methodId );
expect( body.method_title ).toEqual( methodTitle );
expect( body.enabled ).toEqual( true );
if ( [ 'flat_rate', 'local_pickup' ].includes( methodId ) ) {
expect( body.settings.cost.value ).toEqual( cost );
}
// Cleanup: Delete the shipping method
await shippingMethodsApi.delete.shippingMethod(
shippingZoneId,
body.id,
true
);
}
);
} );