saleor-dashboard/cypress/utils/productsUtils.js

137 lines
3.4 KiB
JavaScript
Raw Normal View History

import Attribute from "../apiRequests/Attribute";
import Category from "../apiRequests/Category";
import Product from "../apiRequests/Product";
2021-02-16 14:19:46 +00:00
import Promises from "../support/promises/promises.js";
class ProductsUtils {
2021-02-16 14:19:46 +00:00
promises = new Promises();
productRequest = new Product();
attributeRequest = new Attribute();
categoryRequest = new Category();
2021-02-16 14:19:46 +00:00
product;
variants;
productType;
attribute;
category;
async createProductInChannel(
name,
channelId,
warehouseId,
quantityInWarehouse,
productTypeId,
attributeId,
categoryId,
price
) {
2021-02-16 14:19:46 +00:00
await this.createProduct(attributeId, name, productTypeId, categoryId);
this.updateChannelInProduct(this.product.id, channelId);
await this.createVariant(
this.product.id,
name,
warehouseId,
quantityInWarehouse,
channelId,
price
);
}
2021-02-16 14:19:46 +00:00
async createTypeAttributeAndCategoryForProduct(name) {
await this.createAttribute(name);
await this.createTypeProduct(name, this.attribute.id);
await this.createCategory(name);
}
async createAttribute(name) {
const respProm = await this.promises.createPromise(
this.attributeRequest.createAttribute(name)
);
this.attribute = respProm.attributeCreate.attribute;
}
async createTypeProduct(name, attributeId) {
const respProm = await this.promises.createPromise(
this.productRequest.createTypeProduct(name, attributeId)
);
this.productType = respProm.productTypeCreate.productType;
}
async createCategory(name) {
const respProm = await this.promises.createPromise(
this.categoryRequest.createCategory(name)
);
this.category = respProm.categoryCreate.category;
}
async createProduct(attributeId, name, productTypeId, categoryId) {
const respProm = await this.promises.createPromise(
this.productRequest.createProduct(
attributeId,
name,
productTypeId,
categoryId
)
);
this.product = respProm.productCreate.product;
}
async updateChannelInProduct(productId, channelId) {
await this.promises.createPromise(
this.productRequest.updateChannelInProduct(productId, channelId)
);
}
async createVariant(
productId,
name,
warehouseId,
quantityInWarehouse,
channelId,
price
) {
const respProm = await this.promises.createPromise(
this.productRequest.createVariant(
productId,
name,
warehouseId,
quantityInWarehouse,
channelId,
price
)
);
this.variants = respProm.productVariantBulkCreate.productVariants;
}
getCreatedVariants() {
2021-02-16 14:19:46 +00:00
return this.variants;
}
2021-02-16 14:19:46 +00:00
getProductType() {
return this.productType;
}
2021-02-16 14:19:46 +00:00
getAttribute() {
return this.attribute;
}
2021-02-16 14:19:46 +00:00
getCategory() {
return this.category;
}
2021-02-16 14:19:46 +00:00
deleteProperProducts(startsWith) {
const product = new Product();
const attribute = new Attribute();
const category = new Category();
2021-02-16 14:19:46 +00:00
cy.deleteProperElements(
product.deleteProductType,
product.getProductTypes,
startsWith,
"productType"
);
cy.deleteProperElements(
attribute.deleteAttribute,
attribute.getAttributes,
startsWith,
"attributes"
);
cy.deleteProperElements(
category.deleteCategory,
category.getCategories,
startsWith,
"categories"
);
}
}
2021-02-11 12:20:00 +00:00
export default ProductsUtils;