From 72f8943b6c68d19f7c56cf83371e7326c6176420 Mon Sep 17 00:00:00 2001 From: Barry Hughes <3594411+barryhughes@users.noreply.github.com> Date: Tue, 19 Sep 2023 16:03:52 -0700 Subject: [PATCH] Regression test for `woocommerce_get_customer_details` ajax endpoint. (#40273) * Regression test for `woocommerce_get_customer_details` ajax endpoint. * Remove unnecesssary code manipulating customer selector. * Clean-up test customer. --- .../changelog/add-regression-test-user-meta | 5 ++ .../e2e-pw/tests/merchant/order-edit.spec.js | 69 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 plugins/woocommerce/changelog/add-regression-test-user-meta diff --git a/plugins/woocommerce/changelog/add-regression-test-user-meta b/plugins/woocommerce/changelog/add-regression-test-user-meta new file mode 100644 index 00000000000..52ede0eec5e --- /dev/null +++ b/plugins/woocommerce/changelog/add-regression-test-user-meta @@ -0,0 +1,5 @@ +Significance: patch +Type: dev +Comment: Adds regression test for https://github.com/woocommerce/woocommerce/pull/40221. + + diff --git a/plugins/woocommerce/tests/e2e-pw/tests/merchant/order-edit.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/merchant/order-edit.spec.js index 94ae4cef3ac..270f93ba851 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/merchant/order-edit.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/merchant/order-edit.spec.js @@ -86,6 +86,75 @@ test.describe( 'Edit order', () => { '2018-12-14' ); } ); + + test( 'can load billing details', async ( { page, baseURL } ) => { + let customerId = 0; + + const api = new wcApi( { + url: baseURL, + consumerKey: process.env.CONSUMER_KEY, + consumerSecret: process.env.CONSUMER_SECRET, + version: 'wc/v3', + } ); + + await api + .post( 'customers', { + email: 'archie123@email.addr', + first_name: 'Archie', + last_name: 'Greenback', + username: 'big.archie', + billing: { + first_name: 'Archibald', + last_name: 'Greenback', + company: 'Automattic', + country: 'US', + address_1: 'address1', + address_2: 'address2', + city: 'San Francisco', + state: 'CA', + postcode: '94107', + phone: '123456789', + email: 'archie123@email.addr', + } + } ) + .then( ( response ) => { + customerId = response.data.id; + } ); + + // Open our test order and select the customer we just created. + await page.goto( `wp-admin/post.php?post=${orderId}&action=edit` ); + + // Simulate the ajax `woocommerce_get_customer_details` call normally done inside meta-boxes-order.js. + const response = await page.evaluate( + async ( customerId ) => { + const simulateCustomerDetailsCall = new Promise( ( resolve ) => { + jQuery.ajax( { + url: woocommerce_admin_meta_boxes.ajax_url, + data: { + user_id : customerId, + action : 'woocommerce_get_customer_details', + security: woocommerce_admin_meta_boxes.get_customer_details_nonce + }, + type: 'POST', + success: function( response ) { + resolve( response ); + } + } ); + } ); + + return await simulateCustomerDetailsCall; + }, + customerId + ); + + // Response should contain billing address info, but should not contain user meta data. + expect( 'billing' in response ).toBeTruthy(); + expect( response.billing.first_name ).toContain( 'Archibald' ); + expect( response.meta_data ).toBeUndefined(); + + // Clean-up. + await api.delete( `customers/${ customerId }`, { force: true } ); + } ); } ); test.describe( 'Edit order > Downloadable product permissions', () => {