saleor-dashboard/cypress/utils/products/productsUtils.js

104 lines
2.5 KiB
JavaScript
Raw Normal View History

import * as attributeRequest from "../../apiRequests/Attribute";
import * as categoryRequest from "../../apiRequests/Category";
import * as productRequest from "../../apiRequests/Product";
2021-07-05 10:21:35 +00:00
import {
createTypeProduct,
deleteProductType,
getProductTypes
} from "../../apiRequests/productType";
import { deleteAttributesStartsWith } from "../attributes/attributeUtils";
2021-02-04 11:15:27 +00:00
export function createProductInChannel({
name,
channelId,
warehouseId = null,
quantityInWarehouse = 10,
productTypeId,
attributeId,
categoryId,
price = 1,
isPublished = true,
isAvailableForPurchase = true,
visibleInListings = true,
collectionId = null,
description = null,
trackInventory = true,
weight = 1
}) {
let product;
let variantsList;
return productRequest
.createProduct({
attributeId,
name,
productTypeId,
categoryId,
collectionId,
description
})
.then(productResp => {
product = productResp;
productRequest.updateChannelInProduct({
productId: product.id,
channelId,
isPublished,
isAvailableForPurchase,
visibleInListings
2021-02-04 11:15:27 +00:00
});
})
.then(() => {
productRequest.createVariant({
productId: product.id,
sku: name,
attributeId,
2021-02-16 14:19:46 +00:00
warehouseId,
quantityInWarehouse,
2021-02-16 14:19:46 +00:00
channelId,
price,
trackInventory,
weight
});
})
.then(variantsResp => {
variantsList = variantsResp;
return { product, variantsList };
});
}
export function createTypeAttributeAndCategoryForProduct(
name,
attributeValues
) {
let attribute;
let productType;
let category;
return attributeRequest
2021-07-15 11:22:04 +00:00
.createAttribute({ name, attributeValues })
.then(attributeResp => {
attribute = attributeResp;
2021-07-05 10:21:35 +00:00
createTypeProduct({ name, attributeId: attributeResp.id });
})
.then(productTypeResp => {
productType = productTypeResp;
categoryRequest.createCategory(name);
})
.then(categoryResp => {
category = categoryResp;
return { attribute, category, productType };
});
}
export function deleteProductsStartsWith(startsWith) {
deleteAttributesStartsWith(startsWith);
2021-07-05 10:21:35 +00:00
cy.deleteElementsStartsWith(deleteProductType, getProductTypes, startsWith);
cy.deleteElementsStartsWith(
attributeRequest.deleteAttribute,
attributeRequest.getAttributes,
startsWith
);
cy.deleteElementsStartsWith(
categoryRequest.deleteCategory,
categoryRequest.getCategories,
startsWith
);
2021-02-04 11:15:27 +00:00
}