woocommerce/packages/js/api-core-tests/endpoints/orders.js

77 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-08-23 17:39:03 +00:00
/**
* Internal dependencies
*/
const {
getRequest,
postRequest,
putRequest,
deleteRequest,
} = require( '../utils/request' );
const { getOrderExample, shared } = require( '../data' );
2021-08-23 17:39:03 +00:00
/**
* WooCommerce Orders endpoints.
*
* https://woocommerce.github.io/woocommerce-rest-api-docs/#orders
*/
const ordersApi = {
name: 'Orders',
create: {
name: 'Create an order',
method: 'POST',
path: 'orders',
responseCode: 201,
2021-09-08 01:02:58 +00:00
payload: getOrderExample(),
2021-09-07 22:20:44 +00:00
order: async ( orderDetails ) => postRequest( 'orders', orderDetails ),
2021-08-23 17:39:03 +00:00
},
retrieve: {
name: 'Retrieve an order',
method: 'GET',
path: 'orders/<id>',
responseCode: 200,
order: async ( orderId, ordersQuery = {} ) =>
getRequest( `orders/${ orderId }`, ordersQuery ),
2021-08-23 17:39:03 +00:00
},
listAll: {
name: 'List all orders',
method: 'GET',
path: 'orders',
responseCode: 200,
orders: async ( ordersQuery = {} ) =>
getRequest( 'orders', ordersQuery ),
2021-08-23 17:39:03 +00:00
},
update: {
name: 'Update an order',
method: 'PUT',
path: 'orders/<id>',
responseCode: 200,
2021-09-08 01:02:58 +00:00
payload: getOrderExample(),
order: async ( orderId, orderDetails ) =>
putRequest( `orders/${ orderId }`, orderDetails ),
2021-08-23 17:39:03 +00:00
},
delete: {
name: 'Delete an order',
method: 'DELETE',
path: 'orders/<id>',
responseCode: 200,
payload: {
force: false,
2021-08-23 17:39:03 +00:00
},
order: async ( orderId, deletePermanently ) =>
deleteRequest( `orders/${ orderId }`, deletePermanently ),
2021-08-23 17:39:03 +00:00
},
batch: {
name: 'Batch update orders',
method: 'POST',
path: 'orders/batch',
responseCode: 200,
2021-09-08 01:02:58 +00:00
payload: shared.getBatchPayloadExample( getOrderExample() ),
orders: async ( batchUpdatePayload ) =>
postRequest( `orders/batch`, batchUpdatePayload ),
2021-08-23 17:39:03 +00:00
},
2021-09-07 22:20:44 +00:00
};
2021-08-23 17:39:03 +00:00
module.exports = {
ordersApi,
2021-09-07 22:20:44 +00:00
};