Code review feedback
This commit is contained in:
parent
94a96edf2b
commit
5bf172315e
|
@ -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 );
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ const runRefundOrderTest = () => {
|
|||
beforeAll(async () => {
|
||||
productId = await createSimpleProduct();
|
||||
orderId = await createOrder( {
|
||||
productId: productId,
|
||||
productId,
|
||||
status: 'completed'
|
||||
} );
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue