move coupon delete, add tax classes, rates to withRestApi
This commit is contained in:
parent
a6df312732
commit
eeb331f160
|
@ -1,83 +0,0 @@
|
||||||
/* eslint-disable jest/no-export, jest/no-disabled-tests */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal dependencies
|
|
||||||
*/
|
|
||||||
const {
|
|
||||||
merchant,
|
|
||||||
completeOnboardingWizard,
|
|
||||||
withRestApi,
|
|
||||||
addShippingZoneAndMethod,
|
|
||||||
IS_RETEST_MODE,
|
|
||||||
} = require( '@woocommerce/e2e-utils' );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* External dependencies
|
|
||||||
*/
|
|
||||||
const config = require( 'config' );
|
|
||||||
const {
|
|
||||||
it,
|
|
||||||
describe,
|
|
||||||
} = require( '@jest/globals' );
|
|
||||||
|
|
||||||
const shippingZoneNameUS = config.get( 'addresses.customer.shipping.country' );
|
|
||||||
|
|
||||||
const runOnboardingFlowTest = () => {
|
|
||||||
describe('Store owner can go through store Onboarding', () => {
|
|
||||||
if ( IS_RETEST_MODE ) {
|
|
||||||
it('can reset onboarding to default settings', async () => {
|
|
||||||
await withRestApi.resetOnboarding();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can reset shipping zones to default settings', async () => {
|
|
||||||
await withRestApi.deleteAllShippingZones();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can reset to default settings', async () => {
|
|
||||||
await withRestApi.resetSettingsGroupToDefault('general');
|
|
||||||
await withRestApi.resetSettingsGroupToDefault('products');
|
|
||||||
await withRestApi.resetSettingsGroupToDefault('tax');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
it('can start and complete onboarding when visiting the site for the first time.', async () => {
|
|
||||||
await completeOnboardingWizard();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const runTaskListTest = () => {
|
|
||||||
describe('Store owner can go through setup Task List', () => {
|
|
||||||
it('can setup shipping', async () => {
|
|
||||||
await page.evaluate(() => {
|
|
||||||
document.querySelector('.woocommerce-list__item-title').scrollIntoView();
|
|
||||||
});
|
|
||||||
// Query for all tasks on the list
|
|
||||||
const taskListItems = await page.$$('.woocommerce-list__item-title');
|
|
||||||
expect(taskListItems.length).toBeInRange( 5, 6 );
|
|
||||||
|
|
||||||
// Work around for https://github.com/woocommerce/woocommerce-admin/issues/6761
|
|
||||||
if ( taskListItems.length == 6 ) {
|
|
||||||
// Click on "Set up shipping" task to move to the next step
|
|
||||||
const [ setupTaskListItem ] = await page.$x( '//div[contains(text(),"Set up shipping")]' );
|
|
||||||
await setupTaskListItem.click();
|
|
||||||
|
|
||||||
// Wait for "Proceed" button to become active
|
|
||||||
await page.waitForSelector('button.is-primary:not(:disabled)');
|
|
||||||
await page.waitFor(3000);
|
|
||||||
|
|
||||||
// Click on "Proceed" button to save shipping settings
|
|
||||||
await page.click('button.is-primary');
|
|
||||||
await page.waitFor(3000);
|
|
||||||
} else {
|
|
||||||
await merchant.openNewShipping();
|
|
||||||
await addShippingZoneAndMethod(shippingZoneNameUS);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
runOnboardingFlowTest,
|
|
||||||
runTaskListTest,
|
|
||||||
};
|
|
|
@ -5,9 +5,8 @@ const {
|
||||||
merchant,
|
merchant,
|
||||||
clickTab,
|
clickTab,
|
||||||
AdminEdit,
|
AdminEdit,
|
||||||
factories,
|
withRestApi,
|
||||||
} = require( '@woocommerce/e2e-utils' );
|
} = require( '@woocommerce/e2e-utils' );
|
||||||
const { Coupon } = require( '@woocommerce/api' );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
|
@ -50,8 +49,7 @@ const runCreateCouponTest = () => {
|
||||||
// Delete the coupon
|
// Delete the coupon
|
||||||
const couponId = await adminEdit.getId();
|
const couponId = await adminEdit.getId();
|
||||||
if ( couponId ) {
|
if ( couponId ) {
|
||||||
const repository = Coupon.restRepository( factories.api.withDefaultPermalinks );
|
await withRestApi.deleteCoupon( couponId );
|
||||||
await repository.delete( couponId );
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
const {
|
const {
|
||||||
merchant,
|
merchant,
|
||||||
uiUnblocked,
|
uiUnblocked,
|
||||||
|
withRestApi,
|
||||||
AdminEdit,
|
AdminEdit,
|
||||||
} = require('@woocommerce/e2e-utils');
|
} = require( '@woocommerce/e2e-utils' );
|
||||||
const config = require('config');
|
const config = require( 'config' );
|
||||||
const {
|
const {
|
||||||
HTTPClientFactory,
|
HTTPClientFactory,
|
||||||
VariableProduct,
|
VariableProduct,
|
||||||
|
@ -14,22 +15,34 @@ const {
|
||||||
SimpleProduct,
|
SimpleProduct,
|
||||||
ProductVariation,
|
ProductVariation,
|
||||||
ExternalProduct
|
ExternalProduct
|
||||||
} = require('@woocommerce/api');
|
} = require( '@woocommerce/api' );
|
||||||
|
|
||||||
|
const taxClasses = [
|
||||||
|
{
|
||||||
|
name: 'Tax Class Simple',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Tax Class Variable',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Tax Class External',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const taxRates = [
|
const taxRates = [
|
||||||
{
|
{
|
||||||
name: 'Tax Rate Simple',
|
name: 'Tax Rate Simple',
|
||||||
rate: '10',
|
rate: '10.0000',
|
||||||
class: 'tax-class-simple'
|
class: 'tax-class-simple'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Tax Rate Variable',
|
name: 'Tax Rate Variable',
|
||||||
rate: '20',
|
rate: '20.0000',
|
||||||
class: 'tax-class-variable'
|
class: 'tax-class-variable'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Tax Rate External',
|
name: 'Tax Rate External',
|
||||||
rate: '30',
|
rate: '30.0000',
|
||||||
class: 'tax-class-external'
|
class: 'tax-class-external'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -43,60 +56,22 @@ const initProducts = async () => {
|
||||||
const httpClient = HTTPClientFactory.build(apiUrl)
|
const httpClient = HTTPClientFactory.build(apiUrl)
|
||||||
.withBasicAuth(adminUsername, adminPassword)
|
.withBasicAuth(adminUsername, adminPassword)
|
||||||
.create();
|
.create();
|
||||||
const taxClassesPath = '/wc/v3/taxes/classes';
|
|
||||||
const taxClasses = [
|
|
||||||
{
|
|
||||||
name: 'Tax Class Simple',
|
|
||||||
slug: 'tax-class-simple-698962'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Tax Class Variable',
|
|
||||||
slug: 'tax-class-variable-790238'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Tax Class External',
|
|
||||||
slug: 'tax-class-external-991321'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
// Enable taxes in settings
|
await withRestApi.updateSettingOption( 'general', 'woocommerce_calc_taxes', { value: 'yes' } );
|
||||||
const enableTaxes = async () => {
|
await withRestApi.addTaxClasses( taxClasses );
|
||||||
const path = '/wc/v3/settings/general/woocommerce_calc_taxes';
|
await withRestApi.addTaxRates( taxRates );
|
||||||
const data = {
|
|
||||||
value: 'yes'
|
|
||||||
};
|
|
||||||
await httpClient.put(path, data);
|
|
||||||
};
|
|
||||||
await enableTaxes();
|
|
||||||
|
|
||||||
// Initialize tax classes
|
|
||||||
const initTaxClasses = async () => {
|
|
||||||
for (const classToBeAdded of taxClasses) {
|
|
||||||
await httpClient.post(taxClassesPath, classToBeAdded);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
await initTaxClasses();
|
|
||||||
|
|
||||||
// Initialize tax rates
|
|
||||||
const initTaxRates = async () => {
|
|
||||||
const path = '/wc/v3/taxes';
|
|
||||||
|
|
||||||
for (const rateToBeAdded of taxRates) {
|
|
||||||
await httpClient.post(path, rateToBeAdded);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
await initTaxRates();
|
|
||||||
|
|
||||||
// Initialization functions per product type
|
// Initialization functions per product type
|
||||||
const initSimpleProduct = async () => {
|
const initSimpleProduct = async () => {
|
||||||
const repo = SimpleProduct.restRepository(httpClient);
|
const repo = SimpleProduct.restRepository( httpClient );
|
||||||
const simpleProduct = {
|
const simpleProduct = {
|
||||||
name: 'Simple Product 273722',
|
name: 'Simple Product 273722',
|
||||||
regularPrice: '100',
|
regularPrice: '100',
|
||||||
taxClass: 'Tax Class Simple'
|
taxClass: 'Tax Class Simple'
|
||||||
};
|
};
|
||||||
return await repo.create(simpleProduct);
|
return await repo.create( simpleProduct );
|
||||||
};
|
};
|
||||||
|
|
||||||
const initVariableProduct = async () => {
|
const initVariableProduct = async () => {
|
||||||
const variations = [
|
const variations = [
|
||||||
{
|
{
|
||||||
|
@ -264,12 +239,12 @@ const runCreateOrderTest = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that the names of each tax class were shown
|
// Verify that the names of each tax class were shown
|
||||||
for (const { name } of taxRates) {
|
for (const taxRate of taxRates) {
|
||||||
await expect(page).toMatchElement('th.line_tax', {
|
await expect(page).toMatchElement('th.line_tax', {
|
||||||
text: name
|
text: taxRate.name
|
||||||
});
|
});
|
||||||
await expect(page).toMatchElement('.wc-order-totals td.label', {
|
await expect(page).toMatchElement('.wc-order-totals td.label', {
|
||||||
text: name
|
text: taxRate.name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,13 +190,13 @@ const completeOnboardingWizard = async () => {
|
||||||
/**
|
/**
|
||||||
* Create simple product.
|
* Create simple product.
|
||||||
*
|
*
|
||||||
* @param productTitle - Defaults to Simple Product. Customizable title.
|
* @param productTitle Defaults to Simple Product. Customizable title.
|
||||||
* @param productPrice - Defaults to $9.99. Customizable pricing.
|
* @param productPrice Defaults to $9.99. Customizable pricing.
|
||||||
*/
|
*/
|
||||||
const createSimpleProduct = async ( productTitle = simpleProductName, productPrice = simpleProductPrice ) => {
|
const createSimpleProduct = async ( productTitle = simpleProductName, productPrice = simpleProductPrice ) => {
|
||||||
const product = await factories.products.simple.create( {
|
const product = await factories.products.simple.create( {
|
||||||
name: productTitle,
|
name: productTitle,
|
||||||
regularPrice: productPrice
|
regularPrice: productPrice,
|
||||||
} );
|
} );
|
||||||
return product.id;
|
return product.id;
|
||||||
} ;
|
} ;
|
||||||
|
|
|
@ -4,12 +4,14 @@ import {Coupon, Setting, SimpleProduct, Order} from '@woocommerce/api';
|
||||||
|
|
||||||
const client = factories.api.withDefaultPermalinks;
|
const client = factories.api.withDefaultPermalinks;
|
||||||
const onboardingProfileEndpoint = '/wc-admin/onboarding/profile';
|
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';
|
|
||||||
const productsEndpoint = '/wc/v3/products';
|
const productsEndpoint = '/wc/v3/products';
|
||||||
const productCategoriesEndpoint = '/wc/v3/products/categories';
|
const productCategoriesEndpoint = '/wc/v3/products/categories';
|
||||||
|
const shippingClassesEndpoint = '/wc/v3/products/shipping_classes';
|
||||||
|
const shippingZoneEndpoint = '/wc/v3/shipping/zones';
|
||||||
|
const systemStatusEndpoint = '/wc/v3/system_status';
|
||||||
|
const taxClassesEndpoint = '/wc/v3/taxes/classes';
|
||||||
|
const taxRatesEndpoint = '/wc/v3/taxes';
|
||||||
|
const userEndpoint = '/wp/v2/users';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function to delete all merchant created data store objects.
|
* Utility function to delete all merchant created data store objects.
|
||||||
|
@ -42,6 +44,16 @@ const deleteAllRepositoryObjects = async ( repository, defaultObjectId = null, s
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility to flatten a tax rate.
|
||||||
|
*
|
||||||
|
* @param {object} taxRate Tax rate to be flattened.
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
const flattenTaxRate = ( taxRate ) => {
|
||||||
|
return taxRate.rate + '/' + taxRate.class + '/' + taxRate.name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility functions that use the REST API to process the requested function.
|
* Utility functions that use the REST API to process the requested function.
|
||||||
*/
|
*/
|
||||||
|
@ -77,6 +89,16 @@ export const withRestApi = {
|
||||||
const repository = Coupon.restRepository( client );
|
const repository = Coupon.restRepository( client );
|
||||||
await deleteAllRepositoryObjects( repository );
|
await deleteAllRepositoryObjects( repository );
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Use api package to delete a coupon.
|
||||||
|
*
|
||||||
|
* @param {number} couponId Coupon ID.
|
||||||
|
* @return {Promise} Promise resolving once coupon has been deleted.
|
||||||
|
*/
|
||||||
|
deleteCoupon: async ( couponId ) => {
|
||||||
|
const repository = Coupon.restRepository( client );
|
||||||
|
await repository.delete( couponId );
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Use api package to delete products.
|
* Use api package to delete products.
|
||||||
*
|
*
|
||||||
|
@ -331,13 +353,46 @@ export const withRestApi = {
|
||||||
*
|
*
|
||||||
* @param orders Array of orders to be created
|
* @param orders Array of orders to be created
|
||||||
*/
|
*/
|
||||||
batchCreateOrders: async (orders) => {
|
batchCreateOrders: async ( orders ) => {
|
||||||
const path = '/wc/v3/orders/batch';
|
const path = '/wc/v3/orders/batch';
|
||||||
const payload = { create: orders };
|
const payload = { create: orders };
|
||||||
|
|
||||||
const response = await client.post(path, payload);
|
const response = await client.post(path, payload);
|
||||||
expect( response.status ).toEqual(200);
|
expect( response.status ).toEqual(200);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Add tax classes.
|
||||||
|
*
|
||||||
|
* @param {<Array<Object>>} taxClasses Array of tax class objects.
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
addTaxClasses: async ( taxClasses ) => {
|
||||||
|
// Only add tax classes which don't already exist.
|
||||||
|
const existingTaxClasses = await client.get( taxClassesEndpoint );
|
||||||
|
const existingTaxNames = existingTaxClasses.data.map( taxClass => taxClass.name );
|
||||||
|
const newTaxClasses = taxClasses.filter( taxClass => ! existingTaxNames.includes( taxClass.name ) );
|
||||||
|
|
||||||
|
for ( const taxClass of newTaxClasses ) {
|
||||||
|
await client.post( taxClassesEndpoint, taxClass );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Add tax rates.
|
||||||
|
*
|
||||||
|
* @param {<Array<Object>>} taxRates Array of tax rate objects.
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
addTaxRates: async ( taxRates ) => {
|
||||||
|
// Only add rates which don't already exist
|
||||||
|
const existingTaxRates = await client.get( taxRatesEndpoint );
|
||||||
|
const existingRates = existingTaxRates.data.map( taxRate => flattenTaxRate( taxRate ) );
|
||||||
|
|
||||||
|
for ( const taxRate of taxRates ) {
|
||||||
|
if ( ! existingRates.includes( flattenTaxRate( taxRate ) ) ) {
|
||||||
|
await client.post( taxRatesEndpoint, taxRate );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Get the current environment from the WooCommerce system status API.
|
* Get the current environment from the WooCommerce system status API.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue