Merge pull request #30398 from woocommerce/add/e2e-order-cleanup

Added order cleanup to e2e setup
This commit is contained in:
Ron Rennick 2021-08-09 12:33:53 -03:00 committed by GitHub
commit 7ba121ec1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 3 deletions

View File

@ -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');

View File

@ -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

View File

@ -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

View File

@ -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.
*