diff --git a/cypress/integration/products/productsVariants.js b/cypress/integration/products/productsVariants.js index 04e8a71a0..7c28eb999 100644 --- a/cypress/integration/products/productsVariants.js +++ b/cypress/integration/products/productsVariants.js @@ -85,18 +85,15 @@ describe("creating variants", () => { }); getProductVariants(createdProduct.id, defaultChannel.slug); }) - .then(variants => { - expect(variants[0]).to.have.property("name", attributeValues[0]); - expect(variants[0].pricing.price.gross).to.have.property( - "amount", - price - ); + .then(([variant]) => { + expect(variant).to.have.property("name", attributeValues[0]); + expect(variant).to.have.property("price", price); }); }); it("should create several variants", () => { const name = `${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; productUtils @@ -107,7 +104,7 @@ describe("creating variants", () => { warehouseId: warehouse.id, productTypeId: productType.id, categoryId: category.id, - price: variants[0].amount + price: variants[0].price }) .then(() => { createdProduct = productUtils.getCreatedProduct(); @@ -116,21 +113,14 @@ describe("creating variants", () => { sku: secondVariantSku, warehouseName: warehouse.name, attributeName: variants[1].name, - price: variants[1].amount + price: variants[1].price }); }) .then(() => getProductVariants(createdProduct.id, defaultChannel.slug)) - .then(variantsResp => { - expect(variantsResp).to.have.length(2); - expect(variantsResp[0].pricing.price.gross).to.have.property( - "amount", - 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 - ); + .then(([firstVariant, secondVariant]) => { + expect(firstVariant).to.have.property("price", variants[0].price); + expect(secondVariant).to.have.property("name", variants[1].name); + expect(secondVariant).to.have.property("price", variants[1].price); }); }); it("should create variant for many channels", () => { @@ -172,20 +162,14 @@ describe("creating variants", () => { }); getProductVariants(createdProduct.id, defaultChannel.slug); }) - .then(variants => { - expect(variants[0]).to.have.property("name", attributeValues[0]); - expect(variants[0].pricing.price.gross).to.have.property( - "amount", - variantsPrice - ); + .then(([variant]) => { + expect(variant).to.have.property("name", attributeValues[0]); + expect(variant).to.have.property("price", variantsPrice); getProductVariants(createdProduct.id, newChannel.slug); }) - .then(variants => { - expect(variants[0]).to.have.property("name", attributeValues[0]); - expect(variants[0].pricing.price.gross).to.have.property( - "amount", - variantsPrice - ); + .then(([variant]) => { + expect(variant).to.have.property("name", attributeValues[0]); + expect(variant).to.have.property("price", variantsPrice); }); }); }); diff --git a/cypress/steps/products/VariantsSteps.js b/cypress/steps/products/VariantsSteps.js index 72036c7e8..d1baba221 100644 --- a/cypress/steps/products/VariantsSteps.js +++ b/cypress/steps/products/VariantsSteps.js @@ -1,5 +1,6 @@ import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors"; import { VARIANTS_SELECTORS } from "../../elements/catalog/variants-selectors"; + class VariantsSteps { createFirstVariant({ sku, warehouseId, price, attribute }) { cy.get(PRODUCTS_SELECTORS.addVariantsButton).click(); diff --git a/cypress/utils/storeFront/storeFrontProductUtils.js b/cypress/utils/storeFront/storeFrontProductUtils.js index dbaa2cb2c..a02981716 100644 --- a/cypress/utils/storeFront/storeFrontProductUtils.js +++ b/cypress/utils/storeFront/storeFrontProductUtils.js @@ -34,7 +34,11 @@ export const isProductVisibleInSearchResult = (productName, channelSlug) => { export const getProductVariants = (productId, channelSlug) => { const productDetails = new ProductDetails(); - return productDetails - .getProductDetails(productId, channelSlug) - .then(resp => resp.body.data.product.variants); + return productDetails.getProductDetails(productId, channelSlug).then(resp => { + const variantsList = resp.body.data.product.variants; + return variantsList.map(element => ({ + name: element.name, + price: element.pricing.price.gross.amount + })); + }); };