test - fixes createSales ans updateSales (#3816)

* test - fixes createSales ans updateSales

* changed name shouldVariantBeOnSale into getVariantWithSaleStatus

* cr fixes
This commit is contained in:
wojteknowacki 2023-06-29 15:40:51 +02:00 committed by GitHub
parent df76e07f8e
commit c12a42932d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 18 deletions

View file

@ -7,7 +7,10 @@ import { createCheckout } from "../../../support/api/requests/Checkout";
import { updateSale } from "../../../support/api/requests/Discounts/Sales"; import { updateSale } from "../../../support/api/requests/Discounts/Sales";
import { createVariant } from "../../../support/api/requests/Product"; import { createVariant } from "../../../support/api/requests/Product";
import * as channelsUtils from "../../../support/api/utils/channelsUtils"; import * as channelsUtils from "../../../support/api/utils/channelsUtils";
import { createSaleInChannel } from "../../../support/api/utils/discounts/salesUtils"; import {
createSaleInChannel,
getVariantWithSaleStatus,
} from "../../../support/api/utils/discounts/salesUtils";
import * as productsUtils from "../../../support/api/utils/products/productsUtils"; import * as productsUtils from "../../../support/api/utils/products/productsUtils";
import { createShipping } from "../../../support/api/utils/shippingUtils"; import { createShipping } from "../../../support/api/utils/shippingUtils";
import { import {
@ -95,6 +98,8 @@ describe("Sales discounts for variant", () => {
{ tags: ["@sales", "@allEnv", "@stable"] }, { tags: ["@sales", "@allEnv", "@stable"] },
() => { () => {
const saleName = `${startsWith}${faker.datatype.number()}`; const saleName = `${startsWith}${faker.datatype.number()}`;
const variantSku = `${startsWith}${faker.datatype.number()}`;
const productSku = `${startsWith}${faker.datatype.number()}`;
const productName = faker.commerce.product(); const productName = faker.commerce.product();
const productSlug = productName + faker.datatype.number(); const productSlug = productName + faker.datatype.number();
const productPriceOnSale = productPrice - discountValue; const productPriceOnSale = productPrice - discountValue;
@ -113,13 +118,14 @@ describe("Sales discounts for variant", () => {
...productData, ...productData,
name: productName, name: productName,
slug: productSlug, slug: productSlug,
sku: productSku,
}) })
.then(({ product, variantsList }) => { .then(({ product, variantsList }) => {
variantNotOnSale = variantsList; variantNotOnSale = variantsList;
createVariant({ createVariant({
productId: product.id, productId: product.id,
sku: saleName, sku: variantSku,
attributeId: productData.attributeId, attributeId: productData.attributeId,
attributeName: "value2", attributeName: "value2",
warehouseId: warehouse.id, warehouseId: warehouse.id,
@ -131,6 +137,11 @@ describe("Sales discounts for variant", () => {
}) })
.then(variantsList => { .then(variantsList => {
updateSale({ saleId: sale.id, variants: variantsList }); updateSale({ saleId: sale.id, variants: variantsList });
getVariantWithSaleStatus({
channelSlug: defaultChannel.slug,
variantId: variantsList[0].id,
onSaleStatus: true,
});
createCheckout({ createCheckout({
channelSlug: defaultChannel.slug, channelSlug: defaultChannel.slug,
email: "example@example.com", email: "example@example.com",

View file

@ -8,12 +8,12 @@ import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements"; import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
import { saleDetailsUrl } from "../../../fixtures/urlList"; import { saleDetailsUrl } from "../../../fixtures/urlList";
import { updateSale } from "../../../support/api/requests/Discounts/Sales"; import { updateSale } from "../../../support/api/requests/Discounts/Sales";
import { getVariant } from "../../../support/api/requests/Product";
import { getDefaultChannel } from "../../../support/api/utils/channelsUtils"; import { getDefaultChannel } from "../../../support/api/utils/channelsUtils";
import { import {
createSaleInChannel, createSaleInChannel,
createSaleInChannelWithProduct, createSaleInChannelWithProduct,
deleteSalesStartsWith, deleteSalesStartsWith,
getVariantWithSaleStatus,
} from "../../../support/api/utils/discounts/salesUtils"; } from "../../../support/api/utils/discounts/salesUtils";
import { import {
createProductInChannel, createProductInChannel,
@ -116,9 +116,10 @@ describe("As an admin I want to update sales", () => {
{ tags: ["@sales", "@allEnv", "@stable"] }, { tags: ["@sales", "@allEnv", "@stable"] },
() => { () => {
const productName = `${startsWith}${faker.datatype.number()}`; const productName = `${startsWith}${faker.datatype.number()}`;
const productSku = `${startsWith}${faker.datatype.number()}`;
productData.name = productName; productData.name = productName;
productData.sku = productName; productData.sku = productSku;
createProductInChannel(productData) createProductInChannel(productData)
.then(({ variantsList }) => { .then(({ variantsList }) => {
@ -133,9 +134,12 @@ describe("As an admin I want to update sales", () => {
}); });
}) })
.then(saleResp => { .then(saleResp => {
getVariant(variants[0].id, defaultChannel.slug) getVariantWithSaleStatus({
channelSlug: defaultChannel.slug,
variantId: variants[0].id,
onSaleStatus: true,
})
.its("pricing") .its("pricing")
.should("include", { onSale: true })
.its("price.gross.amount") .its("price.gross.amount")
.should("eq", productPriceOnSale); .should("eq", productPriceOnSale);
cy.visit(saleDetailsUrl(saleResp.id)) cy.visit(saleDetailsUrl(saleResp.id))
@ -145,9 +149,12 @@ describe("As an admin I want to update sales", () => {
.get(BUTTON_SELECTORS.submit) .get(BUTTON_SELECTORS.submit)
.click() .click()
.wait("@SaleDelete"); .wait("@SaleDelete");
getVariant(variants[0].id, defaultChannel.slug) getVariantWithSaleStatus({
channelSlug: defaultChannel.slug,
variantId: variants[0].id,
onSaleStatus: false,
})
.its("pricing") .its("pricing")
.should("include", { onSale: false })
.its("price.gross.amount") .its("price.gross.amount")
.should("eq", productPrice); .should("eq", productPrice);
}); });
@ -173,9 +180,12 @@ describe("As an admin I want to update sales", () => {
saleId: sale.id, saleId: sale.id,
variants, variants,
}); });
getVariant(variants[0].id, defaultChannel.slug) getVariantWithSaleStatus({
channelSlug: defaultChannel.slug,
variantId: variants[0].id,
onSaleStatus: true,
})
.its("pricing") .its("pricing")
.should("include", { onSale: true })
.its("price.gross.amount") .its("price.gross.amount")
.should("eq", productPriceOnSale); .should("eq", productPriceOnSale);
cy.visit(saleDetailsUrl(sale.id)) cy.visit(saleDetailsUrl(sale.id))
@ -188,9 +198,12 @@ describe("As an admin I want to update sales", () => {
.get(BUTTON_SELECTORS.submit) .get(BUTTON_SELECTORS.submit)
.click() .click()
.wait("@SaleCataloguesRemove"); .wait("@SaleCataloguesRemove");
getVariant(variants[0].id, defaultChannel.slug) getVariantWithSaleStatus({
channelSlug: defaultChannel.slug,
variantId: variants[0].id,
onSaleStatus: false,
})
.its("pricing") .its("pricing")
.should("include", { onSale: false })
.its("price.gross.amount") .its("price.gross.amount")
.should("eq", productPrice); .should("eq", productPrice);
}, },

View file

@ -1,9 +1,10 @@
import { getVariant } from "../../../../support/api/requests/Product";
import { import {
addChannelToSale, addChannelToSale,
createSale, createSale,
deleteSale, deleteSale,
getSales, getSales,
updateSale updateSale,
} from "../../requests/Discounts/Sales"; } from "../../requests/Discounts/Sales";
export function deleteSalesStartsWith(startsWith) { export function deleteSalesStartsWith(startsWith) {
@ -15,13 +16,13 @@ export function createSaleInChannel({
type, type,
value, value,
channelId, channelId,
discountValue = value discountValue = value,
}) { }) {
let sale; let sale;
return createSale({ return createSale({
name, name,
type, type,
value value,
}) })
.then(saleResp => { .then(saleResp => {
sale = saleResp; sale = saleResp;
@ -29,6 +30,26 @@ export function createSaleInChannel({
}) })
.then(() => sale); .then(() => sale);
} }
export function getVariantWithSaleStatus(
{ variantId, channelSlug, onSaleStatus },
retries = 0,
) {
return getVariant(variantId, channelSlug).then(salesResponse => {
if (salesResponse.pricing.onSale === onSaleStatus) {
return;
} else if (retries > 4) {
throw new Error(
`Variant field onSale should have value: ${onSaleStatus} but has opposite. Retried for ${retries} times`,
);
} else {
cy.wait(5000);
getVariantWithSaleStatus(
{ variantId, channelSlug, onSaleStatus },
retries + 1,
);
}
});
}
export function createSaleInChannelWithProduct({ export function createSaleInChannelWithProduct({
name, name,
@ -36,21 +57,21 @@ export function createSaleInChannelWithProduct({
value, value,
channelId, channelId,
variants, variants,
productId productId,
}) { }) {
let sale; let sale;
return createSaleInChannel({ return createSaleInChannel({
name, name,
type, type,
value, value,
channelId channelId,
}) })
.then(saleResp => { .then(saleResp => {
sale = saleResp; sale = saleResp;
updateSale({ updateSale({
saleId: sale.id, saleId: sale.id,
variants, variants,
productId productId,
}); });
}) })
.then(() => sale); .then(() => sale);

View file

@ -2,6 +2,7 @@ import { SALES_SELECTORS } from "../../../elements/discounts/sales";
import { ASSIGN_ELEMENTS_SELECTORS } from "../../../elements/shared/assign-elements-selectors"; import { ASSIGN_ELEMENTS_SELECTORS } from "../../../elements/shared/assign-elements-selectors";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { urlList } from "../../../fixtures/urlList"; import { urlList } from "../../../fixtures/urlList";
import { getVariantWithSaleStatus } from "../../../support/api/utils/discounts/salesUtils";
import { formatDate } from "../../../support/formatData/formatDate"; import { formatDate } from "../../../support/formatData/formatDate";
import { getVariant } from "../../api/requests/Product"; import { getVariant } from "../../api/requests/Product";
import { createProductInChannel } from "../../api/utils/products/productsUtils"; import { createProductInChannel } from "../../api/utils/products/productsUtils";
@ -150,6 +151,11 @@ export function createSaleWithNewVariant({
discountOption, discountOption,
}); });
assignVariants(product.name, variant.name); assignVariants(product.name, variant.name);
getVariantWithSaleStatus({
channelSlug: channel.slug,
variantId: variant.id,
onSaleStatus: true,
});
return getVariant(variant.id, channel.slug, "token"); return getVariant(variant.id, channel.slug, "token");
}); });
} }