Skip to content

Commit

Permalink
[QA] Fix tests for SALEOR_1801, SALEOR_1802 & SALEOR_3002 (#4852)
Browse files Browse the repository at this point in the history
* Add fixes

* WIP

* wip

* Added waiting for:
- product being available in search
- product variant being set to onSale

Resolves issues with
- Unable to find product while assigning from discounts
- Checking discounted value too quickly before the sale got processed.

* Revert package-lock.json

* Add missing LB

* Add changeset

* Add quick fix for SALEOR_3002

---------

Co-authored-by: wojteknowacki <wojciech.nowacki@saleor.io>
  • Loading branch information
michalina-graczyk and wojteknowacki committed May 14, 2024
1 parent deb6c1e commit ad6c8b7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-donuts-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fixed flaky Cypress tests related to Discounts
1 change: 1 addition & 0 deletions cypress/e2e/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe("As a staff user I want to manage apps", () => {
.click()
.get(BUTTON_SELECTORS.confirm)
.click()
.wait(3000)
.confirmationMessageShouldDisappear();
getApp(createdApp.app.id).then(({ webhooks }) => {
expect(webhooks[0].name).to.eq(randomWebhookName);
Expand Down
36 changes: 18 additions & 18 deletions cypress/e2e/discounts/sales/createSalesForProducts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import faker from "faker";
import { urlList } from "../../../fixtures/urlList";
import { createChannel } from "../../../support/api/requests/Channels";
import { updateChannelInProduct } from "../../../support/api/requests/Product";
import { expectProductVisibleInShop } from "../../../support/api/requests/storeFront/Search";
import * as channelsUtils from "../../../support/api/utils/channelsUtils";
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 {
getProductPrice,
} from "../../../support/api/utils/storeFront/storeFrontProductUtils";

import { getProductPrice } from "../../../support/api/utils/storeFront/storeFrontProductUtils";
import {
getDefaultTaxClass,
updateTaxConfigurationForChannel,
Expand All @@ -26,8 +25,8 @@ import {

describe("As an admin I want to create sale for products", () => {
const startsWith = "SalesProd-";
const discountValue = 50;
const productPrice = 100;
const discountValue = 10;
const productPrice = 50;

let productType;
let attribute;
Expand Down Expand Up @@ -97,7 +96,7 @@ describe("As an admin I want to create sale for products", () => {
{ tags: ["@sales", "@allEnv", "@stable"] },
() => {
const saleName = `${startsWith}${faker.datatype.number()}`;
const expectedPrice = (productPrice * discountValue) / 100;
const discountOption = discountOptions.PERCENTAGE;

createSaleWithNewProduct({
name: saleName,
Expand All @@ -107,10 +106,10 @@ describe("As an admin I want to create sale for products", () => {
attributeId: attribute.id,
categoryId: category.id,
price: productPrice,
discountOption: discountOptions.PERCENTAGE,
discountOption,
discountValue,
taxClassId: taxClass.id,
}).should("eq", expectedPrice);
}).should("eq", 45);
},
);

Expand All @@ -119,7 +118,7 @@ describe("As an admin I want to create sale for products", () => {
{ tags: ["@sales", "@allEnv", "@stable"] },
() => {
const saleName = `${startsWith}${faker.datatype.number()}`;
const expectedPrice = productPrice - discountValue;
const discountOption = discountOptions.FIXED;

createSaleWithNewProduct({
name: saleName,
Expand All @@ -129,14 +128,14 @@ describe("As an admin I want to create sale for products", () => {
attributeId: attribute.id,
categoryId: category.id,
price: productPrice,
discountOption: discountOptions.FIXED,
discountOption,
discountValue,
}).should("eq", expectedPrice);
}).should("eq", 40);
},
);

it(
"should not be able to see product discount not assign to channel. TC: SALEOR_1803",
"should not be able to see product discount not assigned to channel. TC: SALEOR_1803",
{ tags: ["@sales", "@allEnv", "@stable"] },
() => {
const saleName = `${startsWith}${faker.datatype.number()}`;
Expand Down Expand Up @@ -165,20 +164,21 @@ describe("As an admin I want to create sale for products", () => {
productId: product.id,
channelId: channel.id,
});
/* Uncomment after fixing SALEOR-3367 bug
cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
/*Uncomment after fixing SALEOR-3367 bug
cy.clearSessionData().loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount);
*/
cy.visit(urlList.sales);
createSale({
saleName,
channelName: channel.name,
discountValue,
});
// Make sure the product is searchable before assigning
expectProductVisibleInShop(product.name);
assignProducts(product.name);
getProductPrice(product.id, defaultChannel.slug);
})
.should("eq", productPrice);
.should("eq", 50);
},
);
});
12 changes: 8 additions & 4 deletions cypress/support/api/requests/storeFront/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export function searchInShop(searchQuery) {
}`;
return cy.sendRequestWithQuery(query, "token");
}
export function expectProductVisibleInShop(productName, retries = 0) {

export function expectProductVisibleInShop(productName, maxRetries = 5) {
let retries = 0;

return searchInShop(productName).then(searchInShopResponse => {
const productsList = searchInShopResponse.body.data.products;
if (
Expand All @@ -24,13 +27,14 @@ export function expectProductVisibleInShop(productName, retries = 0) {
) {
cy.log(`Found product name: ${productName}`);
return;
} else if (retries > 4) {
} else if (retries >= maxRetries) {
throw new Error(
`Product with name ${productName} is not visible in search results. Retried for ${retries} times`,
`Product with name ${productName} is not visible in search results. Retried for ${maxRetries} times`,
);
} else {
cy.wait(5000);
expectProductVisibleInShop(productName, retries + 1);
retries++;
expectProductVisibleInShop(productName);
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const getProductVariants = (productId, channelSlug) => {
};

export const getProductPrice = (productId, channelSlug) => {
getProductDetails(productId, channelSlug).then(
return getProductDetails(productId, channelSlug).then(
resp => resp.body.data.product.variants[0].pricing.price.gross.amount,
);
};
27 changes: 24 additions & 3 deletions cypress/support/pages/discounts/salesPage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { SHARED_ELEMENTS } from "../../../elements";
import { SALES_SELECTORS } from "../../../elements/discounts/sales";
import { ASSIGN_ELEMENTS_SELECTORS } from "../../../elements/shared/assign-elements-selectors";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { urlList } from "../../../fixtures/urlList";
import { getVariantWithSaleStatus } from "../../../support/api/utils/discounts/salesUtils";
import { formatDate } from "../../../support/formatData/formatDate";
import { getVariant } from "../../api/requests/Product";
import { expectProductVisibleInShop } from "../../api/requests/storeFront/Search";
import { createProductInChannel } from "../../api/utils/products/productsUtils";
import { getProductPrice } from "../../api/utils/storeFront/storeFrontProductUtils";
import { selectChannelInDetailsPages } from "../channelsPage";
Expand All @@ -29,14 +31,18 @@ export function createSale({
.get(discountOption)
.click();
selectChannelInDetailsPages(channelName);
cy.get(SALES_SELECTORS.discountValue)

return cy
.get(SALES_SELECTORS.discountValue)
.type(discountValue)
.get(SALES_SELECTORS.startDateInput)
.type(todaysDate)
.addAliasToGraphRequest("SaleCreate")
.get(SALES_SELECTORS.saveButton)
.click()
.waitForRequestAndCheckIfNoErrors("@SaleCreate");
.waitForRequestAndCheckIfNoErrors("@SaleCreate")
.get(SHARED_ELEMENTS.notificationMessage)
.should("contain", "Successfully created sale");
}

export function assignProducts(productName) {
Expand All @@ -53,6 +59,10 @@ export function assignProducts(productName) {
cy.addAliasToGraphRequest("SaleCataloguesAdd");
cy.get(BUTTON_SELECTORS.submit).click();
cy.waitForRequestAndCheckIfNoErrors("@SaleCataloguesAdd");
cy.get(SHARED_ELEMENTS.notificationMessage).should(
"contain",
"Saved changes",
);
}

export function assignVariants(productName, variantName) {
Expand Down Expand Up @@ -94,8 +104,9 @@ export function createSaleWithNewProduct({
categoryId,
price,
taxClassId,
}).then(({ product: productResp }) => {
}).then(({ product: productResp, variantsList }) => {
const product = productResp;

/* Uncomment after fixing SALEOR-3367 bug
cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
Expand All @@ -107,7 +118,17 @@ export function createSaleWithNewProduct({
discountValue,
discountOption,
});

// Make sure the product is searchable before assigning
expectProductVisibleInShop(product.name);
assignProducts(product.name);
// Wait until product variant receives onSale status
getVariantWithSaleStatus({
variantId: variantsList[0].id,
channelSlug: channel.slug,
onSaleStatus: true,
});

return getProductPrice(product.id, channel.slug);
});
}
Expand Down

0 comments on commit ad6c8b7

Please sign in to comment.