From c25b23aafcab2597da23b981df893d976bbcb05d Mon Sep 17 00:00:00 2001 From: Rodel Calasagsag Date: Wed, 30 Jun 2021 18:48:10 +0800 Subject: [PATCH] Used API package to create orders by batch --- .../wp-admin-order-status-filters.test.js | 23 ++++++++-------- tests/e2e/utils/src/components.js | 26 +++++++++++++++++++ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-order-status-filters.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-order-status-filters.test.js index 2870fe20830..d47d54073bf 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-order-status-filters.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-order-status-filters.test.js @@ -4,7 +4,7 @@ */ const { merchant, - createSimpleOrder, + batchCreateOrders, clickFilter, moveAllItemsToTrash, } = require( '@woocommerce/e2e-utils' ); @@ -46,18 +46,17 @@ const orderStatus = { 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 statuses = Object.entries(orderStatus).map((entryPair) => { + const statusName = entryPair[1].name; - // 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 statusName.replace('wc-', ''); + }); + await batchCreateOrders(statuses); + + // Next, let's login + await merchant.login(); + }); afterAll( async () => { // Make sure we're on the all orders view and cleanup the orders we created diff --git a/tests/e2e/utils/src/components.js b/tests/e2e/utils/src/components.js index d77351d66c7..387a6cf4faf 100644 --- a/tests/e2e/utils/src/components.js +++ b/tests/e2e/utils/src/components.js @@ -352,6 +352,31 @@ const createSimpleOrder = async ( orderStatus = 'Pending payment' ) => { return variablePostIdValue; }; +/** + * Creates a batch of orders from the given `statuses` + * using the "Batch Create Order" API. + * + * @param statuses Array of order statuses + */ +const batchCreateOrders = async (statuses) => { + const defaultOrder = config.get('orders.basicPaidOrder'); + const path = '/wc/v3/orders/batch'; + + // Create an order per status + const orders = statuses.map((s) => { + return { + ...defaultOrder, + status: s + }; + }); + + // Set the request payload from the created orders. + // Then send the API request. + const payload = { create: orders }; + const { statusCode } = await client.post(path, payload); + expect(statusCode).toEqual(200); +}; + /** * Adds a product to an order in the merchant. * @@ -522,4 +547,5 @@ export { clickUpdateOrder, deleteAllEmailLogs, deleteAllShippingZones, + batchCreateOrders };