Merge branch 'trunk' into update/marketplace-1

This commit is contained in:
And Finally 2021-08-19 10:29:37 +01:00
commit fa76121b41
22 changed files with 188 additions and 77 deletions

View File

@ -40,6 +40,7 @@ jobs:
E2E_SLACK_TOKEN: ${{ secrets.SMOKE_TEST_SLACK_TOKEN }}
E2E_SLACK_CHANNEL: ${{ secrets.SMOKE_TEST_SLACK_CHANNEL }}
UPDATE_WC: 1
DEFAULT_TIMEOUT_OVERRIDE: 120000
run: |
npx wc-e2e test:e2e ./tests/e2e/specs/smoke-tests/update-woocommerce.js
npx wc-e2e test:e2e

View File

@ -41,6 +41,7 @@ jobs:
E2E_SLACK_CHANNEL: ${{ secrets.SMOKE_TEST_SLACK_CHANNEL }}
TEST_RELEASE: 1
UPDATE_WC: 1
DEFAULT_TIMEOUT_OVERRIDE: 120000
run: |
npx wc-e2e test:e2e ./tests/e2e/specs/smoke-tests/update-woocommerce.js
npx wc-e2e test:e2e

View File

@ -68,16 +68,16 @@
},
{
"name": "league/flysystem",
"version": "1.1.4",
"version": "1.1.5",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/flysystem.git",
"reference": "f3ad69181b8afed2c9edf7be5a2918144ff4ea32"
"reference": "18634df356bfd4119fe3d6156bdb990c414c14ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/f3ad69181b8afed2c9edf7be5a2918144ff4ea32",
"reference": "f3ad69181b8afed2c9edf7be5a2918144ff4ea32",
"url": "https://api.github.com/repos/thephpleague/flysystem/zipball/18634df356bfd4119fe3d6156bdb990c414c14ea",
"reference": "18634df356bfd4119fe3d6156bdb990c414c14ea",
"shasum": ""
},
"require": {
@ -150,7 +150,7 @@
],
"support": {
"issues": "https://github.com/thephpleague/flysystem/issues",
"source": "https://github.com/thephpleague/flysystem/tree/1.1.4"
"source": "https://github.com/thephpleague/flysystem/tree/1.1.5"
},
"funding": [
{
@ -158,7 +158,7 @@
"type": "other"
}
],
"time": "2021-06-23T21:56:05+00:00"
"time": "2021-08-17T13:49:42+00:00"
},
{
"name": "league/mime-type-detection",

View File

@ -25,7 +25,7 @@
* Dev - Apply `woocommerce_logout_default_redirect_url` filter to logout for custom endpoint. #29967
* Dev - Added new `woocommerce_email_sent` hook. #30123
**WooCommerce Admin - 2.5.0**
**WooCommerce Admin - 2.5.0 & 2.5.1**
- Add - Add a delete option to completed tasks #7300
- Add - Add unit tests around extended payment gateway controller #7133
@ -79,6 +79,7 @@
- Fix - Fix analytics overview re-arrangement on initial load. #7475
- Fix - Fixes action button mis-alignment within card footer. #7412
- Fix - Fix up onboarding profiler not working when opted out of tracking
- Fix - Fix blank screen by setting a default value #7506
- Tweak - Remove performance indicators when Analytics Flag disabled #7234
- Tweak - Change event name when installing Google Listings and Ads. #7276
- Tweak - Removed unused feature flags #7233 and #7273

View File

@ -21,8 +21,8 @@
"pelago/emogrifier": "3.1.0",
"psr/container": "1.0.0",
"woocommerce/action-scheduler": "3.2.1",
"woocommerce/woocommerce-admin": "2.5.0",
"woocommerce/woocommerce-blocks": "5.5.1"
"woocommerce/woocommerce-admin": "2.5.1",
"woocommerce/woocommerce-blocks": "5.7.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4"

26
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "190546c0839729dcc8e8c9eb8268455e",
"content-hash": "0ddc585162239e09c69981f3a83d3d04",
"packages": [
{
"name": "automattic/jetpack-autoloader",
@ -532,16 +532,16 @@
},
{
"name": "woocommerce/woocommerce-admin",
"version": "2.5.0",
"version": "2.5.1",
"source": {
"type": "git",
"url": "https://github.com/woocommerce/woocommerce-admin.git",
"reference": "99a0bd3a48bf33a054efd3b0df29bf42766761f8"
"reference": "093d698d770f49d41df8abe89a716dc897bb9e96"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/99a0bd3a48bf33a054efd3b0df29bf42766761f8",
"reference": "99a0bd3a48bf33a054efd3b0df29bf42766761f8",
"url": "https://api.github.com/repos/woocommerce/woocommerce-admin/zipball/093d698d770f49d41df8abe89a716dc897bb9e96",
"reference": "093d698d770f49d41df8abe89a716dc897bb9e96",
"shasum": ""
},
"require": {
@ -596,22 +596,22 @@
"homepage": "https://github.com/woocommerce/woocommerce-admin",
"support": {
"issues": "https://github.com/woocommerce/woocommerce-admin/issues",
"source": "https://github.com/woocommerce/woocommerce-admin/tree/v2.5.0"
"source": "https://github.com/woocommerce/woocommerce-admin/tree/v2.5.1"
},
"time": "2021-08-09T21:00:32+00:00"
"time": "2021-08-16T14:31:33+00:00"
},
{
"name": "woocommerce/woocommerce-blocks",
"version": "v5.5.1",
"version": "v5.7.0",
"source": {
"type": "git",
"url": "https://github.com/woocommerce/woocommerce-gutenberg-products-block.git",
"reference": "f3d8dbadb745cbb2544e86dfb3864e870146d197"
"reference": "6056eb0fd5ec74972237faa6ed0f08f774466324"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/woocommerce/woocommerce-gutenberg-products-block/zipball/f3d8dbadb745cbb2544e86dfb3864e870146d197",
"reference": "f3d8dbadb745cbb2544e86dfb3864e870146d197",
"url": "https://api.github.com/repos/woocommerce/woocommerce-gutenberg-products-block/zipball/6056eb0fd5ec74972237faa6ed0f08f774466324",
"reference": "6056eb0fd5ec74972237faa6ed0f08f774466324",
"shasum": ""
},
"require": {
@ -647,9 +647,9 @@
],
"support": {
"issues": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues",
"source": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/tree/v5.5.1"
"source": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/tree/v5.7.0"
},
"time": "2021-07-14T20:59:04+00:00"
"time": "2021-08-17T12:58:49+00:00"
}
],
"packages-dev": [

View File

@ -226,7 +226,7 @@ final class WC_Cart_Totals {
$item->taxable = 'taxable' === $cart_item['data']->get_tax_status();
$item->price_includes_tax = wc_prices_include_tax();
$item->quantity = $cart_item['quantity'];
$item->price = wc_add_number_precision_deep( $cart_item['data']->get_price() * $cart_item['quantity'] );
$item->price = wc_add_number_precision_deep( (float) $cart_item['data']->get_price() * (float) $cart_item['quantity'] );
$item->product = $cart_item['data'];
$item->tax_rates = $this->get_item_tax_rates( $item );
$this->items[ $cart_item_key ] = $item;

View File

@ -809,6 +809,7 @@ class WC_Countries {
'AF' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'AO' => array(
@ -826,6 +827,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'AU' => array(
@ -845,6 +847,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'BA' => array(
@ -871,7 +874,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'label' => __( 'Province', 'woocommerce' ),
'hidden' => true,
),
),
'BH' => array(
@ -880,11 +883,13 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'BI' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'BO' => array(
@ -949,6 +954,7 @@ class WC_Countries {
'CZ' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'DE' => array(
@ -975,6 +981,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'FI' => array(
@ -983,6 +990,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'FR' => array(
@ -991,6 +999,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'GH' => array(
@ -1004,11 +1013,13 @@ class WC_Countries {
'GP' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'GF' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'GR' => array(
@ -1082,6 +1093,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'IL' => array(
@ -1090,11 +1102,13 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'IM' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'IN' => array(
@ -1158,11 +1172,13 @@ class WC_Countries {
'KR' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'KW' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'LV' => array(
@ -1174,16 +1190,19 @@ class WC_Countries {
'LB' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'MQ' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'MT' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'MZ' => array(
@ -1201,7 +1220,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'label' => __( 'Province', 'woocommerce' ),
'hidden' => true,
),
),
'NG' => array(
@ -1229,6 +1248,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'NP' => array(
@ -1245,6 +1265,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'PR' => array(
@ -1259,11 +1280,13 @@ class WC_Countries {
'PT' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'RE' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'RO' => array(
@ -1287,6 +1310,7 @@ class WC_Countries {
'SG' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
'city' => array(
'required' => false,
@ -1298,6 +1322,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'SI' => array(
@ -1306,6 +1331,7 @@ class WC_Countries {
),
'state' => array(
'required' => false,
'hidden' => true,
),
),
'SR' => array(
@ -1334,11 +1360,13 @@ class WC_Countries {
'LK' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'LU' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'MD' => array(
@ -1427,6 +1455,7 @@ class WC_Countries {
'YT' => array(
'state' => array(
'required' => false,
'hidden' => true,
),
),
'ZA' => array(

View File

@ -84,7 +84,7 @@ class WC_Discounts {
$item->object = $cart_item;
$item->product = $cart_item['data'];
$item->quantity = $cart_item['quantity'];
$item->price = wc_add_number_precision_deep( $item->product->get_price() * $item->quantity );
$item->price = wc_add_number_precision_deep( (float) $item->product->get_price() * (float) $item->quantity );
$this->items[ $key ] = $item;
}

View File

@ -160,9 +160,6 @@ class WC_Tracker {
// Template overrides.
$data['template_overrides'] = self::get_all_template_overrides();
// Template overrides.
$data['admin_user_agents'] = self::get_admin_user_agents();
// Cart & checkout tech (blocks or shortcodes).
$data['cart_checkout'] = self::get_cart_checkout_info();
@ -619,6 +616,8 @@ class WC_Tracker {
'version' => WC()->version,
'currency' => get_woocommerce_currency(),
'base_location' => WC()->countries->get_base_country(),
'base_state' => WC()->countries->get_base_state(),
'base_postcode' => WC()->countries->get_base_postcode(),
'selling_locations' => WC()->countries->get_allowed_countries(),
'api_enabled' => get_option( 'woocommerce_api_enabled' ),
'weight_unit' => get_option( 'woocommerce_weight_unit' ),
@ -675,15 +674,6 @@ class WC_Tracker {
return $override_data;
}
/**
* When an admin user logs in, there user agent is tracked in user meta and collected here.
*
* @return array
*/
private static function get_admin_user_agents() {
return array_filter( (array) get_option( 'woocommerce_tracker_ua', array() ) );
}
/**
* Search a specific post for text content.
*

View File

@ -1315,8 +1315,6 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
AND p.post_type = 'product'
",
'orderby' => '
ORDER BY RAND()',
'limits' => '
LIMIT ' . absint( $limit ) . '
',

View File

@ -3532,9 +3532,9 @@
"dev": true
},
"path-parse": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
"dev": true
},
"performance-now": {

View File

@ -8,6 +8,7 @@ import {
const config = require('config');
const { HTTPClientFactory } = require('@woocommerce/api');
const { addConsoleSuppression, updateReadyPageStatus } = require( '@woocommerce/e2e-environment' );
const { DEFAULT_TIMEOUT_OVERRIDE } = process.env;
// @todo: remove this once https://github.com/woocommerce/woocommerce-admin/issues/6992 has been addressed
addConsoleSuppression( 'woocommerce_shared_settings' );
@ -38,6 +39,12 @@ async function trashExistingPosts() {
// other posts/comments/etc. aren't dirtying tests and tests don't depend on
// each other's side-effects.
beforeAll(async () => {
if ( DEFAULT_TIMEOUT_OVERRIDE ) {
page.setDefaultNavigationTimeout( DEFAULT_TIMEOUT_OVERRIDE );
page.setDefaultTimeout( DEFAULT_TIMEOUT_OVERRIDE );
}
// Update the ready page to prevent concurrent test runs
await updateReadyPageStatus('draft');

View File

@ -1,5 +1,3 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests */
/**
* Internal dependencies
*/
@ -10,7 +8,7 @@ const {
addShippingZoneAndMethod,
clearAndFillInput,
selectOptionInSelect2,
deleteAllShippingZones,
withRestApi,
} = require( '@woocommerce/e2e-utils' );
/**
@ -35,8 +33,8 @@ const runAddNewShippingZoneTest = () => {
describe('WooCommerce Shipping Settings - Add new shipping zone', () => {
beforeAll(async () => {
await createSimpleProduct();
await withRestApi.deleteAllShippingZones();
await merchant.login();
await deleteAllShippingZones();
});
it('add shipping zone for San Francisco with free Local pickup', async () => {
@ -86,7 +84,7 @@ const runAddNewShippingZoneTest = () => {
it('allows customer to benefit from a Free shipping if in CA', async () => {
await page.reload();
// Set shipping state to California
await expect(page).toClick('a.shipping-calculator-button');
await expect(page).toClick('#select2-calc_shipping_state-container');

View File

@ -1,16 +1,12 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests, jest/expect-expect */
/**
* Internal dependencies
*/
const {
shopper,
merchant,
createSimpleProduct,
addShippingZoneAndMethod,
clearAndFillInput,
uiUnblocked,
selectOptionInSelect2,
withRestApi,
} = require( '@woocommerce/e2e-utils' );
/**
@ -43,29 +39,21 @@ const runCartCalculateShippingTest = () => {
await createSimpleProduct(firstProductName);
await createSimpleProduct(secondProductName, secondProductPrice);
await merchant.login();
await merchant.openNewShipping();
await withRestApi.resetSettingsGroupToDefault( 'general' );
// Add a new shipping zone Germany with Free shipping
await addShippingZoneAndMethod(shippingZoneNameDE, shippingCountryDE, ' ', 'free_shipping');
await withRestApi.addShippingZoneAndMethod(shippingZoneNameDE, shippingCountryDE, ' ', 'free_shipping');
// Add a new shipping zone for France with Flat rate & Local pickup
await addShippingZoneAndMethod(shippingZoneNameFR, shippingCountryFR, ' ', 'flat_rate');
await page.waitFor(1000); // to avoid flakiness in headless
await page.click('a.wc-shipping-zone-method-settings', {text: 'Flat rate'});
await clearAndFillInput('#woocommerce_flat_rate_cost', '5');
await page.click('.wc-backbone-modal-main button#btn-ok');
// Add additional method Local pickup for the same location
await page.waitFor(1000); // to avoid flakiness in headless
await page.click('button.wc-shipping-zone-add-method', {text:'Add shipping method'});
await page.waitForSelector('.wc-shipping-zone-method-selector');
await page.select('select[name="add_method_id"]', 'local_pickup');
await page.click('button#btn-ok');
await page.waitForSelector('#zone_locations');
await merchant.logout();
await withRestApi.addShippingZoneAndMethod(shippingZoneNameFR, shippingCountryFR, ' ', 'flat_rate', '5', ['local_pickup']);
await shopper.emptyCart();
});
afterAll(async () => {
await withRestApi.deleteAllShippingZones();
});
it('allows customer to calculate Free Shipping if in Germany', async () => {
await shopper.goToShop();
await shopper.addToCartFromShopPage(firstProductName);
@ -76,6 +64,7 @@ const runCartCalculateShippingTest = () => {
await expect(page).toClick('#select2-calc_shipping_country-container');
await selectOptionInSelect2('Germany');
await expect(page).toClick('button[name="calc_shipping"]');
await uiUnblocked();
// Verify shipping costs
await page.waitForSelector('.order-total');
@ -84,13 +73,14 @@ const runCartCalculateShippingTest = () => {
});
it('allows customer to calculate Flat rate and Local pickup if in France', async () => {
await page.reload();
await page.reload( { waitUntil: ['networkidle0', 'domcontentloaded'] } );
// Set shipping country to France
await expect(page).toClick('a.shipping-calculator-button');
await expect(page).toClick('#select2-calc_shipping_country-container');
await selectOptionInSelect2('France');
await expect(page).toClick('button[name="calc_shipping"]');
await uiUnblocked();
// Verify shipping costs
await page.waitForSelector('.order-total');
@ -119,13 +109,14 @@ const runCartCalculateShippingTest = () => {
});
it('should show correct total cart price with 2 products without flat rate', async () => {
await page.reload();
await page.reload( { waitUntil: ['networkidle0', 'domcontentloaded'] } );
// Set shipping country to Spain
await expect(page).toClick('a.shipping-calculator-button');
await expect(page).toClick('#select2-calc_shipping_country-container');
await selectOptionInSelect2('Spain');
await expect(page).toClick('button[name="calc_shipping"]');
await uiUnblocked();
// Verify shipping costs
await page.waitForSelector('.order-total');

View File

@ -1,12 +1,14 @@
# Unreleased
- `updateReadyPageStatus` utility to update the status of the ready page
- Added plugin upload functionality util that provides a method to pull a plugin zip from a remote location
- `updateReadyPageStatus` utility to update the status of the ready page.
- Added plugin upload functionality util that provides a method to pull a plugin zip from a remote location:
- `getRemotePluginZip( fileUrl )` to get the remote zip. Returns the filepath of the zip location.
- Added plugin zip utility functions:
- `checkNestedZip( zipFilePath, savePath )` checks a plugin zip file for any nested zip files. If one is found, it is extracted. Returns the path where the zip file is located.
- `downloadZip( fileUrl, downloadPath )` downloads a plugin zip file from a remote location to the provided path.
- Added `getLatestReleaseZipUrl( owner, repository, getPrerelease, perPage )` util function to get the latest release zip from a GitHub repository
- Added `getLatestReleaseZipUrl( owner, repository, getPrerelease, perPage )` util function to get the latest release zip from a GitHub repository.
- Added `DEFAULT_TIMEOUT_OVERRIDE` that allows passing in a time in milliseconds to override the default Jest and Puppeteer timeouts.
- Update fallback WordPress version to 5.8.0.
# 0.2.2

View File

@ -87,6 +87,21 @@ await takeScreenshotFor( 'name of current step' );
Screenshots will be saved to `tests/e2e/screenshots`. This folder is cleared at the beginning of each test run.
### Override default test timeout
To override the default timeout for the tests, you can use the `DEFAULT_TIMEOUT_OVERRIDE` flag and pass in a maximum timeout in milliseconds. For example, you can pass it in when running the tests from the command line:
```bash
DEFAULT_TIMEOUT_OVERRIDE=35000 npx wc-e2e test:e2e
```
This value will override the default Jest timeout as well as pass the timeout to the following Puppeteer methods:
* page.setDefaultTimeout();
* page.setDefaultNavigationTimeout();
For a list of the methods that the above timeout affects, please see the Puppeteer documentation for [`page.setDefaultTimeout()`](https://pptr.dev/#?product=Puppeteer&version=v10.2.0&show=api-pagesetdefaulttimeouttimeout) and [`page.setDefaultNavigationTimeout`](https://pptr.dev/#?product=Puppeteer&version=v10.2.0&show=api-pagesetdefaultnavigationtimeouttimeout) for more information.
### Jest Puppeteer Config
The test sequencer uses the following default Puppeteer configuration:

View File

@ -10,7 +10,7 @@ if [[ $1 ]]; then
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+ ]]; then
export WORDPRESS_VERSION=$WP_VERSION
else
export WORDPRESS_VERSION="5.5.1"
export WORDPRESS_VERSION="5.8.0"
fi
if ! [[ $TRAVIS_PHP_VERSION =~ ^[0-9]+\.[0-9]+ ]]; then

View File

@ -5,7 +5,7 @@ const program = require( 'commander' );
const path = require( 'path' );
const fs = require( 'fs' );
const { getAppRoot } = require( '../utils' );
const { WC_E2E_SCREENSHOTS, JEST_PUPPETEER_CONFIG } = process.env;
const { WC_E2E_SCREENSHOTS, JEST_PUPPETEER_CONFIG, DEFAULT_TIMEOUT_OVERRIDE } = process.env;
program
.usage( '<file ...> [options]' )
@ -43,6 +43,10 @@ let testEnvVars = {
jest_test_timeout: program.dev ? 120000 : 30000,
};
if ( DEFAULT_TIMEOUT_OVERRIDE ) {
testEnvVars.jest_test_timeout = DEFAULT_TIMEOUT_OVERRIDE;
}
if ( ! JEST_PUPPETEER_CONFIG ) {
// Use local Puppeteer config if there is one.
// Load test configuration file into an object.

View File

@ -16,6 +16,7 @@
- Added `deleteAllOrders()` that goes through and deletes all orders
- Added `deleteAllShippingClasses()` which permanently deletes all shipping classes using the API
- Added `statuses` optional parameter to `deleteAllRepositoryObjects()` to delete on specific statuses
- Updated `addShippingZoneAndMethod` to use the API instead of UI to create shipping zones
# 0.1.5

View File

@ -2,7 +2,7 @@
"name": "@woocommerce/e2e-utils",
"version": "0.1.5",
"description": "End-To-End (E2E) test utils for WooCommerce",
"homepage": "https://github.com/woocommerce/woocommerce/tree/trunk/tests/utils/README.md",
"homepage": "https://github.com/woocommerce/woocommerce/tree/trunk/tests/e2e/utils/README.md",
"repository": {
"type": "git",
"url": "https://github.com/woocommerce/woocommerce.git"

View File

@ -93,6 +93,79 @@ export const withRestApi = {
const repository = Order.restRepository( client );
await deleteAllRepositoryObjects( repository, null, orderStatuses );
},
/**
* Adds a shipping zone along with a shipping method using the API.
*
* @param zoneName Shipping zone name.
* @param zoneLocation Shiping zone location. Defaults to country:US. For states use: state:US:CA.
* @param zipCode Shipping zone zip code. Default is no zip code.
* @param zoneMethod Shipping method type. Defaults to flat_rate (use also: free_shipping or local_pickup).
* @param cost Shipping method cost. Default is no cost.
* @param additionalZoneMethods Array of additional zone methods to add to the shipping zone.
*/
addShippingZoneAndMethod: async (
zoneName,
zoneLocation = 'country:US',
zipCode = '',
zoneMethod = 'flat_rate',
cost = '',
additionalZoneMethods = [] ) => {
const path = 'wc/v3/shipping/zones';
const response = await client.post( path, { name: zoneName } );
expect(response.statusCode).toEqual(201);
let zoneId = response.data.id;
// Select shipping zone location
let [ zoneType, zoneCode ] = zoneLocation.split(/:(.+)/);
let zoneLocationPayload = [
{
code: zoneCode,
type: zoneType,
}
];
// Fill shipping zone postcode if provided
if ( zipCode ) {
zoneLocationPayload.push( {
code: zipCode,
type: "postcode",
} );
}
const locationResponse = await client.put( path + `/${zoneId}/locations`, zoneLocationPayload );
expect(locationResponse.statusCode).toEqual(200);
// Add shipping zone method
let methodPayload = {
method_id: zoneMethod
}
const methodsResponse = await client.post( path + `/${zoneId}/methods`, methodPayload );
expect(methodsResponse.statusCode).toEqual(200);
let methodId = methodsResponse.data.id;
// Add in cost, if provided
if ( cost ) {
let costPayload = {
settings: {
cost: cost
}
}
const costResponse = await client.put( path + `/${zoneId}/methods/${methodId}`, costPayload );
expect(costResponse.statusCode).toEqual(200);
}
// Add any additional zones, if provided
if (additionalZoneMethods.length > 0) {
for ( let z = 0; z < additionalZoneMethods.length; z++ ) {
let response = await client.post( path + `/${zoneId}/methods`, { method_id: additionalZoneMethods[z] } );
expect(response.statusCode).toEqual(200);
}
}
},
/**
* Use api package to delete shipping zones.
*