wip: setup products via API instead of UI
This commit is contained in:
parent
8614134887
commit
2e667ae317
|
@ -5,44 +5,17 @@
|
||||||
const {
|
const {
|
||||||
merchant,
|
merchant,
|
||||||
verifyPublishAndTrash,
|
verifyPublishAndTrash,
|
||||||
createSimpleProduct,
|
|
||||||
createVariableProduct,
|
|
||||||
createGroupedProduct,
|
|
||||||
uiUnblocked
|
uiUnblocked
|
||||||
} = require('@woocommerce/e2e-utils');
|
} = require('@woocommerce/e2e-utils');
|
||||||
const faker = require('faker');
|
const faker = require('faker');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
|
const { HTTPClientFactory,
|
||||||
/**
|
VariableProduct,
|
||||||
* Create different product types
|
GroupedProduct,
|
||||||
*/
|
SimpleProduct,
|
||||||
const setupProducts = async () => {
|
ProductAttribute,
|
||||||
const simpleProduct = {
|
ProductVariation
|
||||||
name: faker.commerce.productName(),
|
} = require('@woocommerce/api');
|
||||||
price: faker.commerce.price(1, 999),
|
|
||||||
id: null
|
|
||||||
}
|
|
||||||
const variableProduct = {
|
|
||||||
name: 'Variable Product with Three Variations',
|
|
||||||
prices: [9.99, 11.99, 20.00],
|
|
||||||
id: null
|
|
||||||
}
|
|
||||||
const groupedProduct = {
|
|
||||||
name: config.get('products.simple.name'),
|
|
||||||
simpleProductPrice: config.has('products.simple.price') ? config.get('products.simple.price') : '9.99',
|
|
||||||
id: null
|
|
||||||
}
|
|
||||||
|
|
||||||
simpleProduct.id = await createSimpleProduct(simpleProduct.name, simpleProduct.price)
|
|
||||||
variableProduct.id = await createVariableProduct();
|
|
||||||
groupedProduct.id = await createGroupedProduct()
|
|
||||||
|
|
||||||
return [
|
|
||||||
simpleProduct,
|
|
||||||
variableProduct,
|
|
||||||
groupedProduct
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
const runCreateOrderTest = () => {
|
const runCreateOrderTest = () => {
|
||||||
describe('WooCommerce Orders > Add new order', () => {
|
describe('WooCommerce Orders > Add new order', () => {
|
||||||
|
@ -74,8 +47,40 @@ const runCreateOrderTest = () => {
|
||||||
|
|
||||||
// todo remove .only
|
// todo remove .only
|
||||||
it('can create new complex order with multiple product types & tax classes', async () => {
|
it('can create new complex order with multiple product types & tax classes', async () => {
|
||||||
// todo setup products and tax classes
|
// Initialize different product types
|
||||||
const products = await setupProducts();
|
const initProducts = async () => {
|
||||||
|
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();
|
||||||
|
const productName = () => faker.commerce.productName();
|
||||||
|
const price = () => faker.commerce.price(1, 999);
|
||||||
|
|
||||||
|
// Initialize repositories
|
||||||
|
const simpleRepo = SimpleProduct.restRepository(httpClient);
|
||||||
|
const variableRepo = VariableProduct.restRepository(httpClient);
|
||||||
|
const groupedRepo = GroupedProduct.restRepository(httpClient);
|
||||||
|
|
||||||
|
|
||||||
|
// Initialize products
|
||||||
|
const simpleProduct = await simpleRepo.create({ name: productName(), price: price() });
|
||||||
|
const variableProduct = await variableRepo.create({ name: productName() });
|
||||||
|
const groupMemberProduct1 = await simpleRepo.create({ name: productName(), price: price() });
|
||||||
|
const groupMemberProduct2 = await simpleRepo.create({ name: productName(), price: price() });
|
||||||
|
const groupedProduct = await groupedRepo.create({
|
||||||
|
name: productName(),
|
||||||
|
groupedProducts: [groupMemberProduct1.id, groupMemberProduct2.id]
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
simpleProduct,
|
||||||
|
variableProduct,
|
||||||
|
groupedProduct
|
||||||
|
];
|
||||||
|
}
|
||||||
|
const products = await initProducts();
|
||||||
|
|
||||||
// Go to "add order" page
|
// Go to "add order" page
|
||||||
await merchant.openNewOrder();
|
await merchant.openNewOrder();
|
||||||
|
@ -102,6 +107,9 @@ const runCreateOrderTest = () => {
|
||||||
for (const { name } of products) {
|
for (const { name } of products) {
|
||||||
await expect(page).toMatchElement('.wc-order-item-name', { text: name });
|
await expect(page).toMatchElement('.wc-order-item-name', { text: name });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify variation details in variable product line item
|
||||||
|
await expect(page).toMatchElement('.wc-order-item-variation', { text: products.filter(p => p.variations).id })
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue