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

85 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-11-15 14:30:34 +00:00
/**
* Internal dependencies
*/
const {
getRequest,
postRequest,
putRequest,
deleteRequest,
} = require( '../utils/request' );
2021-12-02 13:52:25 +00:00
const { getVariationExample, shared } = require( '../data' );
2021-11-15 14:30:34 +00:00
/**
* WooCommerce Product Variation endpoints.
*
* https://woocommerce.github.io/woocommerce-rest-api-docs/#product-variations
*/
const variationsApi = {
name: 'Product variations',
create: {
name: 'Create a product variation',
method: 'POST',
path: 'products/<product_id>/variations',
responseCode: 201,
2021-12-02 13:52:25 +00:00
payload: getVariationExample(),
2021-11-15 14:30:34 +00:00
variation: async ( productId, variation ) =>
postRequest( `products/${ productId }/variations`, variation ),
},
retrieve: {
name: 'Retrieve a product variation',
method: 'GET',
path: 'products/<product_id>/variations/<id>',
responseCode: 200,
variation: async ( productId, variationId ) =>
`products/${ productId }/variations/${ variationId }`,
},
listAll: {
name: 'List all product variations',
method: 'GET',
path: 'products/<product_id>/variations',
responseCode: 200,
variations: async ( productId, queryString = {} ) =>
getRequest( `products/${ productId }/variations`, queryString ),
},
update: {
name: 'Update a product variation',
method: 'PUT',
path: 'products/<product_id>/variations/<id>',
responseCode: 200,
2021-12-02 13:52:25 +00:00
payload: getVariationExample(),
2021-11-15 14:30:34 +00:00
variation: async ( productId, variationId, variationDetails ) =>
putRequest(
`products/${ productId }/variations/${ variationId }`,
taxRateDetails
),
},
delete: {
name: 'Delete a product variation',
method: 'DELETE',
path: 'products/<product_id>/variations/<id>',
responseCode: 200,
payload: {
force: false,
},
variation: async ( productId, variationId, deletePermanently ) =>
deleteRequest(
`products/${ productId }/variations/${ variationId }`,
deletePermanently
),
},
batch: {
name: 'Batch update product variations',
method: 'POST',
path: 'products/<product_id>/variations/batch',
responseCode: 200,
2021-12-02 13:52:25 +00:00
payload: shared.getBatchPayloadExample( getVariationExample() ),
2021-11-15 14:30:34 +00:00
variations: async ( batchUpdatePayload ) =>
postRequest(
`products/${ productId }/variations/${ variationId }`,
batchUpdatePayload
),
},
};
module.exports = { variationsApi };