2021-02-04 11:15:27 +00:00
|
|
|
import Attribute from "../apiRequests/Attribute";
|
|
|
|
import Category from "../apiRequests/Category";
|
|
|
|
import Product from "../apiRequests/Product";
|
|
|
|
|
|
|
|
class ProductsUtils {
|
2021-02-16 14:19:46 +00:00
|
|
|
productRequest = new Product();
|
|
|
|
attributeRequest = new Attribute();
|
|
|
|
categoryRequest = new Category();
|
2021-02-04 11:15:27 +00:00
|
|
|
|
2021-02-16 14:19:46 +00:00
|
|
|
product;
|
|
|
|
variants;
|
|
|
|
productType;
|
|
|
|
attribute;
|
|
|
|
category;
|
|
|
|
|
2021-02-18 15:28:29 +00:00
|
|
|
createProductWithVariant(name, attributeId, productTypeId, categoryId) {
|
|
|
|
return this.createProduct(
|
|
|
|
attributeId,
|
|
|
|
name,
|
|
|
|
productTypeId,
|
|
|
|
categoryId
|
2021-02-19 08:45:34 +00:00
|
|
|
).then(() => this.createVariant(this.product.id, name, attributeId));
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-18 15:28:29 +00:00
|
|
|
|
2021-02-04 11:15:27 +00:00
|
|
|
createProductInChannel(
|
|
|
|
name,
|
|
|
|
channelId,
|
|
|
|
warehouseId,
|
|
|
|
quantityInWarehouse,
|
2021-02-02 11:34:10 +00:00
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
2021-02-18 18:28:01 +00:00
|
|
|
price,
|
|
|
|
isPublished = true,
|
|
|
|
isAvailableForPurchase = true,
|
|
|
|
visibleInListings = true
|
2021-02-04 11:15:27 +00:00
|
|
|
) {
|
2021-02-16 20:48:37 +00:00
|
|
|
return this.createProduct(attributeId, name, productTypeId, categoryId)
|
|
|
|
.then(() =>
|
2021-02-18 18:28:01 +00:00
|
|
|
this.productRequest.updateChannelInProduct(
|
|
|
|
this.product.id,
|
|
|
|
channelId,
|
|
|
|
isPublished,
|
|
|
|
isAvailableForPurchase,
|
|
|
|
visibleInListings
|
|
|
|
)
|
2021-02-16 20:48:37 +00:00
|
|
|
)
|
|
|
|
.then(() => {
|
|
|
|
this.createVariant(
|
|
|
|
this.product.id,
|
|
|
|
name,
|
|
|
|
warehouseId,
|
|
|
|
quantityInWarehouse,
|
|
|
|
channelId,
|
|
|
|
price
|
|
|
|
);
|
2021-02-04 11:15:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
createTypeAttributeAndCategoryForProduct(name) {
|
2021-02-16 20:48:37 +00:00
|
|
|
return this.createAttribute(name)
|
|
|
|
.then(() => this.createTypeProduct(name, this.attribute.id))
|
|
|
|
.then(() => this.createCategory(name));
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-16 20:48:37 +00:00
|
|
|
createAttribute(name) {
|
|
|
|
return this.attributeRequest
|
|
|
|
.createAttribute(name)
|
|
|
|
.then(
|
|
|
|
resp => (this.attribute = resp.body.data.attributeCreate.attribute)
|
|
|
|
);
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-16 20:48:37 +00:00
|
|
|
createTypeProduct(name, attributeId) {
|
|
|
|
return this.productRequest
|
|
|
|
.createTypeProduct(name, attributeId)
|
|
|
|
.then(
|
|
|
|
resp =>
|
|
|
|
(this.productType = resp.body.data.productTypeCreate.productType)
|
|
|
|
);
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-16 20:48:37 +00:00
|
|
|
createCategory(name) {
|
|
|
|
return this.categoryRequest
|
|
|
|
.createCategory(name)
|
|
|
|
.then(resp => (this.category = resp.body.data.categoryCreate.category));
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-16 20:48:37 +00:00
|
|
|
createProduct(attributeId, name, productTypeId, categoryId) {
|
|
|
|
return this.productRequest
|
|
|
|
.createProduct(attributeId, name, productTypeId, categoryId)
|
|
|
|
.then(resp => (this.product = resp.body.data.productCreate.product));
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-16 20:48:37 +00:00
|
|
|
createVariant(
|
2021-02-16 14:19:46 +00:00
|
|
|
productId,
|
|
|
|
name,
|
|
|
|
warehouseId,
|
|
|
|
quantityInWarehouse,
|
|
|
|
channelId,
|
|
|
|
price
|
|
|
|
) {
|
2021-02-16 20:48:37 +00:00
|
|
|
return this.productRequest
|
|
|
|
.createVariant(
|
2021-02-16 14:19:46 +00:00
|
|
|
productId,
|
|
|
|
name,
|
|
|
|
warehouseId,
|
|
|
|
quantityInWarehouse,
|
|
|
|
channelId,
|
|
|
|
price
|
|
|
|
)
|
2021-02-16 20:48:37 +00:00
|
|
|
.then(
|
|
|
|
resp =>
|
|
|
|
(this.variants =
|
|
|
|
resp.body.data.productVariantBulkCreate.productVariants)
|
|
|
|
);
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-18 18:28:01 +00:00
|
|
|
getCreatedProduct() {
|
|
|
|
return this.product;
|
|
|
|
}
|
2021-02-02 11:34:10 +00:00
|
|
|
getCreatedVariants() {
|
2021-02-16 14:19:46 +00:00
|
|
|
return this.variants;
|
2021-02-02 11:34:10 +00:00
|
|
|
}
|
2021-02-16 14:19:46 +00:00
|
|
|
getProductType() {
|
|
|
|
return this.productType;
|
2021-02-02 11:34:10 +00:00
|
|
|
}
|
2021-02-16 14:19:46 +00:00
|
|
|
getAttribute() {
|
|
|
|
return this.attribute;
|
2021-02-02 11:34:10 +00:00
|
|
|
}
|
2021-02-16 14:19:46 +00:00
|
|
|
getCategory() {
|
|
|
|
return this.category;
|
2021-02-02 11:34:10 +00:00
|
|
|
}
|
2021-02-16 14:19:46 +00:00
|
|
|
deleteProperProducts(startsWith) {
|
2021-02-04 11:15:27 +00:00
|
|
|
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-04 11:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default ProductsUtils;
|