Used API package to create orders by batch

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

View File

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

View File

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