Merge pull request #30398 from woocommerce/add/e2e-order-cleanup
Added order cleanup to e2e setup
This commit is contained in:
commit
7ba121ec1a
|
@ -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');
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
- Added `describeIf()` to conditionally run a test suite
|
||||
- Added `itIf()` to conditionally run a test case.
|
||||
- Added merchant workflows around plugins: `uploadAndActivatePlugin()`, `activatePlugin()`, `deactivatePlugin()`, `deletePlugin()`
|
||||
- Added `deleteAllOrders()` that goes through and deletes all orders
|
||||
- Added `deleteAllShippingClasses()` which permanently deletes all shipping classes using the API
|
||||
- Added `statuses` optional parameter to `deleteAllRepositoryObjects()` to delete on specific statuses
|
||||
|
||||
# 0.1.5
|
||||
|
||||
|
|
|
@ -146,6 +146,7 @@ This package provides support for enabling retries in tests:
|
|||
| `deleteAllShippingClasses` | Permanently delete all shipping classes |
|
||||
| `deleteCustomerByEmail` | `emailAddress` | Delete customer user account. Posts are reassigned to user ID 1 |
|
||||
| `resetSettingsGroupToDefault` | `settingsGroup` | Reset settings in settings group to default except `select` fields |
|
||||
| `deleteAllOrders` | | Permanently delete all orders |
|
||||
|
||||
### Page Utilities
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import factories from '../factories';
|
||||
import {Coupon, Setting, SimpleProduct} from '@woocommerce/api';
|
||||
import {Coupon, Setting, SimpleProduct, Order} from '@woocommerce/api';
|
||||
|
||||
const client = factories.api.withDefaultPermalinks;
|
||||
const onboardingProfileEndpoint = '/wc-admin/onboarding/profile';
|
||||
|
@ -12,12 +12,12 @@ const userEndpoint = '/wp/v2/users';
|
|||
*
|
||||
* @param repository
|
||||
* @param defaultObjectId
|
||||
* @param statuses Status of the object to check
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const deleteAllRepositoryObjects = async ( repository, defaultObjectId = null ) => {
|
||||
const deleteAllRepositoryObjects = async ( repository, defaultObjectId = null, statuses = [ 'draft', 'publish', 'trash' ] ) => {
|
||||
let objects;
|
||||
const minimum = defaultObjectId == null ? 0 : 1;
|
||||
const statuses = ['draft','publish','trash'];
|
||||
|
||||
for ( let s = 0; s < statuses.length; s++ ) {
|
||||
const status = statuses[ s ];
|
||||
|
@ -82,6 +82,17 @@ 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'];
|
||||
const repository = Order.restRepository( client );
|
||||
await deleteAllRepositoryObjects( repository, null, orderStatuses );
|
||||
},
|
||||
/**
|
||||
* Use api package to delete shipping zones.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue