Merge pull request #31109 from woocommerce/add/api-t-order-search

Added tests for order search
This commit is contained in:
Greg 2021-12-02 10:28:34 -07:00 committed by GitHub
commit 7891d382c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 87 additions and 0 deletions

View File

@ -7,3 +7,4 @@
- Refunds API Tests - Refunds API Tests
- Products API Tests - Products API Tests
- CRUD tests for the Orders API - CRUD tests for the Orders API
- Order Search API Tests

View File

@ -0,0 +1,86 @@
const { ordersApi } = require( '../../endpoints' );
const { getOrderExample, shared } = require( '../../data' );
/**
* Order to be searched
*/
const order = {
...getOrderExample(),
shipping: {
...shared.customerShipping,
company: 'Murphy LLC',
phone: '6146524353',
},
shipping_lines: [],
fee_lines: [],
coupon_lines: [],
};
/**
* Search parameters to be used.
* The following scenarios are not covered in this test suite because they're already covered in the `List all orders > search` test in `orders.test.js`
* ```
* can search by billing address 1
* can search by shipping address 1
* can search by billing last name
* can search by billing email
* can search by item name
* ```
*/
const searchParams = [
[ 'orderId', 'orderId' ],
[ 'billing first name', order.billing.first_name ],
[ 'billing company name', order.billing.company ],
[ 'billing address 2', order.billing.address_2 ],
[ 'billing city name', order.billing.city ],
[ 'billing post code', order.billing.postcode ],
[ 'billing phone', order.billing.phone ],
[ 'billing state', order.billing.state ],
[ 'shipping first name', order.shipping.first_name ],
[ 'shipping last name', order.shipping.last_name ],
[ 'shipping address 2', order.shipping.address_2 ],
[ 'shipping city', order.shipping.city ],
[ 'shipping post code', order.shipping.postcode ],
[ 'shipping state', order.shipping.state ],
];
/**
* Tests for the WooCommerce Order Search API.
*
* @group api
* @group orders
*
*/
describe( 'Order Search API tests', () => {
beforeAll( async () => {
// Create an order and save its ID
const { body } = await ordersApi.create.order( order );
order.id = body.id;
} );
afterAll( async () => {
// Cleanup: Delete the order
await ordersApi.delete.order( order.id, true );
} );
it.each( searchParams )( 'can search by %s', async ( title, param ) => {
const searchValue = param === 'orderId' ? order.id : param;
const { status, body } = await ordersApi.listAll.orders( {
search: searchValue,
} );
expect( status ).toEqual( ordersApi.listAll.responseCode );
expect( body ).toHaveLength( 1 );
expect( body[ 0 ].id ).toEqual( order.id );
} );
it( 'can return an empty result set when no matches were found', async () => {
const { status, body } = await ordersApi.listAll.orders( {
search: 'Chauncey Smith Kunde',
} );
expect( status ).toEqual( ordersApi.listAll.responseCode );
expect( body ).toEqual( [] );
} );
} );