From cd838e3742574d687ac21e7060b594bff88a5552 Mon Sep 17 00:00:00 2001 From: nigeljamesstevenson <105309450+nigeljamesstevenson@users.noreply.github.com> Date: Mon, 6 Nov 2023 19:35:03 +0000 Subject: [PATCH] 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 --- ...-fix-to-allow-execution-against-daily-site | 4 + .../payment-gateways-crud.test.js | 408 +++++++++--------- .../system-status/system-status-crud.test.js | 6 +- 3 files changed, 218 insertions(+), 200 deletions(-) create mode 100644 plugins/woocommerce/changelog/api-fix-to-allow-execution-against-daily-site diff --git a/plugins/woocommerce/changelog/api-fix-to-allow-execution-against-daily-site b/plugins/woocommerce/changelog/api-fix-to-allow-execution-against-daily-site new file mode 100644 index 00000000000..071455362a8 --- /dev/null +++ b/plugins/woocommerce/changelog/api-fix-to-allow-execution-against-daily-site @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Update to allow the api-core-tests to execute against the daily test site diff --git a/plugins/woocommerce/tests/api-core-tests/tests/payment-gateways/payment-gateways-crud.test.js b/plugins/woocommerce/tests/api-core-tests/tests/payment-gateways/payment-gateways-crud.test.js index 8f5f09d45ae..70ef9183390 100644 --- a/plugins/woocommerce/tests/api-core-tests/tests/payment-gateways/payment-gateways-crud.test.js +++ b/plugins/woocommerce/tests/api-core-tests/tests/payment-gateways/payment-gateways-crud.test.js @@ -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, + }, + } ); + } ); +} ); diff --git a/plugins/woocommerce/tests/api-core-tests/tests/system-status/system-status-crud.test.js b/plugins/woocommerce/tests/api-core-tests/tests/system-status/system-status-crud.test.js index e0349b327c7..9e96069c2e8 100644 --- a/plugins/woocommerce/tests/api-core-tests/tests/system-status/system-status-crud.test.js +++ b/plugins/woocommerce/tests/api-core-tests/tests/system-status/system-status-crud.test.js @@ -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 ),