Removed unnecessary dependencies
This commit is contained in:
parent
1f341df486
commit
2f87604ef1
File diff suppressed because it is too large
Load Diff
|
@ -1,61 +0,0 @@
|
||||||
/**
|
|
||||||
* This file contains objects that can be used as test data for scenarios around creating, retrieivng, updating, and deleting products.
|
|
||||||
*
|
|
||||||
* For more details on the Product properties, see:
|
|
||||||
*
|
|
||||||
* https://woocommerce.github.io/woocommerce-rest-api-docs/#products
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple, physical product.
|
|
||||||
*/
|
|
||||||
const simpleProduct = {
|
|
||||||
name: 'A Simple Product',
|
|
||||||
regular_price: '25',
|
|
||||||
description: 'Description for this simple product.',
|
|
||||||
short_description: 'Shorter description.',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A virtual product
|
|
||||||
*/
|
|
||||||
const virtualProduct = {
|
|
||||||
name: 'A Virtual Product',
|
|
||||||
regular_price: '10',
|
|
||||||
virtual: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A variable product
|
|
||||||
*/
|
|
||||||
const variableProduct = {
|
|
||||||
name: 'A Variable Product',
|
|
||||||
type: 'variable',
|
|
||||||
attributes: [
|
|
||||||
{
|
|
||||||
name: 'Colour',
|
|
||||||
visible: true,
|
|
||||||
variation: true,
|
|
||||||
options: [ 'Red', 'Green', 'Blue' ],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Size',
|
|
||||||
visible: true,
|
|
||||||
variation: true,
|
|
||||||
options: [ 'Small', 'Medium', 'Large' ],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Logo',
|
|
||||||
visible: true,
|
|
||||||
variation: true,
|
|
||||||
options: [ 'Woo', 'WordPress' ],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
simpleProduct,
|
|
||||||
virtualProduct,
|
|
||||||
variableProduct,
|
|
||||||
};
|
|
|
@ -1,18 +0,0 @@
|
||||||
/**
|
|
||||||
* A basic refund.
|
|
||||||
*
|
|
||||||
* For more details on the order refund properties, see:
|
|
||||||
*
|
|
||||||
* https://woocommerce.github.io/woocommerce-rest-api-docs/#order-refund-properties
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const refund = {
|
|
||||||
api_refund: false,
|
|
||||||
amount: '1.00',
|
|
||||||
reason: 'Late delivery refund.',
|
|
||||||
line_items: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
refund: refund,
|
|
||||||
};
|
|
|
@ -1,7 +1,5 @@
|
||||||
const { ordersApi } = require( '../../endpoints/orders' );
|
const { ordersApi, productsApi } = require( '../../endpoints' );
|
||||||
const { productsApi } = require( '../../endpoints/products' );
|
|
||||||
const { order } = require( '../../data' );
|
const { order } = require( '../../data' );
|
||||||
const { simpleProduct } = require( '../../data/products-crud' );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Billing properties to update.
|
* Billing properties to update.
|
||||||
|
@ -49,6 +47,14 @@ const statusesDataTable = [
|
||||||
'failed',
|
'failed',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple product that will be added to an order.
|
||||||
|
*/
|
||||||
|
const simpleProduct = {
|
||||||
|
name: 'Incredible Plastic Table',
|
||||||
|
regular_price: '48',
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the WooCommerce Orders API.
|
* Tests for the WooCommerce Orders API.
|
||||||
*
|
*
|
||||||
|
@ -60,22 +66,19 @@ describe( 'Orders API tests: CRUD', () => {
|
||||||
let orderId;
|
let orderId;
|
||||||
|
|
||||||
describe( 'Create an order', () => {
|
describe( 'Create an order', () => {
|
||||||
const createdOrders = [];
|
|
||||||
|
|
||||||
afterAll( async () => {
|
|
||||||
// Delete the created orders in the it.each() block.
|
|
||||||
// Unlike the `orderId` variable, these orders will not be needed by other tests.
|
|
||||||
await ordersApi.batch.orders( { delete: createdOrders } );
|
|
||||||
} );
|
|
||||||
|
|
||||||
it( 'can create a pending order by default', async () => {
|
it( 'can create a pending order by default', async () => {
|
||||||
const { body, status } = await ordersApi.create.order( {
|
// Create an order that has a null status
|
||||||
|
const requestPayload = {
|
||||||
...order,
|
...order,
|
||||||
status: null,
|
status: null,
|
||||||
} );
|
};
|
||||||
|
const { body, status } = await ordersApi.create.order(
|
||||||
|
requestPayload
|
||||||
|
);
|
||||||
// Save the order ID. It will be used by the retrieve, update, and delete tests.
|
// Save the order ID. It will be used by the retrieve, update, and delete tests.
|
||||||
orderId = body.id;
|
orderId = body.id;
|
||||||
|
|
||||||
|
// Verify that the order status is 'pending'
|
||||||
expect( status ).toEqual( ordersApi.create.responseCode );
|
expect( status ).toEqual( ordersApi.create.responseCode );
|
||||||
expect( typeof body.id ).toEqual( 'number' );
|
expect( typeof body.id ).toEqual( 'number' );
|
||||||
expect( body.status ).toEqual( 'pending' );
|
expect( body.status ).toEqual( 'pending' );
|
||||||
|
@ -96,8 +99,8 @@ describe( 'Orders API tests: CRUD', () => {
|
||||||
expect( typeof body.id ).toEqual( 'number' );
|
expect( typeof body.id ).toEqual( 'number' );
|
||||||
expect( body.status ).toEqual( expectedStatus );
|
expect( body.status ).toEqual( expectedStatus );
|
||||||
|
|
||||||
// Save the order id to be deleted later
|
// Cleanup: Delete this order
|
||||||
createdOrders.push( body.id );
|
await ordersApi.delete.order( body.id, true );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} );
|
} );
|
||||||
|
@ -113,19 +116,15 @@ describe( 'Orders API tests: CRUD', () => {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
describe( 'Update an order', () => {
|
describe( 'Update an order', () => {
|
||||||
let productId;
|
|
||||||
|
|
||||||
beforeAll( async () => {
|
beforeAll( async () => {
|
||||||
// Setup a product that will be added later to the order
|
// Create the product and save its id
|
||||||
const { body } = await productsApi.create.product( {
|
const { body } = await productsApi.create.product( simpleProduct );
|
||||||
...simpleProduct,
|
simpleProduct.id = body.id;
|
||||||
} );
|
|
||||||
productId = body.id;
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
afterAll( async () => {
|
afterAll( async () => {
|
||||||
// Delete the created product
|
// Delete the created product
|
||||||
await productsApi.delete.product( productId, true );
|
await productsApi.delete.product( simpleProduct.id, true );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
it.each( statusesDataTable )(
|
it.each( statusesDataTable )(
|
||||||
|
@ -160,16 +159,17 @@ describe( 'Orders API tests: CRUD', () => {
|
||||||
it( 'can add a product to an order', async () => {
|
it( 'can add a product to an order', async () => {
|
||||||
// Add the product to the order
|
// Add the product to the order
|
||||||
const requestPayload = {
|
const requestPayload = {
|
||||||
line_items: [ { product_id: productId } ],
|
line_items: [ { product_id: simpleProduct.id } ],
|
||||||
};
|
};
|
||||||
const { body, status } = await ordersApi.update.order(
|
const { body, status } = await ordersApi.update.order(
|
||||||
orderId,
|
orderId,
|
||||||
requestPayload
|
requestPayload
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Verify that the added product has the correct values
|
||||||
expect( status ).toEqual( ordersApi.update.responseCode );
|
expect( status ).toEqual( ordersApi.update.responseCode );
|
||||||
expect( body.line_items ).toHaveLength( 1 );
|
expect( body.line_items ).toHaveLength( 1 );
|
||||||
expect( body.line_items[ 0 ].product_id ).toEqual( productId );
|
expect( body.line_items[ 0 ] ).toMatchObject( simpleProduct );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
it( 'can pay for an order', async () => {
|
it( 'can pay for an order', async () => {
|
||||||
|
@ -186,7 +186,6 @@ describe( 'Orders API tests: CRUD', () => {
|
||||||
orderId,
|
orderId,
|
||||||
updateRequestPayload
|
updateRequestPayload
|
||||||
);
|
);
|
||||||
|
|
||||||
expect( status ).toEqual( ordersApi.update.responseCode );
|
expect( status ).toEqual( ordersApi.update.responseCode );
|
||||||
expect( body.id ).toEqual( orderId );
|
expect( body.id ).toEqual( orderId );
|
||||||
|
|
||||||
|
@ -201,9 +200,11 @@ describe( 'Orders API tests: CRUD', () => {
|
||||||
|
|
||||||
describe( 'Delete an order', () => {
|
describe( 'Delete an order', () => {
|
||||||
it( 'can permanently delete an order', async () => {
|
it( 'can permanently delete an order', async () => {
|
||||||
|
// Delete the order.
|
||||||
const response = await ordersApi.delete.order( orderId, true );
|
const response = await ordersApi.delete.order( orderId, true );
|
||||||
expect( response.status ).toEqual( ordersApi.delete.responseCode );
|
expect( response.status ).toEqual( ordersApi.delete.responseCode );
|
||||||
|
|
||||||
|
// Verify that the order can no longer be retrieved.
|
||||||
const getOrderResponse = await ordersApi.retrieve.order( orderId );
|
const getOrderResponse = await ordersApi.retrieve.order( orderId );
|
||||||
expect( getOrderResponse.status ).toEqual( 404 );
|
expect( getOrderResponse.status ).toEqual( 404 );
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in New Issue