From 185cd3dcaaa0854552f8c4b90b454b5ace237d26 Mon Sep 17 00:00:00 2001 From: nigeljamesstevenson <105309450+nigeljamesstevenson@users.noreply.github.com> Date: Mon, 20 Mar 2023 20:23:23 +0000 Subject: [PATCH] Update playwright api-core-tests to associate orders with real products to prevent extension issues for those that validate product ids (#37243) * Update playwright api-core-tests to associate orders with real products to prevent extension issues for those that validate product ids * add newline at end of file * add comment --- ...-core-tests-to-associate-products-with-orders | 4 ++++ .../tests/orders/order-search.test.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 plugins/woocommerce/changelog/update-api-core-tests-to-associate-products-with-orders diff --git a/plugins/woocommerce/changelog/update-api-core-tests-to-associate-products-with-orders b/plugins/woocommerce/changelog/update-api-core-tests-to-associate-products-with-orders new file mode 100644 index 00000000000..0a21ebfc233 --- /dev/null +++ b/plugins/woocommerce/changelog/update-api-core-tests-to-associate-products-with-orders @@ -0,0 +1,4 @@ +Significance: patch +Type: update + +Update playwright api-core-tests to associate orders with real products to prevent extension issues for those that validate product ids diff --git a/plugins/woocommerce/tests/api-core-tests/tests/orders/order-search.test.js b/plugins/woocommerce/tests/api-core-tests/tests/orders/order-search.test.js index 03ae15d9253..e7d1f400a58 100644 --- a/plugins/woocommerce/tests/api-core-tests/tests/orders/order-search.test.js +++ b/plugins/woocommerce/tests/api-core-tests/tests/orders/order-search.test.js @@ -2,6 +2,9 @@ const { test, expect } = require( '@playwright/test' ); const { getOrderExampleSearchTest } = require( '../../data/order' ); const { customerShippingSearchTest } = require( '../../data/shared/customer' ); +const { + simpleProduct, +} = require('../../data/products-crud'); /** * Order to be searched @@ -55,6 +58,15 @@ const searchParams = [ */ test.describe( 'Order Search API tests', () => { test.beforeAll( async ( { request } ) => { + // Create a product to be associated with the order + const productResponse = await request.post('wp-json/wc/v3/products', { + data: simpleProduct, + }); + const productResponseJSON = await productResponse.json(); + + // Save the created product id against the order line_items + order.line_items[0].product_id = productResponseJSON.id; + // Create an order and save its ID const response = await request.post( '/wp-json/wc/v3/orders', { data: order, @@ -64,6 +76,10 @@ test.describe( 'Order Search API tests', () => { } ); test.afterAll( async ( { request } ) => { + // Cleanup: Delete the product + await request.delete( `/wp-json/wc/v3/products/${ order.line_items[0].product_id }`, { + data: { force: true }, + } ); // Cleanup: Delete the order await request.delete( `/wp-json/wc/v3/orders/${ order.id }`, { data: { force: true },