fix tests for variants

This commit is contained in:
Karolina Rakoczy 2021-03-02 18:26:57 +01:00
parent fb36c6b633
commit a9999c43d8
3 changed files with 24 additions and 35 deletions

View file

@ -85,18 +85,15 @@ describe("creating variants", () => {
}); });
getProductVariants(createdProduct.id, defaultChannel.slug); getProductVariants(createdProduct.id, defaultChannel.slug);
}) })
.then(variants => { .then(([variant]) => {
expect(variants[0]).to.have.property("name", attributeValues[0]); expect(variant).to.have.property("name", attributeValues[0]);
expect(variants[0].pricing.price.gross).to.have.property( expect(variant).to.have.property("price", price);
"amount",
price
);
}); });
}); });
it("should create several variants", () => { it("should create several variants", () => {
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
const secondVariantSku = `${startsWith}${faker.random.number()}`; const secondVariantSku = `${startsWith}${faker.random.number()}`;
const variants = [{ amount: 7 }, { name: attributeValues[1], amount: 16 }]; const variants = [{ price: 7 }, { name: attributeValues[1], price: 16 }];
let createdProduct; let createdProduct;
productUtils productUtils
@ -107,7 +104,7 @@ describe("creating variants", () => {
warehouseId: warehouse.id, warehouseId: warehouse.id,
productTypeId: productType.id, productTypeId: productType.id,
categoryId: category.id, categoryId: category.id,
price: variants[0].amount price: variants[0].price
}) })
.then(() => { .then(() => {
createdProduct = productUtils.getCreatedProduct(); createdProduct = productUtils.getCreatedProduct();
@ -116,21 +113,14 @@ describe("creating variants", () => {
sku: secondVariantSku, sku: secondVariantSku,
warehouseName: warehouse.name, warehouseName: warehouse.name,
attributeName: variants[1].name, attributeName: variants[1].name,
price: variants[1].amount price: variants[1].price
}); });
}) })
.then(() => getProductVariants(createdProduct.id, defaultChannel.slug)) .then(() => getProductVariants(createdProduct.id, defaultChannel.slug))
.then(variantsResp => { .then(([firstVariant, secondVariant]) => {
expect(variantsResp).to.have.length(2); expect(firstVariant).to.have.property("price", variants[0].price);
expect(variantsResp[0].pricing.price.gross).to.have.property( expect(secondVariant).to.have.property("name", variants[1].name);
"amount", expect(secondVariant).to.have.property("price", variants[1].price);
variants[0].amount
);
expect(variantsResp[1]).to.have.property("name", variants[1].name);
expect(variantsResp[1].pricing.price.gross).to.have.property(
"amount",
variants[1].amount
);
}); });
}); });
it("should create variant for many channels", () => { it("should create variant for many channels", () => {
@ -172,20 +162,14 @@ describe("creating variants", () => {
}); });
getProductVariants(createdProduct.id, defaultChannel.slug); getProductVariants(createdProduct.id, defaultChannel.slug);
}) })
.then(variants => { .then(([variant]) => {
expect(variants[0]).to.have.property("name", attributeValues[0]); expect(variant).to.have.property("name", attributeValues[0]);
expect(variants[0].pricing.price.gross).to.have.property( expect(variant).to.have.property("price", variantsPrice);
"amount",
variantsPrice
);
getProductVariants(createdProduct.id, newChannel.slug); getProductVariants(createdProduct.id, newChannel.slug);
}) })
.then(variants => { .then(([variant]) => {
expect(variants[0]).to.have.property("name", attributeValues[0]); expect(variant).to.have.property("name", attributeValues[0]);
expect(variants[0].pricing.price.gross).to.have.property( expect(variant).to.have.property("price", variantsPrice);
"amount",
variantsPrice
);
}); });
}); });
}); });

View file

@ -1,5 +1,6 @@
import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors"; import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors";
import { VARIANTS_SELECTORS } from "../../elements/catalog/variants-selectors"; import { VARIANTS_SELECTORS } from "../../elements/catalog/variants-selectors";
class VariantsSteps { class VariantsSteps {
createFirstVariant({ sku, warehouseId, price, attribute }) { createFirstVariant({ sku, warehouseId, price, attribute }) {
cy.get(PRODUCTS_SELECTORS.addVariantsButton).click(); cy.get(PRODUCTS_SELECTORS.addVariantsButton).click();

View file

@ -34,7 +34,11 @@ export const isProductVisibleInSearchResult = (productName, channelSlug) => {
export const getProductVariants = (productId, channelSlug) => { export const getProductVariants = (productId, channelSlug) => {
const productDetails = new ProductDetails(); const productDetails = new ProductDetails();
return productDetails return productDetails.getProductDetails(productId, channelSlug).then(resp => {
.getProductDetails(productId, channelSlug) const variantsList = resp.body.data.product.variants;
.then(resp => resp.body.data.product.variants); return variantsList.map(element => ({
name: element.name,
price: element.pricing.price.gross.amount
}));
});
}; };