[e2e] External sites - Include API tests for Pressable and WPCOM (#51284)

* Pressable - run only /api-tests

* Skip on Pressable

* Fix lint errors

* WPCOM - run API only

* Revert "WPCOM - run API only"

This reverts commit 5e59be1663.

* WPCOM - run API only

* Update settings-crud.test.js so they are passing against Pressable

* Skip "can retrieve all tax settings"

* Skip "can view all system status items" on WPCOM

* Several skips in settings-crud.test.js

* Skip "Product review tests: CRUD" on WPCOM

* Skip "List all products > categories" on WPCOM

* Skip "can view all payment gateways" on WPCOM

* Skip "Orders API tests" on WPCOM

* Skip "Customers API tests: CRUD" on WPCOM

* Revert `playwright.config.js` files and include '**/api-tests/**/*.test.js',

* Add changefile(s) from automation for the following project(s): woocommerce

* Skip three more API tests for WPCOM

* Skip two coupons tests

* Update report name for Pressable and WPCOM to ``*-core-e2e-and-api`

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Ivan Stojadinov 2024-09-12 16:01:40 +02:00 committed by GitHub
parent 2433f9f1c4
commit a06c6ba496
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 6488 additions and 6233 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Include API tests into test suites for Pressable and WPCOM.

View File

@ -556,7 +556,7 @@
"on-demand" "on-demand"
], ],
"report": { "report": {
"resultsBlobName": "default-pressable-core-e2e", "resultsBlobName": "default-pressable-core-e2e-and-api",
"resultsPath": "tests/e2e-pw/test-results", "resultsPath": "tests/e2e-pw/test-results",
"allure": true "allure": true
} }
@ -572,7 +572,7 @@
"on-demand" "on-demand"
], ],
"report": { "report": {
"resultsBlobName": "default-wpcom-core-e2e", "resultsBlobName": "default-wpcom-core-e2e-and-api",
"resultsPath": "tests/e2e-pw/test-results", "resultsPath": "tests/e2e-pw/test-results",
"allure": true "allure": true
} }
@ -681,7 +681,6 @@
"node_modules/@woocommerce/e2e-core-tests/CHANGELOG.md", "node_modules/@woocommerce/e2e-core-tests/CHANGELOG.md",
"node_modules/@woocommerce/api/dist/", "node_modules/@woocommerce/api/dist/",
"node_modules/@woocommerce/admin-e2e-tests/build", "node_modules/@woocommerce/admin-e2e-tests/build",
"node_modules/@woocommerce/classic-assets/build",
"node_modules/@woocommerce/block-library/build", "node_modules/@woocommerce/block-library/build",
"node_modules/@woocommerce/block-library/blocks.ini", "node_modules/@woocommerce/block-library/blocks.ini",
"node_modules/@woocommerce/admin-library/build", "node_modules/@woocommerce/admin-library/build",

View File

@ -16,6 +16,7 @@ config = {
'**/customize-store/**/*.spec.js', '**/customize-store/**/*.spec.js',
'**/merchant/**/*.spec.js', '**/merchant/**/*.spec.js',
'**/shopper/**/*.spec.js', '**/shopper/**/*.spec.js',
'**/api-tests/**/*.test.js',
], ],
grepInvert: /@skip-on-default-pressable/, grepInvert: /@skip-on-default-pressable/,
}, },

View File

@ -7,7 +7,11 @@ config = {
{ {
name: 'default wpcom', name: 'default wpcom',
use: { ...devices[ 'Desktop Chrome' ] }, use: { ...devices[ 'Desktop Chrome' ] },
testMatch: [ '**/basic.spec.js', '**/shopper/**/*.spec.js' ], testMatch: [
'**/basic.spec.js',
'**/shopper/**/*.spec.js',
'**/api-tests/**/*.test.js',
],
grepInvert: /@skip-on-default-wpcom/, grepInvert: /@skip-on-default-wpcom/,
}, },
], ],

View File

@ -69,7 +69,10 @@ test.describe( 'Coupons API tests', () => {
); );
} ); } );
test( 'can permanently delete a coupon', async ( { request } ) => { test(
'can permanently delete a coupon',
{ tag: '@skip-on-default-wpcom' },
async ( { request } ) => {
//call API to delete previously created coupon //call API to delete previously created coupon
const response = await request.delete( const response = await request.delete(
`/wp-json/wc/v3/coupons/${ couponId }`, `/wp-json/wc/v3/coupons/${ couponId }`,
@ -88,7 +91,8 @@ test.describe( 'Coupons API tests', () => {
//validate response //validate response
expect( getCouponResponse.status() ).toEqual( 404 ); expect( getCouponResponse.status() ).toEqual( 404 );
} ); }
);
} ); } );
test.describe( 'Batch update coupons', () => { test.describe( 'Batch update coupons', () => {
@ -180,7 +184,10 @@ test.describe( 'Batch update coupons', () => {
expect( updatedCoupons[ 1 ].amount ).toEqual( '25.00' ); expect( updatedCoupons[ 1 ].amount ).toEqual( '25.00' );
} ); } );
test( 'can batch delete coupons', async ( { request } ) => { test(
'can batch delete coupons',
{ tag: '@skip-on-default-wpcom' },
async ( { request } ) => {
// Batch delete the 2 coupons. // Batch delete the 2 coupons.
const couponIdsToDelete = expectedCoupons.map( ( { id } ) => id ); const couponIdsToDelete = expectedCoupons.map( ( { id } ) => id );
const batchDeletePayload = { const batchDeletePayload = {
@ -211,7 +218,8 @@ test.describe( 'Batch update coupons', () => {
); );
expect( response.status() ).toEqual( 404 ); expect( response.status() ).toEqual( 404 );
} }
} ); }
);
} ); } );
test.describe( 'List coupons', () => { test.describe( 'List coupons', () => {

View File

@ -2,7 +2,10 @@ const { test, expect } = require( '../../../fixtures/api-tests-fixtures' );
const { admin } = require( '../../../test-data/data' ); const { admin } = require( '../../../test-data/data' );
const { customer } = require( '../../../data' ); const { customer } = require( '../../../data' );
test.describe( 'Customers API tests: CRUD', () => { test.describe(
'Customers API tests: CRUD',
{ tag: [ '@skip-on-default-pressable', '@skip-on-default-wpcom' ] },
() => {
let customerId; let customerId;
let subscriberUserId; let subscriberUserId;
let subscriberUserCreatedDuringTests = false; let subscriberUserCreatedDuringTests = false;
@ -30,7 +33,9 @@ test.describe( 'Customers API tests: CRUD', () => {
// If a subscriber user has not been created then create one // If a subscriber user has not been created then create one
if ( ! subscriberUserId ) { if ( ! subscriberUserId ) {
const now = Date.now(); const now = Date.now();
const userResponse = await request.post( '/wp-json/wp/v2/users', { const userResponse = await request.post(
'/wp-json/wp/v2/users',
{
data: { data: {
username: `customer_${ now }`, username: `customer_${ now }`,
email: `customer_${ now }@woocommercecoretestsuite.com`, email: `customer_${ now }@woocommercecoretestsuite.com`,
@ -40,7 +45,8 @@ test.describe( 'Customers API tests: CRUD', () => {
password: 'password', password: 'password',
name: 'Jane', name: 'Jane',
}, },
} ); }
);
const userResponseJSON = await userResponse.json(); const userResponseJSON = await userResponse.json();
// set subscriber user id to newly created user // set subscriber user id to newly created user
subscriberUserId = userResponseJSON.id; subscriberUserId = userResponseJSON.id;
@ -85,7 +91,9 @@ test.describe( 'Customers API tests: CRUD', () => {
*/ */
test( 'can retrieve admin user', async ( { request } ) => { test( 'can retrieve admin user', async ( { request } ) => {
// call API to retrieve the previously saved customer // call API to retrieve the previously saved customer
const response = await request.get( '/wp-json/wc/v3/customers/1' ); const response = await request.get(
'/wp-json/wc/v3/customers/1'
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( responseJSON.is_paying_customer ).toEqual( false ); expect( responseJSON.is_paying_customer ).toEqual( false );
@ -106,20 +114,28 @@ test.describe( 'Customers API tests: CRUD', () => {
expect( responseJSON.role ).toEqual( 'subscriber' ); expect( responseJSON.role ).toEqual( 'subscriber' );
} ); } );
test( 'retrieve user with id 0 is invalid', async ( { request } ) => { test( 'retrieve user with id 0 is invalid', async ( {
request,
} ) => {
// call API to retrieve the previously saved customer // call API to retrieve the previously saved customer
const response = await request.get( '/wp-json/wc/v3/customers/0' ); const response = await request.get(
'/wp-json/wc/v3/customers/0'
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 404 ); expect( response.status() ).toEqual( 404 );
expect( responseJSON.code ).toEqual( expect( responseJSON.code ).toEqual(
'woocommerce_rest_invalid_id' 'woocommerce_rest_invalid_id'
); );
expect( responseJSON.message ).toEqual( 'Invalid resource ID.' ); expect( responseJSON.message ).toEqual(
'Invalid resource ID.'
);
} ); } );
test( 'can retrieve customers', async ( { request } ) => { test( 'can retrieve customers', async ( { request } ) => {
// call API to retrieve all customers should initially return empty array // call API to retrieve all customers should initially return empty array
const response = await request.get( '/wp-json/wc/v3/customers' ); const response = await request.get(
'/wp-json/wc/v3/customers'
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( Array.isArray( responseJSON ) ).toBe( true ); expect( Array.isArray( responseJSON ) ).toBe( true );
@ -131,11 +147,14 @@ test.describe( 'Customers API tests: CRUD', () => {
// call API to retrieve all customers should initially return empty array // call API to retrieve all customers should initially return empty array
// unless the role 'all' is passed as a search string, in which case the admin // unless the role 'all' is passed as a search string, in which case the admin
// and subscriber users will be returned // and subscriber users will be returned
const response = await request.get( '/wp-json/wc/v3/customers', { const response = await request.get(
'/wp-json/wc/v3/customers',
{
params: { params: {
role: 'all', role: 'all',
}, },
} ); }
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( Array.isArray( responseJSON ) ).toBe( true ); expect( Array.isArray( responseJSON ) ).toBe( true );
@ -146,9 +165,12 @@ test.describe( 'Customers API tests: CRUD', () => {
test.describe( 'Create a customer', () => { test.describe( 'Create a customer', () => {
test( 'can create a customer', async ( { request } ) => { test( 'can create a customer', async ( { request } ) => {
// call API to create a customer // call API to create a customer
const response = await request.post( '/wp-json/wc/v3/customers', { const response = await request.post(
'/wp-json/wc/v3/customers',
{
data: customer, data: customer,
} ); }
);
const responseJSON = await response.json(); const responseJSON = await response.json();
// Save the customer ID. It will be used by the retrieve, update, and delete tests. // Save the customer ID. It will be used by the retrieve, update, and delete tests.
@ -178,7 +200,9 @@ test.describe( 'Customers API tests: CRUD', () => {
request, request,
} ) => { } ) => {
// call API to retrieve all customers // call API to retrieve all customers
const response = await request.get( '/wp-json/wc/v3/customers' ); const response = await request.get(
'/wp-json/wc/v3/customers'
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( Array.isArray( responseJSON ) ).toBe( true ); expect( Array.isArray( responseJSON ) ).toBe( true );
@ -187,13 +211,17 @@ test.describe( 'Customers API tests: CRUD', () => {
} ); } );
test.describe( 'Update a customer', () => { test.describe( 'Update a customer', () => {
test( `can update the admin user/customer`, async ( { request } ) => { test( `can update the admin user/customer`, async ( {
request,
} ) => {
/** /**
* update customer names (regular, billing and shipping) to admin * update customer names (regular, billing and shipping) to admin
* (these were initialised blank when the environment is created, * (these were initialised blank when the environment is created,
* (https://github.com/woocommerce/woocommerce/tree/trunk/plugins/woocommerce/tests/e2e-pw#woocommerce-playwright-end-to-end-tests * (https://github.com/woocommerce/woocommerce/tree/trunk/plugins/woocommerce/tests/e2e-pw#woocommerce-playwright-end-to-end-tests
*/ */
const response = await request.put( `/wp-json/wc/v3/customers/1`, { const response = await request.put(
`/wp-json/wc/v3/customers/1`,
{
data: { data: {
first_name: 'admin', first_name: 'admin',
billing: { billing: {
@ -203,7 +231,8 @@ test.describe( 'Customers API tests: CRUD', () => {
first_name: 'admin', first_name: 'admin',
}, },
}, },
} ); }
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( responseJSON.first_name ).toEqual( 'admin' ); expect( responseJSON.first_name ).toEqual( 'admin' );
@ -213,7 +242,9 @@ test.describe( 'Customers API tests: CRUD', () => {
test( 'retrieve after update admin', async ( { request } ) => { test( 'retrieve after update admin', async ( { request } ) => {
// call API to retrieve the admin customer we updated above // call API to retrieve the admin customer we updated above
const response = await request.get( '/wp-json/wc/v3/customers/1' ); const response = await request.get(
'/wp-json/wc/v3/customers/1'
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( responseJSON.first_name ).toEqual( 'admin' ); expect( responseJSON.first_name ).toEqual( 'admin' );
@ -295,7 +326,9 @@ test.describe( 'Customers API tests: CRUD', () => {
} ); } );
test.describe( 'Delete a customer', () => { test.describe( 'Delete a customer', () => {
test( 'can permanently delete an customer', async ( { request } ) => { test( 'can permanently delete an customer', async ( {
request,
} ) => {
// Delete the customer. // Delete the customer.
const response = await request.delete( const response = await request.delete(
`/wp-json/wc/v3/customers/${ customerId }`, `/wp-json/wc/v3/customers/${ customerId }`,
@ -401,11 +434,14 @@ test.describe( 'Customers API tests: CRUD', () => {
// Verify that the 2 new customers were created // Verify that the 2 new customers were created
const actualCustomers = responseJSON.create; const actualCustomers = responseJSON.create;
expect( actualCustomers ).toHaveLength( expectedCustomers.length ); expect( actualCustomers ).toHaveLength(
expectedCustomers.length
);
for ( let i = 0; i < actualCustomers.length; i++ ) { for ( let i = 0; i < actualCustomers.length; i++ ) {
const { id, first_name } = actualCustomers[ i ]; const { id, first_name } = actualCustomers[ i ];
const expectedCustomerName = expectedCustomers[ i ].first_name; const expectedCustomerName =
expectedCustomers[ i ].first_name;
expect( id ).toBeDefined(); expect( id ).toBeDefined();
expect( first_name ).toEqual( expectedCustomerName ); expect( first_name ).toEqual( expectedCustomerName );
@ -498,4 +534,5 @@ test.describe( 'Customers API tests: CRUD', () => {
} }
} ); } );
} ); } );
} ); }
);

View File

@ -208,7 +208,10 @@ test.describe( 'Orders API test', () => {
} ); } );
} ); } );
test( 'can add complex order', async ( { request } ) => { test(
'can add complex order',
{ tag: [ '@skip-on-default-pressable', '@skip-on-default-wpcom' ] },
async ( { request } ) => {
//ensure tax calculations are enabled //ensure tax calculations are enabled
await request.put( await request.put(
'/wp-json/wc/v3/settings/general/woocommerce_calc_taxes', '/wp-json/wc/v3/settings/general/woocommerce_calc_taxes',
@ -251,5 +254,6 @@ test.describe( 'Orders API test', () => {
expect( actualLineTaxTotal ).toEqual( expectedLineTaxTotal ); expect( actualLineTaxTotal ).toEqual( expectedLineTaxTotal );
} }
} ); }
);
} ); } );

View File

@ -34,7 +34,10 @@ const updatedCustomerShipping = {
phone: '123456789', phone: '123456789',
}; };
test.describe.serial( 'Orders API tests', () => { test.describe.serial(
'Orders API tests',
{ tag: [ '@skip-on-default-pressable', '@skip-on-default-wpcom' ] },
() => {
let orderId, sampleData; let orderId, sampleData;
test.beforeAll( async ( { request } ) => { test.beforeAll( async ( { request } ) => {
@ -175,11 +178,14 @@ test.describe.serial( 'Orders API tests', () => {
}; };
const createSampleTags = async () => { const createSampleTags = async () => {
const cool = await request.post( '/wp-json/wc/v3/products/tags', { const cool = await request.post(
'/wp-json/wc/v3/products/tags',
{
data: { data: {
name: 'Cool', name: 'Cool',
}, },
} ); }
);
const coolJSON = await cool.json(); const coolJSON = await cool.json();
return { return {
@ -1300,7 +1306,8 @@ test.describe.serial( 'Orders API tests', () => {
download_expiry: 0, download_expiry: 0,
external_url: external_url:
'https://mercantile.wordpress.org/product/wordpress-pennant/', 'https://mercantile.wordpress.org/product/wordpress-pennant/',
button_text: 'Buy on the WordPress swag store!', button_text:
'Buy on the WordPress swag store!',
tax_status: 'taxable', tax_status: 'taxable',
tax_class: '', tax_class: '',
manage_stock: false, manage_stock: false,
@ -1350,12 +1357,15 @@ test.describe.serial( 'Orders API tests', () => {
}; };
const createSampleGroupedProduct = async ( categories ) => { const createSampleGroupedProduct = async ( categories ) => {
const logoProducts = await request.get( '/wp-json/wc/v3/products', { const logoProducts = await request.get(
'/wp-json/wc/v3/products',
{
params: { params: {
search: 'logo', search: 'logo',
_fields: [ 'id' ], _fields: [ 'id' ],
}, },
} ); }
);
const logoProductsJSON = await logoProducts.json(); const logoProductsJSON = await logoProducts.json();
const groupedProducts = await request.post( const groupedProducts = await request.post(
@ -1460,7 +1470,8 @@ test.describe.serial( 'Orders API tests', () => {
featured: false, featured: false,
catalog_visibility: 'visible', catalog_visibility: 'visible',
description, description,
short_description: '<p>This is a variable product.</p>\n', short_description:
'<p>This is a variable product.</p>\n',
sku: 'woo-hoodie', sku: 'woo-hoodie',
price: '42', price: '42',
regular_price: '', regular_price: '',
@ -1745,7 +1756,8 @@ test.describe.serial( 'Orders API tests', () => {
featured: true, featured: true,
catalog_visibility: 'visible', catalog_visibility: 'visible',
description, description,
short_description: '<p>This is a variable product.</p>\n', short_description:
'<p>This is a variable product.</p>\n',
sku: 'woo-vneck-tee', sku: 'woo-vneck-tee',
price: '15', price: '15',
regular_price: '', regular_price: '',
@ -1984,7 +1996,9 @@ test.describe.serial( 'Orders API tests', () => {
}; };
const createSampleProductReviews = async ( simpleProducts ) => { const createSampleProductReviews = async ( simpleProducts ) => {
const cap = simpleProducts.find( ( p ) => p.name === 'Cap oxo' ); const cap = simpleProducts.find(
( p ) => p.name === 'Cap oxo'
);
const shirt = simpleProducts.find( const shirt = simpleProducts.find(
( p ) => p.name === 'T-Shirt oxo' ( p ) => p.name === 'T-Shirt oxo'
@ -2138,7 +2152,9 @@ test.describe.serial( 'Orders API tests', () => {
simpleProducts simpleProducts
); );
const orders = await createSampleProductOrders( simpleProducts ); const orders = await createSampleProductOrders(
simpleProducts
);
return { return {
categories, categories,
@ -2158,7 +2174,8 @@ test.describe.serial( 'Orders API tests', () => {
// create Sample Data function // create Sample Data function
const createSampleData = async () => { const createSampleData = async () => {
const testProductData = await productsTestSetupCreateSampleData(); const testProductData =
await productsTestSetupCreateSampleData();
const orderedProducts = { const orderedProducts = {
pocketHoodie: testProductData.simpleProducts.find( pocketHoodie: testProductData.simpleProducts.find(
( p ) => p.name === 'Hoodie with Pocket oxo' ( p ) => p.name === 'Hoodie with Pocket oxo'
@ -2268,7 +2285,9 @@ test.describe.serial( 'Orders API tests', () => {
const orders = []; const orders = [];
// Have "John" order all products. // Have "John" order all products.
Object.values( orderedProducts ).forEach( async ( product ) => { Object.values( orderedProducts ).forEach( async ( product ) => {
const order2 = await request.post( '/wp-json/wc/v3/orders', { const order2 = await request.post(
'/wp-json/wc/v3/orders',
{
data: { data: {
...orderBaseData, ...orderBaseData,
customer_id: johnJSON.id, customer_id: johnJSON.id,
@ -2284,7 +2303,8 @@ test.describe.serial( 'Orders API tests', () => {
}, },
], ],
}, },
} ); }
);
const orderJSON = await order2.json(); const orderJSON = await order2.json();
orders.push( orderJSON ); orders.push( orderJSON );
@ -2339,7 +2359,9 @@ test.describe.serial( 'Orders API tests', () => {
orders.push( order3JSON ); orders.push( order3JSON );
// Guest order. // Guest order.
const guestOrder = await request.post( '/wp-json/wc/v3/orders', { const guestOrder = await request.post(
'/wp-json/wc/v3/orders',
{
data: { data: {
...orderBaseData, ...orderBaseData,
billing: guestBillingAddress, billing: guestBillingAddress,
@ -2355,7 +2377,8 @@ test.describe.serial( 'Orders API tests', () => {
}, },
], ],
}, },
} ); }
);
const guestOrderJSON = await guestOrder.json(); const guestOrderJSON = await guestOrder.json();
// Create an order with all possible numerical fields (taxes, fees, refunds, etc). // Create an order with all possible numerical fields (taxes, fees, refunds, etc).
@ -2427,7 +2450,8 @@ test.describe.serial( 'Orders API tests', () => {
{ {
id: order4JSON.line_items[ 0 ].id, id: order4JSON.line_items[ 0 ].id,
quantity: 1, quantity: 1,
refund_total: order4JSON.line_items[ 0 ].total, refund_total:
order4JSON.line_items[ 0 ].total,
refund_tax: [ refund_tax: [
{ {
id: order4JSON.line_items[ 0 ] id: order4JSON.line_items[ 0 ]
@ -2494,11 +2518,14 @@ test.describe.serial( 'Orders API tests', () => {
] ); ] );
for ( const _order of orders ) { for ( const _order of orders ) {
await request.delete( `/wp-json/wc/v3/orders/${ _order.id }`, { await request.delete(
`/wp-json/wc/v3/orders/${ _order.id }`,
{
data: { data: {
force: true, force: true,
}, },
} ); }
);
} }
for ( const productId of productIds ) { for ( const productId of productIds ) {
@ -2552,7 +2579,9 @@ test.describe.serial( 'Orders API tests', () => {
); );
} }
for ( const shippingClass of Object.values( shippingClasses ) ) { for ( const shippingClass of Object.values(
shippingClasses
) ) {
await request.delete( await request.delete(
`/wp-json/wc/v3/products/shipping_classes/${ shippingClass.id }`, `/wp-json/wc/v3/products/shipping_classes/${ shippingClass.id }`,
{ {
@ -2583,14 +2612,19 @@ test.describe.serial( 'Orders API tests', () => {
for ( const _order of _sampleData.orders.concat( [ for ( const _order of _sampleData.orders.concat( [
_sampleData.guestOrderJSON, _sampleData.guestOrderJSON,
] ) ) { ] ) ) {
await request.delete( `/wp-json/wc/v3/orders/${ _order.id }`, { await request.delete(
`/wp-json/wc/v3/orders/${ _order.id }`,
{
data: { data: {
force: true, force: true,
}, },
} ); }
);
} }
for ( const customer of Object.values( _sampleData.customers ) ) { for ( const customer of Object.values(
_sampleData.customers
) ) {
await request.delete( await request.delete(
`/wp-json/wc/v3/customers/${ customer.id }`, `/wp-json/wc/v3/customers/${ customer.id }`,
{ {
@ -2711,7 +2745,9 @@ test.describe.serial( 'Orders API tests', () => {
acc[ id ] = 1; acc[ id ] = 1;
return acc; return acc;
}, {} ); }, {} );
expect( Object.keys( allOrderIds ) ).toHaveLength( pageSize * 2 ); expect( Object.keys( allOrderIds ) ).toHaveLength(
pageSize * 2
);
// Verify that offset takes precedent over page number. // Verify that offset takes precedent over page number.
const page2Offset = await request.get( 'wp-json/wc/v3/orders', { const page2Offset = await request.get( 'wp-json/wc/v3/orders', {
@ -2770,7 +2806,9 @@ test.describe.serial( 'Orders API tests', () => {
const allOrdersJSON = await allOrders.json(); const allOrdersJSON = await allOrders.json();
expect( allOrders.status() ).toEqual( 200 ); expect( allOrders.status() ).toEqual( 200 );
const allOrdersIds = allOrdersJSON.map( ( _order ) => _order.id ); const allOrdersIds = allOrdersJSON.map(
( _order ) => _order.id
);
expect( allOrdersIds ).toHaveLength( ORDERS_COUNT ); expect( allOrdersIds ).toHaveLength( ORDERS_COUNT );
const ordersToFilter = [ const ordersToFilter = [
@ -3007,7 +3045,10 @@ test.describe.serial( 'Orders API tests', () => {
_order.tax_lines.forEach( ( taxLine ) => { _order.tax_lines.forEach( ( taxLine ) => {
expectPrecisionToMatch( taxLine.tax_total, dp ); expectPrecisionToMatch( taxLine.tax_total, dp );
expectPrecisionToMatch( taxLine.shipping_tax_total, dp ); expectPrecisionToMatch(
taxLine.shipping_tax_total,
dp
);
} ); } );
_order.shipping_lines.forEach( ( shippingLine ) => { _order.shipping_lines.forEach( ( shippingLine ) => {
@ -3262,4 +3303,5 @@ test.describe.serial( 'Orders API tests', () => {
} ); } );
} ); } );
} ); } );
} ); }
);

View File

@ -1,9 +1,14 @@
const { test, expect } = require( '../../../fixtures/api-tests-fixtures' ); const { test, expect } = require( '../../../fixtures/api-tests-fixtures' );
test.describe( 'Payment Gateways API tests', () => { test.describe( 'Payment Gateways API tests', () => {
test( 'can view all payment gateways', async ( { request } ) => { test(
'can view all payment gateways',
{ tag: [ '@skip-on-default-pressable', '@skip-on-default-wpcom' ] },
async ( { request } ) => {
// call API to retrieve the payment gateways // call API to retrieve the payment gateways
const response = await request.get( '/wp-json/wc/v3/payment_gateways' ); const response = await request.get(
'/wp-json/wc/v3/payment_gateways'
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( Array.isArray( responseJSON ) ).toBe( true ); expect( Array.isArray( responseJSON ) ).toBe( true );
@ -164,7 +169,8 @@ test.describe( 'Payment Gateways API tests', () => {
} ), } ),
] ) ] )
); );
} ); }
);
test( 'can view a payment gateway', async ( { request } ) => { test( 'can view a payment gateway', async ( { request } ) => {
// call API to retrieve a single payment gateway // call API to retrieve a single payment gateway

View File

@ -2230,7 +2230,10 @@ test.describe( 'Products API tests: List All Products', () => {
await deleteSampleData( sampleData ); await deleteSampleData( sampleData );
}, 10000 ); }, 10000 );
test.describe( 'List all products', () => { test.describe(
'List all products',
{ tag: [ '@skip-on-default-pressable', '@skip-on-default-wpcom' ] },
() => {
test( 'defaults', async ( { request } ) => { test( 'defaults', async ( { request } ) => {
const result = await request.get( 'wp-json/wc/v3/products', { const result = await request.get( 'wp-json/wc/v3/products', {
params: { params: {
@ -2284,17 +2287,22 @@ test.describe( 'Products API tests: List All Products', () => {
acc[ product.id ] = 1; acc[ product.id ] = 1;
return acc; return acc;
}, {} ); }, {} );
expect( Object.keys( allProductIds ) ).toHaveLength( pageSize * 2 ); expect( Object.keys( allProductIds ) ).toHaveLength(
pageSize * 2
);
// Verify that offset takes precedent over page number. // Verify that offset takes precedent over page number.
const page2Offset = await request.get( 'wp-json/wc/v3/products', { const page2Offset = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
per_page: pageSize, per_page: pageSize,
page: 2, page: 2,
offset: pageSize + 1, offset: pageSize + 1,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const page2OffsetJSON = await page2Offset.json(); const page2OffsetJSON = await page2Offset.json();
// The offset pushes the result set 1 product past the start of page 2. // The offset pushes the result set 1 product past the start of page 2.
expect( page2OffsetJSON ).toEqual( expect( page2OffsetJSON ).toEqual(
@ -2358,16 +2366,21 @@ test.describe( 'Products API tests: List All Products', () => {
const result2JSON = await result2.json(); const result2JSON = await result2.json();
expect( result2.status() ).toEqual( 200 ); expect( result2.status() ).toEqual( 200 );
expect( result2JSON ).toHaveLength( 1 ); expect( result2JSON ).toHaveLength( 1 );
expect( result2JSON[ 0 ].name ).toBe( 'Hoodie with Pocket xxx' ); expect( result2JSON[ 0 ].name ).toBe(
'Hoodie with Pocket xxx'
);
} ); } );
test( 'inclusion / exclusion', async ( { request } ) => { test( 'inclusion / exclusion', async ( { request } ) => {
const allProducts = await request.get( 'wp-json/wc/v3/products', { const allProducts = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
per_page: 20, per_page: 20,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const allProductsJSON = await allProducts.json(); const allProductsJSON = await allProducts.json();
expect( allProducts.status() ).toEqual( 200 ); expect( allProducts.status() ).toEqual( 200 );
const allProductIds = allProductsJSON.map( const allProductIds = allProductsJSON.map(
@ -2540,7 +2553,9 @@ test.describe( 'Products API tests: List All Products', () => {
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
expect( result1JSON ).toHaveLength( featured.length ); expect( result1JSON ).toHaveLength( featured.length );
expect( result1JSON ).toEqual( expect.arrayContaining( featured ) ); expect( result1JSON ).toEqual(
expect.arrayContaining( featured )
);
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get( 'wp-json/wc/v3/products', {
params: { params: {
@ -2555,7 +2570,10 @@ test.describe( 'Products API tests: List All Products', () => {
); );
} ); } );
test( 'categories', async ( { request } ) => { test(
'categories',
{ tag: '@skip-on-default-wpcom' },
async ( { request } ) => {
const accessory = [ const accessory = [
expect.objectContaining( { expect.objectContaining( {
name: 'Beanie xxx', name: 'Beanie xxx',
@ -2577,32 +2595,43 @@ test.describe( 'Products API tests: List All Products', () => {
]; ];
// Verify that subcategories are included. // Verify that subcategories are included.
const result1 = await request.get( 'wp-json/wc/v3/products', { const result1 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
per_page: 20, per_page: 20,
category: sampleData.categories.clothingJSON.id, category: sampleData.categories.clothingJSON.id,
}, },
} ); }
);
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
expect( result1JSON ).toEqual( expect( result1JSON ).toEqual(
expect.arrayContaining( accessory ) expect.arrayContaining( accessory )
); );
expect( result1JSON ).toEqual( expect.arrayContaining( hoodies ) ); expect( result1JSON ).toEqual(
expect.arrayContaining( hoodies )
);
// Verify sibling categories are not. // Verify sibling categories are not.
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
category: sampleData.categories.hoodiesJSON.id, category: sampleData.categories.hoodiesJSON.id,
}, },
} ); }
);
const result2JSON = await result2.json(); const result2JSON = await result2.json();
expect( result2.status() ).toEqual( 200 ); expect( result2.status() ).toEqual( 200 );
expect( result2JSON ).toEqual( expect( result2JSON ).toEqual(
expect.not.arrayContaining( accessory ) expect.not.arrayContaining( accessory )
); );
expect( result2JSON ).toEqual( expect.arrayContaining( hoodies ) ); expect( result2JSON ).toEqual(
} ); expect.arrayContaining( hoodies )
);
}
);
test( 'on sale', async ( { request } ) => { test( 'on sale', async ( { request } ) => {
const onSale = [ const onSale = [
@ -2638,7 +2667,9 @@ test.describe( 'Products API tests: List All Products', () => {
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
expect( result1JSON ).toHaveLength( onSale.length ); expect( result1JSON ).toHaveLength( onSale.length );
expect( result1JSON ).toEqual( expect.arrayContaining( onSale ) ); expect( result1JSON ).toEqual(
expect.arrayContaining( onSale )
);
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get( 'wp-json/wc/v3/products', {
params: { params: {
@ -2737,7 +2768,9 @@ test.describe( 'Products API tests: List All Products', () => {
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
expect( result1JSON ).toHaveLength( before.length ); expect( result1JSON ).toHaveLength( before.length );
expect( result1JSON ).toEqual( expect.arrayContaining( before ) ); expect( result1JSON ).toEqual(
expect.arrayContaining( before )
);
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get( 'wp-json/wc/v3/products', {
params: { params: {
@ -2751,7 +2784,9 @@ test.describe( 'Products API tests: List All Products', () => {
expect.not.arrayContaining( before ) expect.not.arrayContaining( before )
); );
expect( result2JSON ).toHaveLength( after.length ); expect( result2JSON ).toHaveLength( after.length );
expect( result2JSON ).toEqual( expect.arrayContaining( after ) ); expect( result2JSON ).toEqual(
expect.arrayContaining( after )
);
} ); } );
test( 'attributes', async ( { request } ) => { test( 'attributes', async ( { request } ) => {
@ -2814,7 +2849,8 @@ test.describe( 'Products API tests: List All Products', () => {
test( 'shipping class', async ( { request } ) => { test( 'shipping class', async ( { request } ) => {
const result = await request.get( 'wp-json/wc/v3/products', { const result = await request.get( 'wp-json/wc/v3/products', {
params: { params: {
shipping_class: sampleData.shippingClasses.freightJSON.id, shipping_class:
sampleData.shippingClasses.freightJSON.id,
}, },
} ); } );
const resultJSON = await result.json(); const resultJSON = await result.json();
@ -2947,51 +2983,64 @@ test.describe( 'Products API tests: List All Products', () => {
test( 'default', async ( { request } ) => { test( 'default', async ( { request } ) => {
// Default = date desc. // Default = date desc.
const result = await request.get( 'wp-json/wc/v3/products', { const result = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const resultJSON = await result.json(); const resultJSON = await result.json();
expect( result.status() ).toEqual( 200 ); expect( result.status() ).toEqual( 200 );
// Verify all dates are in descending order. // Verify all dates are in descending order.
let lastDate = Date.now(); let lastDate = Date.now();
resultJSON.forEach( ( { date_created_gmt } ) => { resultJSON.forEach( ( { date_created_gmt } ) => {
const created = Date.parse( date_created_gmt + '.000Z' ); const created = Date.parse(
date_created_gmt + '.000Z'
);
expect( lastDate ).toBeGreaterThan( created ); expect( lastDate ).toBeGreaterThan( created );
lastDate = created; lastDate = created;
} ); } );
} ); } );
test( 'date', async ( { request } ) => { test( 'date', async ( { request } ) => {
const result = await request.get( 'wp-json/wc/v3/products', { const result = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'asc', order: 'asc',
orderby: 'date', orderby: 'date',
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const resultJSON = await result.json(); const resultJSON = await result.json();
expect( result.status() ).toEqual( 200 ); expect( result.status() ).toEqual( 200 );
// Verify all dates are in ascending order. // Verify all dates are in ascending order.
let lastDate = 0; let lastDate = 0;
resultJSON.forEach( ( { date_created_gmt } ) => { resultJSON.forEach( ( { date_created_gmt } ) => {
const created = Date.parse( date_created_gmt + '.000Z' ); const created = Date.parse(
date_created_gmt + '.000Z'
);
expect( created ).toBeGreaterThan( lastDate ); expect( created ).toBeGreaterThan( lastDate );
lastDate = created; lastDate = created;
} ); } );
} ); } );
test( 'id', async ( { request } ) => { test( 'id', async ( { request } ) => {
const result1 = await request.get( 'wp-json/wc/v3/products', { const result1 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'asc', order: 'asc',
orderby: 'id', orderby: 'id',
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
@ -3002,13 +3051,16 @@ test.describe( 'Products API tests: List All Products', () => {
lastId = id; lastId = id;
} ); } );
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'desc', order: 'desc',
orderby: 'id', orderby: 'id',
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result2JSON = await result2.json(); const result2JSON = await result2.json();
expect( result2.status() ).toEqual( 200 ); expect( result2.status() ).toEqual( 200 );
@ -3021,14 +3073,17 @@ test.describe( 'Products API tests: List All Products', () => {
} ); } );
test( 'title', async ( { request } ) => { test( 'title', async ( { request } ) => {
const result1 = await request.get( 'wp-json/wc/v3/products', { const result1 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'asc', order: 'asc',
orderby: 'title', orderby: 'title',
per_page: productNamesAsc.length, per_page: productNamesAsc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
@ -3037,14 +3092,17 @@ test.describe( 'Products API tests: List All Products', () => {
expect( name ).toBe( productNamesAsc[ idx ] ); expect( name ).toBe( productNamesAsc[ idx ] );
} ); } );
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'desc', order: 'desc',
orderby: 'title', orderby: 'title',
per_page: productNamesDesc.length, per_page: productNamesDesc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result2JSON = await result2.json(); const result2JSON = await result2.json();
expect( result2.status() ).toEqual( 200 ); expect( result2.status() ).toEqual( 200 );
@ -3063,14 +3121,17 @@ test.describe( 'Products API tests: List All Products', () => {
...productNamesBySlugAsc, ...productNamesBySlugAsc,
].reverse(); ].reverse();
const result1 = await request.get( 'wp-json/wc/v3/products', { const result1 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'asc', order: 'asc',
orderby: 'slug', orderby: 'slug',
per_page: productNamesBySlugAsc.length, per_page: productNamesBySlugAsc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
@ -3079,14 +3140,17 @@ test.describe( 'Products API tests: List All Products', () => {
expect( name ).toBe( productNamesBySlugAsc[ idx ] ); expect( name ).toBe( productNamesBySlugAsc[ idx ] );
} ); } );
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'desc', order: 'desc',
orderby: 'slug', orderby: 'slug',
per_page: productNamesBySlugDesc.length, per_page: productNamesBySlugDesc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result2JSON = await result2.json(); const result2JSON = await result2.json();
expect( result2.status() ).toEqual( 200 ); expect( result2.status() ).toEqual( 200 );
@ -3119,14 +3183,17 @@ test.describe( 'Products API tests: List All Products', () => {
'Belt xxx', 'Belt xxx',
'Sunglasses xxx', 'Sunglasses xxx',
]; ];
const result1 = await request.get( 'wp-json/wc/v3/products', { const result1 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'asc', order: 'asc',
orderby: 'price', orderby: 'price',
per_page: productNamesMinPriceAsc.length, per_page: productNamesMinPriceAsc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
expect( result1JSON ).toHaveLength( expect( result1JSON ).toHaveLength(
@ -3163,14 +3230,17 @@ test.describe( 'Products API tests: List All Products', () => {
'Parent Product xxx', 'Parent Product xxx',
]; ];
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'desc', order: 'desc',
orderby: 'price', orderby: 'price',
per_page: productNamesMaxPriceDesc.length, per_page: productNamesMaxPriceDesc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result2JSON = await result2.json(); const result2JSON = await result2.json();
expect( result2.status() ).toEqual( 200 ); expect( result2.status() ).toEqual( 200 );
expect( result2JSON ).toHaveLength( expect( result2JSON ).toHaveLength(
@ -3192,13 +3262,16 @@ test.describe( 'Products API tests: List All Products', () => {
sampleData.hierarchicalProducts.parentJSON.id, sampleData.hierarchicalProducts.parentJSON.id,
]; ];
const result1 = await request.get( 'wp-json/wc/v3/products', { const result1 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'asc', order: 'asc',
orderby: 'include', orderby: 'include',
include: includeIds.join( ',' ), include: includeIds.join( ',' ),
}, },
} ); }
);
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
@ -3209,13 +3282,16 @@ test.describe( 'Products API tests: List All Products', () => {
expect( id ).toBe( includeIds[ idx ] ); expect( id ).toBe( includeIds[ idx ] );
} ); } );
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'desc', order: 'desc',
orderby: 'include', orderby: 'include',
include: includeIds.join( ',' ), include: includeIds.join( ',' ),
}, },
} ); }
);
const result2JSON = await result2.json(); const result2JSON = await result2.json();
expect( result2.status() ).toEqual( 200 ); expect( result2.status() ).toEqual( 200 );
expect( result2JSON ).toHaveLength( includeIds.length ); expect( result2JSON ).toHaveLength( includeIds.length );
@ -3227,14 +3303,17 @@ test.describe( 'Products API tests: List All Products', () => {
} ); } );
test( 'rating (desc)', async ( { request } ) => { test( 'rating (desc)', async ( { request } ) => {
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'desc', order: 'desc',
orderby: 'rating', orderby: 'rating',
per_page: productNamesByRatingDesc.length, per_page: productNamesByRatingDesc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result2JSON = await result2.json(); const result2JSON = await result2.json();
expect( result2.status() ).toEqual( 200 ); expect( result2.status() ).toEqual( 200 );
@ -3247,14 +3326,17 @@ test.describe( 'Products API tests: List All Products', () => {
// This case will remain skipped until ratings can be sorted ascending. // This case will remain skipped until ratings can be sorted ascending.
// See: https://github.com/woocommerce/woocommerce/issues/30354#issuecomment-925955099. // See: https://github.com/woocommerce/woocommerce/issues/30354#issuecomment-925955099.
test.skip( 'rating (asc)', async ( { request } ) => { test.skip( 'rating (asc)', async ( { request } ) => {
const result1 = await request.get( 'wp-json/wc/v3/products', { const result1 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'asc', order: 'asc',
orderby: 'rating', orderby: 'rating',
per_page: productNamesByRatingAsc.length, per_page: productNamesByRatingAsc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
const result1JSON = await result1.json(); const result1JSON = await result1.json();
@ -3267,40 +3349,51 @@ test.describe( 'Products API tests: List All Products', () => {
// This case will remain skipped until popularity can be sorted ascending. // This case will remain skipped until popularity can be sorted ascending.
// See: https://github.com/woocommerce/woocommerce/issues/30354#issuecomment-925955099. // See: https://github.com/woocommerce/woocommerce/issues/30354#issuecomment-925955099.
test.skip( 'popularity (asc)', async ( { request } ) => { test.skip( 'popularity (asc)', async ( { request } ) => {
const result1 = await request.get( 'wp-json/wc/v3/products', { const result1 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'asc', order: 'asc',
orderby: 'popularity', orderby: 'popularity',
per_page: productNamesByPopularityAsc.length, per_page: productNamesByPopularityAsc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result1JSON = await result1.json(); const result1JSON = await result1.json();
expect( result1.status() ).toEqual( 200 ); expect( result1.status() ).toEqual( 200 );
// Verify all results are in ascending order. // Verify all results are in ascending order.
result1JSON.forEach( ( { name }, idx ) => { result1JSON.forEach( ( { name }, idx ) => {
expect( name ).toBe( productNamesByPopularityAsc[ idx ] ); expect( name ).toBe(
productNamesByPopularityAsc[ idx ]
);
} ); } );
} ); } );
test( 'popularity (desc)', async ( { request } ) => { test( 'popularity (desc)', async ( { request } ) => {
const result2 = await request.get( 'wp-json/wc/v3/products', { const result2 = await request.get(
'wp-json/wc/v3/products',
{
params: { params: {
order: 'desc', order: 'desc',
orderby: 'popularity', orderby: 'popularity',
per_page: productNamesByPopularityDesc.length, per_page: productNamesByPopularityDesc.length,
search: 'xxx', search: 'xxx',
}, },
} ); }
);
const result2JSON = await result2.json(); const result2JSON = await result2.json();
expect( result2.status() ).toEqual( 200 ); expect( result2.status() ).toEqual( 200 );
// Verify all results are in descending order. // Verify all results are in descending order.
result2JSON.forEach( ( { name }, idx ) => { result2JSON.forEach( ( { name }, idx ) => {
expect( name ).toBe( productNamesByPopularityDesc[ idx ] ); expect( name ).toBe(
} ); productNamesByPopularityDesc[ idx ]
);
} ); } );
} ); } );
} ); } );
}
);
} ); } );

View File

@ -589,7 +589,10 @@ test.describe( 'Products API tests: CRUD', () => {
} ); } );
} ); } );
test.describe( 'Product review tests: CRUD', () => { test.describe(
'Product review tests: CRUD',
{ tag: '@skip-on-default-wpcom' },
() => {
let productReviewId; let productReviewId;
let reviewsTestProduct; let reviewsTestProduct;
@ -616,7 +619,9 @@ test.describe( 'Products API tests: CRUD', () => {
expect( response.status() ).toEqual( 201 ); expect( response.status() ).toEqual( 201 );
expect( typeof productReviewId ).toEqual( 'number' ); expect( typeof productReviewId ).toEqual( 'number' );
expect( responseJSON.id ).toEqual( productReviewId ); expect( responseJSON.id ).toEqual( productReviewId );
expect( responseJSON.product_name ).toEqual( 'A Simple Product' ); expect( responseJSON.product_name ).toEqual(
'A Simple Product'
);
expect( responseJSON.status ).toEqual( 'approved' ); expect( responseJSON.status ).toEqual( 'approved' );
expect( responseJSON.reviewer ).toEqual( 'John Doe' ); expect( responseJSON.reviewer ).toEqual( 'John Doe' );
expect( responseJSON.reviewer_email ).toEqual( expect( responseJSON.reviewer_email ).toEqual(
@ -684,8 +689,12 @@ test.describe( 'Products API tests: CRUD', () => {
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( responseJSON.id ).toEqual( productReviewId ); expect( responseJSON.id ).toEqual( productReviewId );
expect( responseJSON.product_id ).toEqual( reviewsTestProduct.id ); expect( responseJSON.product_id ).toEqual(
expect( responseJSON.product_name ).toEqual( 'A Simple Product' ); reviewsTestProduct.id
);
expect( responseJSON.product_name ).toEqual(
'A Simple Product'
);
expect( responseJSON.status ).toEqual( 'approved' ); expect( responseJSON.status ).toEqual( 'approved' );
expect( responseJSON.reviewer ).toEqual( 'John Doe' ); expect( responseJSON.reviewer ).toEqual( 'John Doe' );
expect( responseJSON.reviewer_email ).toEqual( expect( responseJSON.reviewer_email ).toEqual(
@ -722,8 +731,12 @@ test.describe( 'Products API tests: CRUD', () => {
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( responseJSON.id ).toEqual( productReviewId ); expect( responseJSON.id ).toEqual( productReviewId );
expect( responseJSON.product_id ).toEqual( reviewsTestProduct.id ); expect( responseJSON.product_id ).toEqual(
expect( responseJSON.product_name ).toEqual( 'A Simple Product' ); reviewsTestProduct.id
);
expect( responseJSON.product_name ).toEqual(
'A Simple Product'
);
expect( responseJSON.status ).toEqual( 'approved' ); expect( responseJSON.status ).toEqual( 'approved' );
expect( responseJSON.reviewer ).toEqual( 'John Doe' ); expect( responseJSON.reviewer ).toEqual( 'John Doe' );
expect( responseJSON.reviewer_email ).toEqual( expect( responseJSON.reviewer_email ).toEqual(
@ -752,7 +765,9 @@ test.describe( 'Products API tests: CRUD', () => {
const getDeletedProductReviewResponse = await request.get( const getDeletedProductReviewResponse = await request.get(
`wp-json/wc/v3/products/reviews/${ productReviewId }` `wp-json/wc/v3/products/reviews/${ productReviewId }`
); );
expect( getDeletedProductReviewResponse.status() ).toEqual( 404 ); expect( getDeletedProductReviewResponse.status() ).toEqual(
404
);
} ); } );
test( 'can batch update product reviews', async ( { request } ) => { test( 'can batch update product reviews', async ( { request } ) => {
@ -788,7 +803,9 @@ test.describe( 'Products API tests: CRUD', () => {
expect( responseJSON.create[ 0 ].review ).toEqual( expect( responseJSON.create[ 0 ].review ).toEqual(
'Nice product!' 'Nice product!'
); );
expect( responseJSON.create[ 0 ].reviewer ).toEqual( 'John Doe' ); expect( responseJSON.create[ 0 ].reviewer ).toEqual(
'John Doe'
);
expect( responseJSON.create[ 0 ].reviewer_email ).toEqual( expect( responseJSON.create[ 0 ].reviewer_email ).toEqual(
'john.doe@example.com' 'john.doe@example.com'
); );
@ -800,7 +817,9 @@ test.describe( 'Products API tests: CRUD', () => {
expect( responseJSON.create[ 1 ].review ).toEqual( expect( responseJSON.create[ 1 ].review ).toEqual(
'I love this thing!' 'I love this thing!'
); );
expect( responseJSON.create[ 1 ].reviewer ).toEqual( 'Jane Doe' ); expect( responseJSON.create[ 1 ].reviewer ).toEqual(
'Jane Doe'
);
expect( responseJSON.create[ 1 ].reviewer_email ).toEqual( expect( responseJSON.create[ 1 ].reviewer_email ).toEqual(
'Jane.doe@example.com' 'Jane.doe@example.com'
); );
@ -833,7 +852,8 @@ test.describe( 'Products API tests: CRUD', () => {
}, },
} }
); );
const responseBatchUpdateJSON = await responseBatchUpdate.json(); const responseBatchUpdateJSON =
await responseBatchUpdate.json();
const review3Id = responseBatchUpdateJSON.create[ 0 ].id; const review3Id = responseBatchUpdateJSON.create[ 0 ].id;
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
@ -851,7 +871,9 @@ test.describe( 'Products API tests: CRUD', () => {
const getDeletedProductReviewResponse = await request.get( const getDeletedProductReviewResponse = await request.get(
`wp-json/wc/v3/products/reviews/${ review2Id }` `wp-json/wc/v3/products/reviews/${ review2Id }`
); );
expect( getDeletedProductReviewResponse.status() ).toEqual( 404 ); expect( getDeletedProductReviewResponse.status() ).toEqual(
404
);
// Batch delete the created tags // Batch delete the created tags
await request.post( `wp-json/wc/v3/products/reviews/batch`, { await request.post( `wp-json/wc/v3/products/reviews/batch`, {
@ -860,7 +882,8 @@ test.describe( 'Products API tests: CRUD', () => {
}, },
} ); } );
} ); } );
} ); }
);
test.describe( 'Product shipping classes tests: CRUD', () => { test.describe( 'Product shipping classes tests: CRUD', () => {
let productShippingClassId; let productShippingClassId;
@ -958,9 +981,10 @@ test.describe( 'Products API tests: CRUD', () => {
); );
} ); } );
test( 'can batch update product shipping classes', async ( { test(
request, 'can batch update product shipping classes',
} ) => { { tag: [ '@skip-on-default-pressable', '@skip-on-default-wpcom' ] },
async ( { request } ) => {
// Batch create product shipping classes. // Batch create product shipping classes.
const response = await request.post( const response = await request.post(
`wp-json/wc/v3/products/shipping_classes/batch`, `wp-json/wc/v3/products/shipping_classes/batch`,
@ -979,8 +1003,12 @@ test.describe( 'Products API tests: CRUD', () => {
); );
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( responseJSON.create[ 0 ].name ).toEqual( 'Small Items' ); expect( responseJSON.create[ 0 ].name ).toEqual(
expect( responseJSON.create[ 1 ].name ).toEqual( 'Large Items' ); 'Small Items'
);
expect( responseJSON.create[ 1 ].name ).toEqual(
'Large Items'
);
const shippingClass1Id = responseJSON.create[ 0 ].id; const shippingClass1Id = responseJSON.create[ 0 ].id;
const shippingClass2Id = responseJSON.create[ 1 ].id; const shippingClass2Id = responseJSON.create[ 1 ].id;
@ -1004,7 +1032,8 @@ test.describe( 'Products API tests: CRUD', () => {
}, },
} }
); );
const responseBatchUpdateJSON = await responseBatchUpdate.json(); const responseBatchUpdateJSON =
await responseBatchUpdate.json();
const shippingClass3Id = responseBatchUpdateJSON.create[ 0 ].id; const shippingClass3Id = responseBatchUpdateJSON.create[ 0 ].id;
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
@ -1018,12 +1047,13 @@ test.describe( 'Products API tests: CRUD', () => {
); );
// Verify that the product tag can no longer be retrieved. // Verify that the product tag can no longer be retrieved.
const getDeletedProductShippingClassResponse = await request.get( const getDeletedProductShippingClassResponse =
await request.get(
`wp-json/wc/v3/products/shipping_classes/${ shippingClass2Id }` `wp-json/wc/v3/products/shipping_classes/${ shippingClass2Id }`
); );
expect( getDeletedProductShippingClassResponse.status() ).toEqual( expect(
404 getDeletedProductShippingClassResponse.status()
); ).toEqual( 404 );
// Batch delete the created tags // Batch delete the created tags
await request.post( await request.post(
@ -1034,7 +1064,8 @@ test.describe( 'Products API tests: CRUD', () => {
}, },
} }
); );
} ); }
);
} ); } );
test.describe( 'Product tags tests: CRUD', () => { test.describe( 'Product tags tests: CRUD', () => {

View File

@ -280,7 +280,7 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
type: 'text', type: 'text',
default: '', default: '',
tip: 'The street address for your business location.', tip: 'The street address for your business location.',
value: '', value: expect.any( String ),
} ), } ),
] ) ] )
); );
@ -310,7 +310,7 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
type: 'text', type: 'text',
default: '', default: '',
tip: 'The city in which your business is located.', tip: 'The city in which your business is located.',
value: '', value: expect.any( String ),
} ), } ),
] ) ] )
); );
@ -341,7 +341,7 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
type: 'text', type: 'text',
default: '', default: '',
tip: 'The postal code, if any, in which your business is located.', tip: 'The postal code, if any, in which your business is located.',
value: '', value: expect.any( String ),
} ), } ),
] ) ] )
); );
@ -1019,9 +1019,14 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
} ); } );
test.describe( 'List all Tax settings options', () => { test.describe( 'List all Tax settings options', () => {
test( 'can retrieve all tax settings', async ( { request } ) => { test(
'can retrieve all tax settings',
{ tag: [ '@skip-on-default-pressable', '@skip-on-default-wpcom' ] },
async ( { request } ) => {
// call API to retrieve all settings options // call API to retrieve all settings options
const response = await request.get( '/wp-json/wc/v3/settings/tax' ); const response = await request.get(
'/wp-json/wc/v3/settings/tax'
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
expect( Array.isArray( responseJSON ) ).toBe( true ); expect( Array.isArray( responseJSON ) ).toBe( true );
@ -1072,7 +1077,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
type: 'select', type: 'select',
default: 'inherit', default: 'inherit',
options: { options: {
inherit: 'Shipping tax class based on cart items', inherit:
'Shipping tax class based on cart items',
'': 'Standard', '': 'Standard',
'reduced-rate': 'Reduced rate', 'reduced-rate': 'Reduced rate',
'zero-rate': 'Zero rate', 'zero-rate': 'Zero rate',
@ -1169,7 +1175,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
} ), } ),
] ) ] )
); );
} ); }
);
} ); } );
test.describe( 'List all Shipping settings options', () => { test.describe( 'List all Shipping settings options', () => {
@ -1613,8 +1620,13 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
} ); } );
} ); } );
test.describe( 'List all Advanced settings options', () => { test.describe(
test( 'can retrieve all advanced settings', async ( { request } ) => { 'List all Advanced settings options',
{ tag: '@skip-on-default-wpcom' },
() => {
test( 'can retrieve all advanced settings', async ( {
request,
} ) => {
// call API to retrieve all settings options // call API to retrieve all settings options
const response = await request.get( const response = await request.get(
'/wp-json/wc/v3/settings/advanced' '/wp-json/wc/v3/settings/advanced'
@ -1668,7 +1680,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
expect.objectContaining( { expect.objectContaining( {
id: 'woocommerce_myaccount_page_id', id: 'woocommerce_myaccount_page_id',
label: 'My account page', label: 'My account page',
description: 'Page contents: [woocommerce_my_account]', description:
'Page contents: [woocommerce_my_account]',
type: 'select', type: 'select',
default: '', default: '',
tip: 'Page contents: [woocommerce_my_account]', tip: 'Page contents: [woocommerce_my_account]',
@ -1871,7 +1884,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
expect.objectContaining( { expect.objectContaining( {
id: 'woocommerce_show_marketplace_suggestions', id: 'woocommerce_show_marketplace_suggestions',
label: 'Show Suggestions', label: 'Show Suggestions',
description: 'Display suggestions within WooCommerce', description:
'Display suggestions within WooCommerce',
type: 'checkbox', type: 'checkbox',
default: 'yes', default: 'yes',
tip: 'Leave this box unchecked if you do not want to pull suggested extensions from WooCommerce.com. You will see a static list of extensions instead.', tip: 'Leave this box unchecked if you do not want to pull suggested extensions from WooCommerce.com. You will see a static list of extensions instead.',
@ -1892,7 +1906,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
] ) ] )
); );
} ); } );
} ); }
);
test.describe( 'List all Email New Order settings', () => { test.describe( 'List all Email New Order settings', () => {
test( 'can retrieve all email new order settings', async ( { test( 'can retrieve all email new order settings', async ( {
@ -1930,7 +1945,7 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
tip: expect.stringContaining( tip: expect.stringContaining(
'Enter recipients (comma separated) for this email. Defaults to' 'Enter recipients (comma separated) for this email. Defaults to'
), ),
value: '', value: expect.any( String ),
} ), } ),
] ) ] )
); );
@ -1998,9 +2013,10 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
} ); } );
test.describe( 'List all Email Failed Order settings', () => { test.describe( 'List all Email Failed Order settings', () => {
test( 'can retrieve all email failed order settings', async ( { test(
request, 'can retrieve all email failed order settings',
} ) => { { tag: '@skip-on-default-pressable' },
async ( { request } ) => {
// call API to retrieve all settings options // call API to retrieve all settings options
const response = await request.get( const response = await request.get(
'/wp-json/wc/v3/settings/email_failed_order' '/wp-json/wc/v3/settings/email_failed_order'
@ -2085,7 +2101,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
expect.objectContaining( { expect.objectContaining( {
id: 'email_type', id: 'email_type',
label: 'Email type', label: 'Email type',
description: 'Choose which format of email to send.', description:
'Choose which format of email to send.',
type: 'select', type: 'select',
default: 'html', default: 'html',
options: { options: {
@ -2098,7 +2115,8 @@ test.describe.serial( 'Settings API tests: CRUD', () => {
} ), } ),
] ) ] )
); );
} ); }
);
} ); } );
test.describe( 'List all Email Customer On Hold Order settings', () => { test.describe( 'List all Email Customer On Hold Order settings', () => {

View File

@ -3,9 +3,14 @@ const { BASE_URL } = process.env;
const shouldSkip = BASE_URL !== undefined && ! BASE_URL.includes( 'localhost' ); const shouldSkip = BASE_URL !== undefined && ! BASE_URL.includes( 'localhost' );
test.describe( 'System Status API tests', () => { test.describe( 'System Status API tests', () => {
test( 'can view all system status items', async ( { request } ) => { test(
'can view all system status items',
{ tag: '@skip-on-default-wpcom' },
async ( { request } ) => {
// call API to view all system status items // call API to view all system status items
const response = await request.get( '/wp-json/wc/v3/system_status' ); const response = await request.get(
'/wp-json/wc/v3/system_status'
);
const responseJSON = await response.json(); const responseJSON = await response.json();
expect( response.status() ).toEqual( 200 ); expect( response.status() ).toEqual( 200 );
@ -99,12 +104,14 @@ test.describe( 'System Status API tests', () => {
maxmind_geoip_database: expect.any( String ), maxmind_geoip_database: expect.any( String ),
database_tables: expect.objectContaining( { database_tables: expect.objectContaining( {
woocommerce: expect.objectContaining( { woocommerce: expect.objectContaining( {
wp_woocommerce_sessions: expect.objectContaining( { wp_woocommerce_sessions:
expect.objectContaining( {
data: expect.any( String ), data: expect.any( String ),
index: expect.any( String ), index: expect.any( String ),
engine: expect.any( String ), engine: expect.any( String ),
} ), } ),
wp_woocommerce_api_keys: expect.objectContaining( { wp_woocommerce_api_keys:
expect.objectContaining( {
data: expect.any( String ), data: expect.any( String ),
index: expect.any( String ), index: expect.any( String ),
engine: expect.any( String ), engine: expect.any( String ),
@ -121,20 +128,20 @@ test.describe( 'System Status API tests', () => {
index: expect.any( String ), index: expect.any( String ),
engine: expect.any( String ), engine: expect.any( String ),
} ), } ),
wp_woocommerce_order_items: expect.objectContaining( wp_woocommerce_order_items:
{ expect.objectContaining( {
data: expect.any( String ), data: expect.any( String ),
index: expect.any( String ), index: expect.any( String ),
engine: expect.any( String ), engine: expect.any( String ),
} } ),
),
wp_woocommerce_order_itemmeta: wp_woocommerce_order_itemmeta:
expect.objectContaining( { expect.objectContaining( {
data: expect.any( String ), data: expect.any( String ),
index: expect.any( String ), index: expect.any( String ),
engine: expect.any( String ), engine: expect.any( String ),
} ), } ),
wp_woocommerce_tax_rates: expect.objectContaining( { wp_woocommerce_tax_rates:
expect.objectContaining( {
data: expect.any( String ), data: expect.any( String ),
index: expect.any( String ), index: expect.any( String ),
engine: expect.any( String ), engine: expect.any( String ),
@ -578,7 +585,8 @@ test.describe( 'System Status API tests', () => {
] ), ] ),
} ) } )
); );
} ); }
);
test( 'can view all system status tools', async ( { request } ) => { test( 'can view all system status tools', async ( { request } ) => {
// call API to view system status tools // call API to view system status tools