wip: setup taxes through API

This commit is contained in:
rodel 2021-03-23 08:09:58 -07:00
parent 4f861c9b7a
commit a24479d596
2 changed files with 75 additions and 28 deletions

View File

@ -12,10 +12,13 @@
},
"products": {
"simple": {
"name": "Simple product"
"name": "Simple product",
"regularPrice": "100.00",
"taxClass": "Standard"
},
"variable": {
"name": "Variable Product with Three Attributes",
"taxClass": "Reduced rate",
"defaultAttributes": [
{
"id": 0,
@ -34,11 +37,7 @@
"name": "Colour",
"isVisibleOnProductPage": true,
"isForVariations": true,
"options": [
"Red",
"Green",
"Blue"
],
"options": ["Red", "Green", "Blue"],
"sortOrder": 0
},
{
@ -46,11 +45,7 @@
"name": "Size",
"isVisibleOnProductPage": true,
"isForVariations": true,
"options": [
"Small",
"Medium",
"Large"
],
"options": ["Small", "Medium", "Large"],
"sortOrder": 0
},
{
@ -58,10 +53,7 @@
"name": "Logo",
"isVisibleOnProductPage": true,
"isForVariations": true,
"options": [
"Woo",
"WordPress"
],
"options": ["Woo", "WordPress"],
"sortOrder": 0
}
]
@ -112,21 +104,25 @@
"groupedProducts": [
{
"name": "Base Unit",
"regularPrice": "29.99"
"regularPrice": "29.99",
"taxClass": "Standard"
},
{
"name": "Add-on A",
"regularPrice": "11.95"
"regularPrice": "11.95",
"taxClass": "Reduced rate"
},
{
"name": "Add-on B",
"regularPrice": "18.97"
"regularPrice": "18.97",
"taxClass": "Zero rate"
}
]
},
"external": {
"name": "External product",
"regularPrice": "24.99",
"taxClass": "Zero rate",
"buttonText": "Buy now",
"externalUrl": "https://wordpress.org/plugins/woocommerce"
}

View File

@ -18,20 +18,37 @@ const { HTTPClientFactory,
let variations;
let products;
const taxRates = [
{
name: 'My Standard Tax 1',
rate: '10',
class: 'standard'
},
{
name: 'My Reduced Rate Tax 2',
rate: '20',
class: 'reduced-rate'
},
{
name: 'My Zero Rate Tax 3',
rate: '30',
class: 'zero-rate'
}
];
const runCreateOrderTest = () => {
describe('WooCommerce Orders > Add new order', () => {
beforeAll(async () => {
// Initialize HTTP client
const apiUrl = config.get('url');
const adminUsername = config.get('users.admin.username');
const adminPassword = config.get('users.admin.password');
const httpClient = HTTPClientFactory.build(apiUrl)
.withBasicAuth(adminUsername, adminPassword)
.create();
// Initialize products for each product type
const initProducts = async () => {
// Initialize HTTP client
const apiUrl = config.get('url');
const adminUsername = config.get('users.admin.username');
const adminPassword = config.get('users.admin.password');
const httpClient = HTTPClientFactory.build(apiUrl)
.withBasicAuth(adminUsername, adminPassword)
.create();
// Initialization functions per product type
const initSimpleProduct = async () => {
const repo = SimpleProduct.restRepository(httpClient);
@ -76,6 +93,42 @@ const runCreateOrderTest = () => {
};
products = await initProducts();
// Initialize tax rates & classes
const initTaxes = async () => {
// Enable taxes in settings
const enableTaxes = async () => {
const path = '/wc/v3/settings/general/woocommerce_calc_taxes';
const data = {
value: 'yes'
}
await httpClient.put(path, data);
}
await enableTaxes();
// Delete existing tax rates
const deleteTaxRates = async () => {
const path = '/wc/v3/taxes';
await httpClient.get(path).then(async (response) => {
for (const { id } of response.data) {
await httpClient.delete(`${path}/${id}?force=true`);
}
});
};
await deleteTaxRates();
// Set up tax rates
const createTaxRates = async () => {
const path = '/wc/v3/taxes';
for (const t of taxRates) {
await httpClient.post(path, t);
}
};
await createTaxRates();
return taxRates;
};
await initTaxes();
// Login
await merchant.login();
});
@ -104,8 +157,6 @@ const runCreateOrderTest = () => {
// todo remove .only
it('can create new complex order with multiple product types & tax classes', async () => {
// Go to "add order" page
await merchant.openNewOrder();