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.
This commit is contained in:
Barry Hughes 2023-09-19 16:03:52 -07:00 committed by GitHub
parent 4470d9e1a4
commit 72f8943b6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Adds regression test for https://github.com/woocommerce/woocommerce/pull/40221.

View File

@ -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', () => {