add basic external product api test
This commit is contained in:
parent
cc86f19dec
commit
116dccd12a
|
@ -17,6 +17,12 @@
|
|||
},
|
||||
"variable": {
|
||||
"name": "Variable Product with Three Variations"
|
||||
},
|
||||
"external": {
|
||||
"name": "External product",
|
||||
"regularPrice": "24.99",
|
||||
"buttonText": "Buy now",
|
||||
"externalUrl": "https://wordpress.org/plugins/woocommerce"
|
||||
}
|
||||
},
|
||||
"addresses": {
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/* eslint-disable jest/no-export, jest/no-disabled-tests */
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
const { HTTPClientFactory, ExternalProduct } = require( '@woocommerce/api' );
|
||||
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
const config = require( 'config' );
|
||||
const {
|
||||
it,
|
||||
describe,
|
||||
beforeAll,
|
||||
} = require( '@jest/globals' );
|
||||
|
||||
/**
|
||||
* Create an external product and retrieve via the API.
|
||||
*/
|
||||
const runExternalProductAPITest = () => {
|
||||
// @todo: add a call to ensure pretty permalinks are enabled once settings api is in use.
|
||||
describe('REST API > External Product', () => {
|
||||
let client;
|
||||
let defaultExternalProduct;
|
||||
let product;
|
||||
let repository;
|
||||
|
||||
beforeAll(async () => {
|
||||
defaultExternalProduct = config.get( 'products.external' );
|
||||
const admin = config.get( 'users.admin' );
|
||||
const url = config.get( 'url' );
|
||||
|
||||
client = HTTPClientFactory.build( url )
|
||||
.withBasicAuth( admin.username, admin.password )
|
||||
.withIndexPermalinks()
|
||||
.create();
|
||||
} );
|
||||
|
||||
it('can create an external product', async () => {
|
||||
repository = ExternalProduct.restRepository( client );
|
||||
|
||||
// Check properties of product in the create product response.
|
||||
product = await repository.create( defaultExternalProduct );
|
||||
expect( product ).toEqual( expect.objectContaining( defaultExternalProduct ) );
|
||||
});
|
||||
|
||||
it('can retrieve a raw external product', async () => {
|
||||
const rawProperties = {
|
||||
id: product.id,
|
||||
button_text: defaultExternalProduct.buttonText,
|
||||
external_url: defaultExternalProduct.externalUrl,
|
||||
price: defaultExternalProduct.regularPrice,
|
||||
sale_price: '',
|
||||
};
|
||||
|
||||
// Read product directly from api.
|
||||
const response = await client.get( `/wc/v3/products/${product.id}` );
|
||||
expect( response.statusCode ).toBe( 200 );
|
||||
expect( response.data ).toEqual( expect.objectContaining( rawProperties ) );
|
||||
});
|
||||
|
||||
it('can retrieve a transformed external product', async () => {
|
||||
const transformedProperties = {
|
||||
...defaultExternalProduct,
|
||||
id: product.id,
|
||||
price: defaultExternalProduct.regularPrice,
|
||||
salePrice: ''
|
||||
};
|
||||
|
||||
// Read product via the repository.
|
||||
const transformed = await repository.read( product.id );
|
||||
expect( transformed ).toEqual( expect.objectContaining( transformedProperties ) );
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = runExternalProductAPITest;
|
|
@ -8,6 +8,9 @@ const runActivationTest = require( './activate-and-setup/activate.test' );
|
|||
const { runOnboardingFlowTest, runTaskListTest } = require( './activate-and-setup/onboarding-tasklist.test' );
|
||||
const runInitialStoreSettingsTest = require( './activate-and-setup/setup.test' );
|
||||
|
||||
// REST API tests
|
||||
const runExternalProductAPITest = require( './api/external-product' );
|
||||
|
||||
// Shopper tests
|
||||
const runCartApplyCouponsTest = require( './shopper/front-end-cart-coupons.test');
|
||||
const runCartPageTest = require( './shopper/front-end-cart.test' );
|
||||
|
@ -68,6 +71,7 @@ module.exports = {
|
|||
runTaskListTest,
|
||||
runInitialStoreSettingsTest,
|
||||
runSetupOnboardingTests,
|
||||
runExternalProductAPITest,
|
||||
runCartApplyCouponsTest,
|
||||
runCartPageTest,
|
||||
runCheckoutApplyCouponsTest,
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
* Internal dependencies
|
||||
*/
|
||||
const { runExternalProductAPITest } = require( '@woocommerce/e2e-core-tests' );
|
||||
|
||||
runExternalProductAPITest();
|
Loading…
Reference in New Issue