Merge pull request #30597 from woocommerce/add/e2e-get-environment-context
Get environment context for tests including WP version and WC version
This commit is contained in:
commit
f6c5dbf268
|
@ -20,7 +20,7 @@ const runInitiateWccomConnectionTest = () => {
|
|||
await merchant.login();
|
||||
});
|
||||
|
||||
it('can initiate WCCOM connection', async () => {
|
||||
it.skip('can initiate WCCOM connection', async () => {
|
||||
await merchant.openHelper();
|
||||
|
||||
// Click on Connect button to initiate a WCCOM connection
|
||||
|
|
|
@ -5,6 +5,7 @@ const {
|
|||
shopper,
|
||||
createSimpleProductWithCategory,
|
||||
utils,
|
||||
getEnvironmentContext,
|
||||
} = require( '@woocommerce/e2e-utils' );
|
||||
|
||||
/**
|
||||
|
@ -15,7 +16,6 @@ const {
|
|||
describe,
|
||||
beforeAll,
|
||||
} = require( '@jest/globals' );
|
||||
const { WORDPRESS_VERSION } = process.env;
|
||||
|
||||
const config = require( 'config' );
|
||||
const simpleProductName = config.get( 'products.simple.name' );
|
||||
|
@ -27,8 +27,13 @@ const audio = 'Audio';
|
|||
const hardware = 'Hardware';
|
||||
const productTitle = 'li.first > a > h2.woocommerce-loop-product__title';
|
||||
|
||||
const getWordPressVersion = async () => {
|
||||
const context = await getEnvironmentContext();
|
||||
return context.wpVersion;
|
||||
}
|
||||
|
||||
const runProductBrowseSearchSortTest = () => {
|
||||
utils.describeIf( WORDPRESS_VERSION >= '5.8' )( 'Search, browse by categories and sort items in the shop', () => {
|
||||
utils.describeIf( getWordPressVersion() >= 5.8 )( 'Search, browse by categories and sort items in the shop', () => {
|
||||
beforeAll(async () => {
|
||||
// Create 1st product with Clothing category
|
||||
await createSimpleProductWithCategory(simpleProductName + ' 1', singleProductPrice, clothing);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
- Added `statuses` optional parameter to `deleteAllRepositoryObjects()` to delete on specific statuses
|
||||
- Added `createOrder()` component util that creates an order using the API with the passed in details
|
||||
- Updated `addShippingZoneAndMethod` to use the API instead of UI to create shipping zones
|
||||
- Added `getSystemEnvironment()` that gets the current environment from the WooCommerce API.
|
||||
|
||||
# 0.1.5
|
||||
|
||||
|
|
|
@ -149,6 +149,7 @@ This package provides support for enabling retries in tests:
|
|||
| `resetSettingsGroupToDefault` | `settingsGroup` | Reset settings in settings group to default except `select` fields |
|
||||
| `batchCreateOrders` | `orders` | Create a batch of orders using the "Batch Create Order" API endpoint |
|
||||
| `deleteAllOrders` | | Permanently delete all orders |
|
||||
| `getSystemEnvironment` | | Get the current environment from the WooCommerce system status API.
|
||||
|
||||
### Page Utilities
|
||||
|
||||
|
|
|
@ -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,34 @@ 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 environment from the WooCommerce system status API.
|
||||
*
|
||||
* For more details, see: https://woocommerce.github.io/woocommerce-rest-api-docs/#system-status-environment-properties
|
||||
*
|
||||
* @returns {Promise<object>} 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -11,3 +11,4 @@ export * from './flows';
|
|||
export * from './old-flows';
|
||||
export * from './components';
|
||||
export * from './page-utils';
|
||||
export * from './system-environment';
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import { withRestApi } from './flows';
|
||||
|
||||
/**
|
||||
* Uses the WooCommerce API to get the environment context.
|
||||
*/
|
||||
export const getEnvironmentContext = async () => {
|
||||
try {
|
||||
const environment = await withRestApi.getSystemEnvironment();
|
||||
return {
|
||||
wpVersion: environment.wp_version,
|
||||
wcVersion: environment.version,
|
||||
}
|
||||
} catch ( error ) {
|
||||
// Prevent an error here causing tests to fail.
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue