diff --git a/tests/e2e/config/jest.setup.js b/tests/e2e/config/jest.setup.js index ebf80556653..70235642d2b 100644 --- a/tests/e2e/config/jest.setup.js +++ b/tests/e2e/config/jest.setup.js @@ -35,6 +35,15 @@ async function trashExistingPosts() { } } +/** + * Uses the WooCommerce API to get the envivonment context. + */ +async function getEnvironmentContext() { + const environment = await withRestApi.getSystemEnvironment(); + process.env.WORDPRESS_VERSION = environment.wp_version; + process.env.WC_VERSION = environment.version; +} + // Before every test suite run, delete all content created by the test. This ensures // other posts/comments/etc. aren't dirtying tests and tests don't depend on // each other's side-effects. @@ -46,6 +55,8 @@ beforeAll(async () => { } try { + await getEnvironmentContext(); + // Update the ready page to prevent concurrent test runs await updateReadyPageStatus('draft'); await trashExistingPosts(); diff --git a/tests/e2e/utils/src/flows/with-rest-api.js b/tests/e2e/utils/src/flows/with-rest-api.js index 7bc1d08cf00..ea6a96e0ac5 100644 --- a/tests/e2e/utils/src/flows/with-rest-api.js +++ b/tests/e2e/utils/src/flows/with-rest-api.js @@ -6,6 +6,7 @@ const onboardingProfileEndpoint = '/wc-admin/onboarding/profile'; const shippingZoneEndpoint = '/wc/v3/shipping/zones'; const shippingClassesEndpoint = '/wc/v3/products/shipping_classes'; const userEndpoint = '/wp/v2/users'; +const systemStatusEndpoint = '/wc/v3/system_status'; /** * Utility function to delete all merchant created data store objects. @@ -252,18 +253,32 @@ export const withRestApi = { } } }, - + /** * Create a batch of orders using the "Batch Create Order" API endpoint. - * + * * @param orders Array of orders to be created */ - batchCreateOrders : async (orders) => { + batchCreateOrders: async (orders) => { const path = '/wc/v3/orders/batch'; const payload = { create: orders }; - + const { statusCode } = await client.post(path, payload); expect(statusCode).toEqual(200); + }, + + /** + * Get the current envrionment from the WooCommerce system status API. + * + * @returns {Promise} The environment object from the API response. + */ + getSystemEnvironment: async () => { + const response = await client.get( systemStatusEndpoint ); + if ( response.data.environment ) { + return response.data.environment + } else { + return; + } } };