Merge pull request #30184 from woocommerce/add/e2e-merchant-batch-create-orders

Use API package to create orders by batch
This commit is contained in:
Ron Rennick 2021-08-20 11:10:05 -03:00 committed by GitHub
commit 504b96d7e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 13 deletions

View File

@ -10,6 +10,9 @@
- Checkout create account test would fail if configuration value `addresses.customer.billing.email` was not `john.doe@example.com`
## Changed
- The e2e test `order-status-filters.test.js` now uses the API to create orders
# 0.1.3
## Added

View File

@ -1,10 +1,11 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests */
/**
* Internal dependencies
*/
import config from 'config';
const {
merchant,
createSimpleOrder,
withRestApi,
clickFilter,
moveAllItemsToTrash,
} = require( '@woocommerce/e2e-utils' );
@ -42,22 +43,28 @@ const orderStatus = {
description: { text: 'Failed' },
}
};
const defaultOrder = config.get('orders.basicPaidOrder');
const runOrderStatusFiltersTest = () => {
describe('WooCommerce Orders > Filter Orders by Status', () => {
beforeAll(async () => {
// First, let's login
await merchant.login();
// First, let's create some orders we can filter against
const orders = Object.entries(orderStatus).map((entryPair) => {
const statusName = entryPair[1].name.replace('wc-', '');
// Next, let's create some orders we can filter against
await createSimpleOrder(orderStatus.pending.description.text);
await createSimpleOrder(orderStatus.processing.description.text);
await createSimpleOrder(orderStatus.onHold.description.text);
await createSimpleOrder(orderStatus.completed.description.text);
await createSimpleOrder(orderStatus.cancelled.description.text);
await createSimpleOrder(orderStatus.refunded.description.text);
await createSimpleOrder(orderStatus.failed.description.text);
}, 60000);
return {
...defaultOrder,
status: statusName,
};
});
// Create the orders using the API
await withRestApi.batchCreateOrders(orders);
// Next, let's login
await merchant.login();
});
afterAll( async () => {
// Make sure we're on the all orders view and cleanup the orders we created

View File

@ -3,6 +3,7 @@
## Added
- Factories for variable product, variation, and grouped product
- New function to create orders by batch using the orders API
- Added new constant for WordPress update page `WP_ADMIN_WP_UPDATES`
- Added new merchant flow for `openWordPressUpdatesPage()`
- Added new merchant flows:

View File

@ -147,6 +147,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 |
| `batchCreateOrders` | `orders` | Create a batch of orders using the "Batch Create Order" API endpoint |
| `deleteAllOrders` | | Permanently delete all orders |
### Page Utilities

View File

@ -251,5 +251,19 @@ export const withRestApi = {
expect( response.value ).toBe( defaultSetting.value );
}
}
},
/**
* Create a batch of orders using the "Batch Create Order" API endpoint.
*
* @param orders Array of orders to be created
*/
batchCreateOrders : async (orders) => {
const path = '/wc/v3/orders/batch';
const payload = { create: orders };
const { statusCode } = await client.post(path, payload);
expect(statusCode).toEqual(200);
}
};