all tests for products

This commit is contained in:
Karolina Rakoczy 2021-02-08 10:23:12 +01:00
parent 584e66b9f9
commit 2a9e420420
8 changed files with 224 additions and 26 deletions

View file

@ -27,7 +27,8 @@ class Product {
productId, productId,
channelId, channelId,
isPublished, isPublished,
isAvailableForPurchase isAvailableForPurchase,
visibleInListings
) { ) {
const mutation = `mutation{ const mutation = `mutation{
productChannelListingUpdate(id:"${productId}", productChannelListingUpdate(id:"${productId}",
@ -36,7 +37,7 @@ class Product {
channelId:"${channelId}" channelId:"${channelId}"
isPublished:${isPublished} isPublished:${isPublished}
isAvailableForPurchase:${isAvailableForPurchase} isAvailableForPurchase:${isAvailableForPurchase}
visibleInListings:true visibleInListings:${visibleInListings}
} }
}){ }){
product{ product{

View file

@ -23,5 +23,6 @@ export const PRODUCTS_SELECTORS = {
channelAvailabilityList: "ul[role='menu']", channelAvailabilityList: "ul[role='menu']",
goBackButton: "[data-test-id='app-header-back-button']", goBackButton: "[data-test-id='app-header-back-button']",
assignedChannels: "[data-test='channel-availability-item']", assignedChannels: "[data-test='channel-availability-item']",
publishedRadioButton: "[role=radiogroup]" publishedRadioButton: "[role=radiogroup]",
visibleInListingsButton: "[class*='MuiFormControlLabel']"
}; };

View file

@ -1,5 +1,13 @@
{ {
"plAddress":{ "plAddress": {
"companyName": "Test3",
"streetAddress1": "Smolna",
"streetAddress2": "13/1",
"city": "Wrocław",
"postalCode": "53-346",
"country": "PL",
"countryArea": "Dolny Śląsk",
"phone": "123456787",
"currency": "PLN" "currency": "PLN"
} }
} }

View file

@ -33,8 +33,8 @@ describe("Products", () => {
shippingUtils.deleteShipping(startsWith); shippingUtils.deleteShipping(startsWith);
productsUtils.deleteProducts(startsWith); productsUtils.deleteProducts(startsWith);
channelsUtils.findDefaultChannel().then(() => { channelsUtils.getDefaultChannel().then(channel => {
defaultChannel = channelsUtils.getDefaultChannel(); defaultChannel = channel;
cy.fixture("addresses").then(json => { cy.fixture("addresses").then(json => {
shippingUtils shippingUtils
.createShipping(defaultChannel, name, json.plAddress, 10) .createShipping(defaultChannel, name, json.plAddress, 10)
@ -66,15 +66,18 @@ describe("Products", () => {
productTypeId, productTypeId,
attributeId, attributeId,
categoryId, categoryId,
defaultChannel, defaultChannel.id,
true, true,
false, false,
true,
warehouseId, warehouseId,
10, 10,
10 10
) )
.then(() => { .then(() => {
const productUrl = `${URL_LIST.products}${productsUtils.getCreatedProductId}`; const productUrl = `${
URL_LIST.products
}${productsUtils.getCreatedProductId()}`;
cy.visit(productUrl) cy.visit(productUrl)
.get(PRODUCTS_SELECTORS.assignedChannels) .get(PRODUCTS_SELECTORS.assignedChannels)
.click() .click()
@ -87,7 +90,7 @@ describe("Products", () => {
.get("@shopUrl") .get("@shopUrl")
.then(shopUrl => { .then(shopUrl => {
cy.visit(shopUrl); cy.visit(shopUrl);
searchSteps.searchFor(name); searchSteps.searchFor(productName);
cy.get(SEARCH_SELECTORS.productItem) cy.get(SEARCH_SELECTORS.productItem)
.contains(productName) .contains(productName)
.click() .click()
@ -98,4 +101,45 @@ describe("Products", () => {
}); });
}); });
}); });
it("shouldn't be possible to add to cart not available for purchase product", () => {
const productName = `${startsWith}${faker.random.number()}`;
productsUtils
.createProductInChannel(
productName,
productTypeId,
attributeId,
categoryId,
defaultChannel.id,
true,
true,
true,
warehouseId,
10,
10
)
.then(() => {
const productUrl = `${
URL_LIST.products
}${productsUtils.getCreatedProductId()}`;
cy.visit(productUrl)
.get(PRODUCTS_SELECTORS.assignedChannels)
.click()
.get(PRODUCTS_SELECTORS.publishedRadioButton)
.contains("Niedostępne do zakupu")
.click()
.get(PRODUCTS_SELECTORS.saveBtn)
.click()
.waitForGraph("ProductChannelListingUpdate")
.get("@shopUrl")
.then(shopUrl => {
cy.visit(shopUrl);
searchSteps.searchFor(productName);
cy.get(SEARCH_SELECTORS.productItem)
.contains(productName)
.click()
.get(PRODUCTS_DETAILS_SELECTORS.addToCartButton)
.should("be.disabled");
});
});
});
}); });

View file

@ -39,7 +39,7 @@ describe("Products", () => {
.its("body.data.shop.domain.url") .its("body.data.shop.domain.url")
.as("shopUrl"); .as("shopUrl");
}); });
xit("should display on frontend only published products", () => { it("should display on frontend only published products", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => { channelsUtils.getDefaultChannel().then(defaultChannel => {
productsUtils productsUtils
@ -50,7 +50,8 @@ describe("Products", () => {
categoryId, categoryId,
defaultChannel.id, defaultChannel.id,
false, false,
false false,
true
) )
.then(() => { .then(() => {
cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`) cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`)
@ -65,8 +66,8 @@ describe("Products", () => {
.get("@shopUrl") .get("@shopUrl")
.then(shopUrl => { .then(shopUrl => {
cy.visit(shopUrl); cy.visit(shopUrl);
searchSteps.searchFor(name); searchSteps.searchFor(productName);
cy.get(SEARCH_SELECTORS.productItem).contains(name); cy.get(SEARCH_SELECTORS.productItem).contains(productName);
}); });
}); });
}); });
@ -82,7 +83,8 @@ describe("Products", () => {
categoryId, categoryId,
defaultChannel.id, defaultChannel.id,
true, true,
false false,
true
) )
.then(() => { .then(() => {
cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`) cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`)
@ -97,13 +99,13 @@ describe("Products", () => {
.get("@shopUrl") .get("@shopUrl")
.then(shopUrl => { .then(shopUrl => {
cy.visit(shopUrl); cy.visit(shopUrl);
searchSteps.searchFor(name); searchSteps.searchFor(productName);
cy.get(SEARCH_SELECTORS.productItem).should("not.exist"); cy.get(SEARCH_SELECTORS.productItem).should("not.exist");
}); });
}); });
}); });
}); });
xit("should display not published product for staff member", () => { it("should display not published product for staff member", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => { channelsUtils.getDefaultChannel().then(defaultChannel => {
productsUtils productsUtils
@ -114,7 +116,8 @@ describe("Products", () => {
categoryId, categoryId,
defaultChannel.id, defaultChannel.id,
true, true,
false false,
true
) )
.then(() => { .then(() => {
cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`) cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`)
@ -131,8 +134,8 @@ describe("Products", () => {
cy.visit(shopUrl) cy.visit(shopUrl)
.loginInShop() .loginInShop()
.then(() => { .then(() => {
searchSteps.searchFor(name); searchSteps.searchFor(productName);
cy.get(SEARCH_SELECTORS.productItem).contains(name); cy.get(SEARCH_SELECTORS.productItem).contains(productName);
}); });
}); });
}); });

View file

@ -0,0 +1,144 @@
import faker from "faker";
import ShopInfo from "../../apiRequests/ShopInfo";
import { PRODUCTS_SELECTORS } from "../../elements/catalog/product-selectors";
import { SEARCH_SELECTORS } from "../../elements/frontend-elements/search-selectors";
import SearchSteps from "../../steps/frontendSteps/searchSteps";
import { URL_LIST } from "../../url/url-list";
import ChannelsUtils from "../../utils/channelsUtils";
import ProductsUtils from "../../utils/productsUtils";
// <reference types="cypress" />
describe("Products", () => {
const channelsUtils = new ChannelsUtils();
const productsUtils = new ProductsUtils();
const searchSteps = new SearchSteps();
const shopInfo = new ShopInfo();
const startsWith = "Cy-";
const name = `${startsWith}${faker.random.number()}`;
let productTypeId;
let attributeId;
let categoryId;
before(() => {
cy.clearSessionData().loginUserViaRequest();
productsUtils.deleteProducts(startsWith);
productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => {
productTypeId = productsUtils.getProductTypeId();
attributeId = productsUtils.getAttributeId();
categoryId = productsUtils.getCategoryId();
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
shopInfo
.getShopInfo()
.its("body.data.shop.domain.url")
.as("shopUrl");
});
it("should display on frontend only visible in listings products", () => {
const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => {
productsUtils
.createProductInChannel(
productName,
productTypeId,
attributeId,
categoryId,
defaultChannel.id,
true,
false,
false
)
.then(() => {
cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`)
.get(PRODUCTS_SELECTORS.assignedChannels)
.click()
.get(PRODUCTS_SELECTORS.visibleInListingsButton)
.contains("Wyświetlaj na liście produktów")
.click()
.get(PRODUCTS_SELECTORS.saveBtn)
.click()
.waitForGraph("ProductChannelListingUpdate")
.get("@shopUrl")
.then(shopUrl => {
cy.visit(shopUrl);
searchSteps.searchFor(productName);
cy.get(SEARCH_SELECTORS.productItem).contains(productName);
});
});
});
});
it("shouldn't display not visible in listing product for unlogged user", () => {
const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => {
productsUtils
.createProductInChannel(
productName,
productTypeId,
attributeId,
categoryId,
defaultChannel.id,
true,
false,
true
)
.then(() => {
cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`)
.get(PRODUCTS_SELECTORS.assignedChannels)
.click()
.get(PRODUCTS_SELECTORS.visibleInListingsButton)
.contains("Wyświetlaj na liście produktów")
.click()
.get(PRODUCTS_SELECTORS.saveBtn)
.click()
.waitForGraph("ProductChannelListingUpdate")
.get("@shopUrl")
.then(shopUrl => {
cy.visit(shopUrl);
searchSteps.searchFor(productName);
cy.get(SEARCH_SELECTORS.productItem).should("not.exist");
});
});
});
});
it("should display not visible in listing product for staff member", () => {
const productName = `${startsWith}${faker.random.number()}`;
channelsUtils.getDefaultChannel().then(defaultChannel => {
productsUtils
.createProductInChannel(
productName,
productTypeId,
attributeId,
categoryId,
defaultChannel.id,
true,
false,
true
)
.then(() => {
cy.visit(`${URL_LIST.products}${productsUtils.getCreatedProductId()}`)
.get(PRODUCTS_SELECTORS.assignedChannels)
.click()
.get(PRODUCTS_SELECTORS.visibleInListingsButton)
.contains("Wyświetlaj na liście produktów")
.click()
.get(PRODUCTS_SELECTORS.saveBtn)
.click()
.waitForGraph("ProductChannelListingUpdate")
.get("@shopUrl")
.then(shopUrl => {
cy.visit(shopUrl)
.loginInShop()
.then(() => {
searchSteps.searchFor(productName);
cy.get(SEARCH_SELECTORS.productItem).contains(productName);
});
});
});
});
});
});

View file

@ -3,8 +3,6 @@ import Channels from "../apiRequests/Channels";
class ChannelsUtils { class ChannelsUtils {
channels = new Channels(); channels = new Channels();
defaultChannel;
deleteChannels(nameStartsWith) { deleteChannels(nameStartsWith) {
this.channels.getChannels().then(resp => { this.channels.getChannels().then(resp => {
const channelsArray = new Set(resp.body.data.channels); const channelsArray = new Set(resp.body.data.channels);
@ -28,7 +26,7 @@ class ChannelsUtils {
} }
}); });
} }
findDefaultChannel() { getDefaultChannel() {
return this.channels.getChannels().then(resp => { return this.channels.getChannels().then(resp => {
const channelsArray = resp.body.data.channels; const channelsArray = resp.body.data.channels;
return (this.defaultChannel = channelsArray.find(function( return (this.defaultChannel = channelsArray.find(function(
@ -38,8 +36,5 @@ class ChannelsUtils {
})); }));
}); });
} }
getDefaultChannel() {
return this.defaultChannel;
}
} }
export default ChannelsUtils; export default ChannelsUtils;

View file

@ -42,6 +42,7 @@ class ProductsUtils {
channelId, channelId,
isPublished, isPublished,
isAvailableForPurchase, isAvailableForPurchase,
visibleInListings,
warehouseId, warehouseId,
quantityInWarehouse, quantityInWarehouse,
price price
@ -57,7 +58,8 @@ class ProductsUtils {
this.createdProductId, this.createdProductId,
channelId, channelId,
isPublished, isPublished,
isAvailableForPurchase isAvailableForPurchase,
visibleInListings
) )
.then(() => .then(() =>
product product