Code review feedback

This commit is contained in:
Greg 2021-08-20 12:52:29 -06:00
parent 94a96edf2b
commit 5bf172315e
5 changed files with 22 additions and 41 deletions

View File

@ -25,7 +25,7 @@ const runOrderApplyCouponTest = () => {
beforeAll(async () => {
productId = await createSimpleProduct();
couponCode = await createCoupon();
orderId = await createOrder( { productId: productId, status: 'pending' } );
orderId = await createOrder( { productId, status: 'pending' } );
await merchant.login();
await merchant.goToOrder( orderId );

View File

@ -20,7 +20,7 @@ const runMerchantOrdersCustomerPaymentPage = () => {
describe('WooCommerce Merchant Flow: Orders > Customer Payment Page', () => {
beforeAll(async () => {
productId = await createSimpleProduct();
orderId = await createOrder( { productId: productId } );
orderId = await createOrder( { productId } );
await merchant.login();
});

View File

@ -44,7 +44,7 @@ const runRefundOrderTest = () => {
beforeAll(async () => {
productId = await createSimpleProduct();
orderId = await createOrder( {
productId: productId,
productId,
status: 'completed'
} );

View File

@ -73,10 +73,10 @@ const runOrderSearchingTest = () => {
productId = await createSimpleProduct('Wanted Product');
customerId = await updateCustomerBilling();
orderId = await createOrder({
customerId: customerId,
productId: productId,
customerBilling: customerBilling,
customerShipping: customerShipping,
customerId,
productId,
customerBilling,
customerShipping,
});
// Login and open All Orders view

View File

@ -16,7 +16,7 @@ import {
waitForSelectorWithoutThrow,
} from './page-utils';
import factories from './factories';
import { Coupon } from '@woocommerce/api';
import { Coupon, Order } from '@woocommerce/api';
const client = factories.api.withDefaultPermalinks;
const config = require( 'config' );
@ -329,40 +329,21 @@ const createGroupedProduct = async (groupedProduct = defaultGroupedProduct) => {
* @returns {Promise<number>} ID of the created order.
*/
const createOrder = async ( orderOptions = {} ) => {
const client = factories.api.withDefaultPermalinks;
const ordersEndpoint = 'wc/v3/orders';
const newOrder = {};
const newOrder = {
...( orderOptions.status ) && { status: orderOptions.status },
...( orderOptions.customerId ) && { customer_id: orderOptions.customerId },
...( orderOptions.customerBilling ) && { billing: orderOptions.customerBilling },
...( orderOptions.customerShipping ) && { shipping: orderOptions.customerShipping },
...( orderOptions.productId ) && { line_items: [
{ product_id: orderOptions.productId },
]
},
};
if ( orderOptions.status ) {
newOrder.status = orderOptions.status;
}
const repository = Order.restRepository( client );
const order = await repository.create( newOrder );
if ( orderOptions.customerId ) {
newOrder.customer_id = orderOptions.customerId;
}
if ( orderOptions.customerBilling ) {
newOrder.billing = orderOptions.customerBilling;
}
if ( orderOptions.customerShipping ) {
newOrder.shipping = orderOptions.customerShipping;
}
if ( orderOptions.productId ) {
newOrder.line_items = [
{
product_id: orderOptions.productId
}
]
}
const order = await client.post( ordersEndpoint, newOrder );
if ( !order.data ) {
return;
}
return order.data.id;
return order.id;
}
/**
@ -565,5 +546,5 @@ export {
clickUpdateOrder,
deleteAllEmailLogs,
deleteAllShippingZones,
createOrder
createOrder,
};