Added order cleanup
This commit is contained in:
parent
164e7e495c
commit
ae75249bed
|
@ -44,6 +44,7 @@ beforeAll(async () => {
|
|||
await trashExistingPosts();
|
||||
await withRestApi.deleteAllProducts();
|
||||
await withRestApi.deleteAllCoupons();
|
||||
await withRestApi.deleteAllOrders();
|
||||
await page.goto(WP_ADMIN_LOGIN);
|
||||
await clearLocalStorage();
|
||||
await setBrowserViewport('large');
|
||||
|
|
|
@ -5,6 +5,7 @@ const client = factories.api.withDefaultPermalinks;
|
|||
const onboardingProfileEndpoint = '/wc-admin/onboarding/profile';
|
||||
const shippingZoneEndpoint = '/wc/v3/shipping/zones';
|
||||
const userEndpoint = '/wp/v2/users';
|
||||
const ordersEndpoint = '/wc/v3/orders';
|
||||
|
||||
/**
|
||||
* Utility function to delete all merchant created data store objects.
|
||||
|
@ -81,6 +82,24 @@ export const withRestApi = {
|
|||
const repository = SimpleProduct.restRepository( client );
|
||||
await deleteAllRepositoryObjects( repository );
|
||||
},
|
||||
/**
|
||||
* Use api package to delete all orders.
|
||||
*
|
||||
* @return {Promise} Promise resolving once orders have been deleted.
|
||||
*/
|
||||
deleteAllOrders: async () => {
|
||||
// We need to specfically filter on order status here to make sure we catch all orders to delete.
|
||||
const orderStatuses = ['pending', 'processing', 'on-hold', 'completed', 'cancelled', 'refunded', 'failed', 'trash'];
|
||||
for (let s = 0; s < orderStatuses.length; s++) {
|
||||
const orders = await client.get( ordersEndpoint + `?status=${orderStatuses[s]}` );
|
||||
if ( orders.data && orders.data.length ) {
|
||||
for ( let o = 0; o < orders.data.length; o++ ) {
|
||||
const response = await client.delete( ordersEndpoint + `/${orders.data[o].id}?force=true` );
|
||||
expect( response.statusCode ).toBe( 200 );
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Use api package to delete shipping zones.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue