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 },