Used API package to create orders by batch

This commit is contained in:
Rodel Calasagsag 2021-06-30 18:48:10 +08:00
parent b88b868ab8
commit 53be6fb3d2
2 changed files with 37 additions and 12 deletions

View File

@ -4,7 +4,7 @@
*/ */
const { const {
merchant, merchant,
createSimpleOrder, batchCreateOrders,
clickFilter, clickFilter,
moveAllItemsToTrash, moveAllItemsToTrash,
} = require( '@woocommerce/e2e-utils' ); } = require( '@woocommerce/e2e-utils' );
@ -46,18 +46,17 @@ const orderStatus = {
const runOrderStatusFiltersTest = () => { const runOrderStatusFiltersTest = () => {
describe('WooCommerce Orders > Filter Orders by Status', () => { describe('WooCommerce Orders > Filter Orders by Status', () => {
beforeAll(async () => { beforeAll(async () => {
// First, let's login // First, let's create some orders we can filter against
await merchant.login(); const statuses = Object.entries(orderStatus).map((entryPair) => {
const statusName = entryPair[1].name;
// Next, let's create some orders we can filter against return statusName.replace('wc-', '');
await createSimpleOrder(orderStatus.pending.description.text); });
await createSimpleOrder(orderStatus.processing.description.text); await batchCreateOrders(statuses);
await createSimpleOrder(orderStatus.onHold.description.text);
await createSimpleOrder(orderStatus.completed.description.text); // Next, let's login
await createSimpleOrder(orderStatus.cancelled.description.text); await merchant.login();
await createSimpleOrder(orderStatus.refunded.description.text); });
await createSimpleOrder(orderStatus.failed.description.text);
}, 60000);
afterAll( async () => { afterAll( async () => {
// Make sure we're on the all orders view and cleanup the orders we created // Make sure we're on the all orders view and cleanup the orders we created

View File

@ -352,6 +352,31 @@ const createSimpleOrder = async ( orderStatus = 'Pending payment' ) => {
return variablePostIdValue; 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. * Adds a product to an order in the merchant.
* *
@ -522,4 +547,5 @@ export {
clickUpdateOrder, clickUpdateOrder,
deleteAllEmailLogs, deleteAllEmailLogs,
deleteAllShippingZones, deleteAllShippingZones,
batchCreateOrders
}; };