Move utility function to withRestApi

This commit is contained in:
Rodel Calasagsag 2021-07-29 19:31:27 +08:00
parent b116756b09
commit 16083c2574
3 changed files with 31 additions and 30 deletions

View File

@ -4,7 +4,7 @@
*/
const {
merchant,
batchCreateOrders,
withRestApi,
clickFilter,
moveAllItemsToTrash,
} = require( '@woocommerce/e2e-utils' );
@ -52,7 +52,7 @@ const runOrderStatusFiltersTest = () => {
return statusName.replace('wc-', '');
});
await batchCreateOrders(statuses);
await withRestApi.batchCreateOrders(statuses);
// Next, let's login
await merchant.login();

View File

@ -352,31 +352,6 @@ 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((status) => {
return {
...defaultOrder,
status: status
};
});
// 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.
*
@ -546,6 +521,5 @@ export {
createSimpleProductWithCategory,
clickUpdateOrder,
deleteAllEmailLogs,
deleteAllShippingZones,
batchCreateOrders
deleteAllShippingZones
};

View File

@ -1,5 +1,6 @@
import factories from '../factories';
import {Coupon, Setting, SimpleProduct} from '@woocommerce/api';
import { Coupon, Setting, SimpleProduct } from '@woocommerce/api';
import config from 'config';
const client = factories.api.withDefaultPermalinks;
const onboardingProfileEndpoint = '/wc-admin/onboarding/profile';
@ -152,5 +153,31 @@ export const withRestApi = {
expect( response.value ).toBe( defaultSetting.value );
}
}
},
/**
* Create a batch of orders with the given `statuses`
* using the "Batch Create Order" API endpoint.
*
* @param statuses Array of order statuses
*/
batchCreateOrders : async (statuses) => {
const defaultOrder = config.get('orders.basicPaidOrder');
const path = '/wc/v3/orders/batch';
// Create an order per status
const orders = statuses.map((status) => {
return {
...defaultOrder,
status: status
};
});
// Set the request payload from the created orders.
// Then send the API request.
const payload = { create: orders };
const { statusCode } = await client.post(path, payload);
/* eslint-disable jest/no-standalone-expect */
expect(statusCode).toEqual(200);
}
};