update api-core-tests to work on daily site and localhost/CI (#41222)

* update api-core-tests to work on daily site

* changelog

* changlog update
This commit is contained in:
nigeljamesstevenson 2023-11-06 19:35:03 +00:00 committed by GitHub
parent 20fac52381
commit cd838e3742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 218 additions and 200 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Update to allow the api-core-tests to execute against the daily test site

View File

@ -1,7 +1,4 @@
const {
test,
expect
} = require('@playwright/test');
const { test, expect } = require( '@playwright/test' );
/**
* Tests for the WooCommerce Refunds API.
@ -10,229 +7,244 @@ const {
* @group payment gateways
*
*/
test.describe('Payment Gateways API tests', () => {
test('can view all payment gateways', async ({
request
}) => {
test.describe( 'Payment Gateways API tests', () => {
test( 'can view all payment gateways', async ( { request } ) => {
// 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();
expect(response.status()).toEqual(200);
expect(Array.isArray(responseJSON)).toBe(true);
expect( response.status() ).toEqual( 200 );
expect( Array.isArray( responseJSON ) ).toBe( true );
const localPickupKey =
process.env.API_BASE_URL &&
! process.env.API_BASE_URL.includes( 'localhost' )
? 'pickup_location'
: 'local_pickup';
console.log( 'localPickupKey=', localPickupKey );
expect(responseJSON).toEqual(
expect.arrayContaining([
expect.objectContaining({
"id": "bacs",
"title": "Direct bank transfer",
"description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.",
"order": "",
"enabled": false,
"method_title": "Direct bank transfer",
"method_description": "Take payments in person via BACS. More commonly known as direct bank/wire transfer.",
"method_supports": [
"products"
],
"settings": {
"title": {
"id": "title",
"label": "Title",
"description": "This controls the title which the user sees during checkout.",
"type": "safe_text",
"value": "Direct bank transfer",
"default": "Direct bank transfer",
"tip": "This controls the title which the user sees during checkout.",
"placeholder": ""
expect( responseJSON ).toEqual(
expect.arrayContaining( [
expect.objectContaining( {
id: 'bacs',
title: 'Direct bank transfer',
description:
'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.',
order: '',
enabled: false,
method_title: 'Direct bank transfer',
method_description:
'Take payments in person via BACS. More commonly known as direct bank/wire transfer.',
method_supports: [ 'products' ],
settings: {
title: {
id: 'title',
label: 'Title',
description:
'This controls the title which the user sees during checkout.',
type: 'safe_text',
value: 'Direct bank transfer',
default: 'Direct bank transfer',
tip: 'This controls the title which the user sees during checkout.',
placeholder: '',
},
instructions: {
id: 'instructions',
label: 'Instructions',
description:
'Instructions that will be added to the thank you page and emails.',
type: 'textarea',
value: '',
default: '',
tip: 'Instructions that will be added to the thank you page and emails.',
placeholder: '',
},
"instructions": {
"id": "instructions",
"label": "Instructions",
"description": "Instructions that will be added to the thank you page and emails.",
"type": "textarea",
"value": "",
"default": "",
"tip": "Instructions that will be added to the thank you page and emails.",
"placeholder": ""
}
},
}),
} ),
expect.objectContaining({
"id": "cheque",
"title": "Check payments",
"description": "Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.",
"order": "",
"enabled": false,
"method_title": "Check payments",
"method_description": "Take payments in person via checks. This offline gateway can also be useful to test purchases.",
"method_supports": [
"products"
],
"settings": {
"title": {
"id": "title",
"label": "Title",
"description": "This controls the title which the user sees during checkout.",
"type": "safe_text",
"value": "Check payments",
"default": "Check payments",
"tip": "This controls the title which the user sees during checkout.",
"placeholder": ""
expect.objectContaining( {
id: 'cheque',
title: 'Check payments',
description:
'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.',
order: '',
enabled: false,
method_title: 'Check payments',
method_description:
'Take payments in person via checks. This offline gateway can also be useful to test purchases.',
method_supports: [ 'products' ],
settings: {
title: {
id: 'title',
label: 'Title',
description:
'This controls the title which the user sees during checkout.',
type: 'safe_text',
value: 'Check payments',
default: 'Check payments',
tip: 'This controls the title which the user sees during checkout.',
placeholder: '',
},
instructions: {
id: 'instructions',
label: 'Instructions',
description:
'Instructions that will be added to the thank you page and emails.',
type: 'textarea',
value: '',
default: '',
tip: 'Instructions that will be added to the thank you page and emails.',
placeholder: '',
},
"instructions": {
"id": "instructions",
"label": "Instructions",
"description": "Instructions that will be added to the thank you page and emails.",
"type": "textarea",
"value": "",
"default": "",
"tip": "Instructions that will be added to the thank you page and emails.",
"placeholder": ""
}
},
}),
} ),
expect.objectContaining({
"id": "cod",
"title": "Cash on delivery",
"description": "Pay with cash upon delivery.",
"order": "",
"enabled": false,
"method_title": "Cash on delivery",
"method_description": "Have your customers pay with cash (or by other means) upon delivery.",
"method_supports": [
"products"
],
"settings": {
"title": {
"id": "title",
"label": "Title",
"description": "Payment method description that the customer will see on your checkout.",
"type": "safe_text",
"value": "Cash on delivery",
"default": "Cash on delivery",
"tip": "Payment method description that the customer will see on your checkout.",
"placeholder": ""
expect.objectContaining( {
id: 'cod',
title: 'Cash on delivery',
description: 'Pay with cash upon delivery.',
order: '',
enabled: false,
method_title: 'Cash on delivery',
method_description:
'Have your customers pay with cash (or by other means) upon delivery.',
method_supports: [ 'products' ],
settings: {
title: {
id: 'title',
label: 'Title',
description:
'Payment method description that the customer will see on your checkout.',
type: 'safe_text',
value: 'Cash on delivery',
default: 'Cash on delivery',
tip: 'Payment method description that the customer will see on your checkout.',
placeholder: '',
},
"instructions": {
"id": "instructions",
"label": "Instructions",
"description": "Instructions that will be added to the thank you page.",
"type": "textarea",
"value": "Pay with cash upon delivery.",
"default": "Pay with cash upon delivery.",
"tip": "Instructions that will be added to the thank you page.",
"placeholder": ""
instructions: {
id: 'instructions',
label: 'Instructions',
description:
'Instructions that will be added to the thank you page.',
type: 'textarea',
value: 'Pay with cash upon delivery.',
default: 'Pay with cash upon delivery.',
tip: 'Instructions that will be added to the thank you page.',
placeholder: '',
},
"enable_for_methods": {
"id": "enable_for_methods",
"label": "Enable for shipping methods",
"description": "If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.",
"type": "multiselect",
"value": "",
"default": "",
"tip": "If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.",
"placeholder": "",
"options": expect.objectContaining({
"Flat rate": {
"flat_rate": "Any "Flat rate" method"
enable_for_methods: {
id: 'enable_for_methods',
label: 'Enable for shipping methods',
description:
'If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.',
type: 'multiselect',
value: '',
default: '',
tip: 'If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.',
placeholder: '',
options: expect.objectContaining( {
'Flat rate': {
flat_rate:
'Any "Flat rate" method',
},
"Free shipping": {
"free_shipping": "Any "Free shipping" method"
'Free shipping': {
free_shipping:
'Any "Free shipping" method',
},
"Local pickup": {
"local_pickup": "Any "Local pickup" method"
}
})
'Local pickup': expect.objectContaining( {
[ localPickupKey ]:
'Any "Local pickup" method',
} ),
} ),
},
enable_for_virtual: {
id: 'enable_for_virtual',
label: 'Accept COD if the order is virtual',
description: '',
type: 'checkbox',
value: 'yes',
default: 'yes',
tip: '',
placeholder: '',
},
"enable_for_virtual": {
"id": "enable_for_virtual",
"label": "Accept COD if the order is virtual",
"description": "",
"type": "checkbox",
"value": "yes",
"default": "yes",
"tip": "",
"placeholder": ""
}
},
})
])
} ),
] )
);
});
} );
test('can view a payment gateway', async ({
request
}) => {
test( 'can view a payment gateway', async ( { request } ) => {
// call API to retrieve a single payment gateway
const response = await request.get('/wp-json/wc/v3/payment_gateways/bacs');
const response = await request.get(
'/wp-json/wc/v3/payment_gateways/bacs'
);
const responseJSON = await response.json();
expect(response.status()).toEqual(200);
expect(Array.isArray(responseJSON)).toBe(false);
expect( response.status() ).toEqual( 200 );
expect( Array.isArray( responseJSON ) ).toBe( false );
expect(responseJSON).toEqual(
expect.objectContaining({
"id": "bacs",
"title": "Direct bank transfer",
"description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.",
"order": "",
"enabled": false,
"method_title": "Direct bank transfer",
"method_description": "Take payments in person via BACS. More commonly known as direct bank/wire transfer.",
"method_supports": [
"products"
],
"settings": {
"title": {
"id": "title",
"label": "Title",
"description": "This controls the title which the user sees during checkout.",
"type": "safe_text",
"value": "Direct bank transfer",
"default": "Direct bank transfer",
"tip": "This controls the title which the user sees during checkout.",
"placeholder": ""
expect( responseJSON ).toEqual(
expect.objectContaining( {
id: 'bacs',
title: 'Direct bank transfer',
description:
'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.',
order: '',
enabled: false,
method_title: 'Direct bank transfer',
method_description:
'Take payments in person via BACS. More commonly known as direct bank/wire transfer.',
method_supports: [ 'products' ],
settings: {
title: {
id: 'title',
label: 'Title',
description:
'This controls the title which the user sees during checkout.',
type: 'safe_text',
value: 'Direct bank transfer',
default: 'Direct bank transfer',
tip: 'This controls the title which the user sees during checkout.',
placeholder: '',
},
instructions: {
id: 'instructions',
label: 'Instructions',
description:
'Instructions that will be added to the thank you page and emails.',
type: 'textarea',
value: '',
default: '',
tip: 'Instructions that will be added to the thank you page and emails.',
placeholder: '',
},
"instructions": {
"id": "instructions",
"label": "Instructions",
"description": "Instructions that will be added to the thank you page and emails.",
"type": "textarea",
"value": "",
"default": "",
"tip": "Instructions that will be added to the thank you page and emails.",
"placeholder": ""
}
},
}));
});
} )
);
} );
test('can update a payment gateway', async ({
request
}) => {
test( 'can update a payment gateway', async ( { request } ) => {
// call API to update a payment gateway
const response = await request.put('/wp-json/wc/v3/payment_gateways/bacs', {
data: {
enabled: true
const response = await request.put(
'/wp-json/wc/v3/payment_gateways/bacs',
{
data: {
enabled: true,
},
}
});
);
const responseJSON = await response.json();
expect(response.status()).toEqual(200);
expect( response.status() ).toEqual( 200 );
expect(responseJSON).toEqual(
expect.objectContaining({
enabled: true
}),
expect( responseJSON ).toEqual(
expect.objectContaining( {
enabled: true,
} )
);
// reset payment gateway setting
await request.put('/wp-json/wc/v3/payment_gateways/bacs', {
await request.put( '/wp-json/wc/v3/payment_gateways/bacs', {
data: {
enabled: false
}
});
});
});
enabled: false,
},
} );
} );
} );

View File

@ -1,6 +1,8 @@
const { test, expect } = require( '@playwright/test' );
const { API_BASE_URL } = process.env;
const shouldSkip = API_BASE_URL != undefined;
const shouldSkip =
API_BASE_URL !== undefined && ! API_BASE_URL.includes( 'localhost' );
/**
* Tests for the WooCommerce API.
*
@ -445,7 +447,7 @@ test.describe( 'System Status API tests', () => {
has_woocommerce_support: expect.any( Boolean ),
has_woocommerce_file: expect.any( Boolean ),
has_outdated_templates: expect.any( Boolean ),
overrides: [],
overrides: expect.any( Array ),
parent_name: expect.any( String ),
parent_version: expect.any( String ),
parent_version_latest: expect.any( String ),