tests for products

This commit is contained in:
Karolina Rakoczy 2021-02-23 13:09:58 +01:00
parent 4fc9fefa74
commit e8c20ae511
12 changed files with 170 additions and 170 deletions

View file

@ -1,4 +1,7 @@
import Utils from "./utils/Utils";
class Product {
utils = new Utils();
getFirstProducts(first, search) {
const filter = search
? `, filter:{
@ -23,13 +26,13 @@ class Product {
.then(resp => resp.body.data.products.edges);
}
updateChannelInProduct(
updateChannelInProduct({
productId,
channelId,
isPublished = true,
isAvailableForPurchase = true,
visibleInListings = true
) {
}) {
const mutation = `mutation{
productChannelListingUpdate(id:"${productId}",
input:{
@ -94,19 +97,36 @@ class Product {
price = 1,
costPrice = 1
) {
const channelListings = channelId
? `channelListings:{
// const channelListings = channelId
// ? `channelListings:{
// channelId:"${channelId}"
// price:"${price}"
// costPrice:"${costPrice}"
// }`
// : "";
const channelListings = this.utils.getValueWithDefault(
channelId,
`channelListings:{
channelId:"${channelId}"
price:"${price}"
costPrice:"${costPrice}"
}`
: "";
const stocks = warehouseId
? `stocks:{
);
const stocks = this.utils.getValueWithDefault(
warehouseId,
`stocks:{
warehouse:"${warehouseId}"
quantity:${quantity}
}`
: "";
);
// warehouseId
// ? `stocks:{
// warehouse:"${warehouseId}"
// quantity:${quantity}
// }`
// : "";
const mutation = `mutation{
productVariantBulkCreate(product: "${productId}", variants: {

View file

@ -0,0 +1,6 @@
class Utils {
getValueWithDefault(condition, value, defaultValue = "") {
return condition ? value : defaultValue;
}
}
export default Utils;

View file

@ -44,10 +44,13 @@ describe("Channels", () => {
it("should create new channel", () => {
const randomChannel = `${channelStartsWith} ${faker.random.number()}`;
cy.visit(urlList.channels).waitForGraph("Channels");
cy.addAliasToGraphRequest("Channels");
cy.visit(urlList.channels);
cy.wait("@Channels");
cy.addAliasToGraphRequest("Channel");
channelsSteps.createChannelByView(randomChannel, currency);
// New channel should be visible in channels list
cy.waitForGraph("Channel")
cy.wait("@Channel")
.get(ADD_CHANNEL_FORM_SELECTORS.backToChannelsList)
.click()
.get(CHANNELS_SELECTORS.channelsTable)
@ -62,7 +65,9 @@ describe("Channels", () => {
.click();
// new channel should be visible at product availability form
cy.visit(urlList.products).waitForGraph("InitialProductFilterData");
cy.addAliasToGraphRequest("InitialProductFilterData");
cy.visit(urlList.products);
cy.wait("@InitialProductFilterData");
cy.get(PRODUCTS_SELECTORS.productsList)
.first()
.click()
@ -103,15 +108,18 @@ describe("Channels", () => {
randomChannelToDelete,
currency
);
cy.visit(urlList.channels).waitForGraph("Channels");
cy.addAliasToGraphRequest("Channels");
cy.visit(urlList.channels);
cy.wait("@Channels");
cy.get(CHANNELS_SELECTORS.channelName)
.contains(randomChannelToDelete)
.parentsUntil(CHANNELS_SELECTORS.channelsTable)
.find("button")
.click()
.get(BUTTON_SELECTORS.submit)
.click()
.waitForGraph("Channels");
.click();
cy.addAliasToGraphRequest("Channels");
cy.get(BUTTON_SELECTORS.submit).click();
cy.wait("@Channels");
cy.get(CHANNELS_SELECTORS.channelName)
.contains(randomChannelToDelete)
.should("not.exist");

View file

@ -48,12 +48,12 @@ describe("Homepage analytics", () => {
)
.then(resp => {
customerId = resp.body.data.customerCreate.user.id;
shippingUtils.createShipping(
defaultChannel.id,
randomName,
addresses.plAddress,
shippingPrice
);
shippingUtils.createShipping({
channelId: defaultChannel.id,
name: randomName,
address: addresses.plAddress,
price: shippingPrice
});
})
.then(() => {
productsUtils.createTypeAttributeAndCategoryForProduct(randomName);
@ -63,16 +63,16 @@ describe("Homepage analytics", () => {
const productType = productsUtils.getProductType();
const attribute = productsUtils.getAttribute();
const category = productsUtils.getCategory();
productsUtils.createProductInChannel(
randomName,
defaultChannel.id,
warehouse.id,
20,
productType.id,
attribute.id,
category.id,
productPrice
);
productsUtils.createProductInChannel({
name: randomName,
channelId: defaultChannel.id,
warehouseId: warehouse.id,
quantityInWarehouse: 20,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
price: productPrice
});
});
});
@ -154,16 +154,16 @@ describe("Homepage analytics", () => {
const attribute = productsUtils.getAttribute();
const category = productsUtils.getCategory();
productsOutOfStockUtils.createProductInChannel(
productOutOfStockRandomName,
defaultChannel.id,
warehouse.id,
0,
productType.id,
attribute.id,
category.id,
productPrice
);
productsOutOfStockUtils.createProductInChannel({
name: productOutOfStockRandomName,
channelId: defaultChannel.id,
warehouseId: warehouse.id,
quantityInWarehouse: 0,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
price: productPrice
});
cy.get("@productsOutOfStock").then(productsOutOfStockBefore => {
const allProductsOutOfStock = productsOutOfStockBefore + 1;

View file

@ -34,12 +34,11 @@ describe("Products available in listings", () => {
cy.fixture("addresses");
})
.then(addressesFixture => {
shippingUtils.createShipping(
defaultChannel,
shippingUtils.createShipping({
channelId: defaultChannel.id,
name,
addressesFixture.plAddress,
10
);
address: addressesFixture.plAddress
});
})
.then(() => {
warehouse = shippingUtils.getWarehouse();
@ -59,19 +58,15 @@ describe("Products available in listings", () => {
it("should update product to available for purchase", () => {
const productName = `${startsWith}${faker.random.number()}`;
productsUtils
.createProductInChannel(
productName,
defaultChannel.id,
warehouse.id,
10,
productType.id,
attribute.id,
category.id,
1,
true,
false,
true
)
.createProductInChannel({
name: productName,
channelId: defaultChannel.id,
warehouseId: warehouse.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
isAvailableForPurchase: false
})
.then(() => {
const productUrl = `${urlList.products}${
productsUtils.getCreatedProduct().id
@ -92,33 +87,29 @@ describe("Products available in listings", () => {
it("should update product to not available for purchase", () => {
const productName = `${startsWith}${faker.random.number()}`;
productsUtils
.createProductInChannel(
productName,
defaultChannel.id,
warehouse.id,
10,
productType.id,
attribute.id,
category.id,
1,
true,
true,
true
)
.createProductInChannel({
name: productName,
channelId: defaultChannel.id,
warehouseId: warehouse.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id
})
.then(() => {
const productUrl = `${urlList.products}${
productsUtils.getCreatedProduct().id
}`;
productSteps.updateProductIsAvailableForPurchase(productUrl, false);
frontShopProductUtils
.isProductAvailableForPurchase(
productsUtils.getCreatedProduct().id,
defaultChannel.slug,
productName
)
.then(isProductVisible => {
expect(isProductVisible).to.be.eq(false);
});
})
.then(() => {
frontShopProductUtils.isProductAvailableForPurchase(
productsUtils.getCreatedProduct().id,
defaultChannel.slug,
productName
);
})
.then(isProductVisible => {
expect(isProductVisible).to.be.eq(false);
});
});
});

View file

@ -39,19 +39,15 @@ describe("Published products", () => {
.getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createProductInChannel(
productName,
defaultChannel.id,
null,
null,
productType.id,
attribute.id,
category.id,
1,
false,
false,
true
);
productsUtils.createProductInChannel({
name: productName,
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
isPublished: false,
isAvailableForPurchase: false
});
})
.then(() => {
const product = productsUtils.getCreatedProduct();
@ -76,15 +72,13 @@ describe("Published products", () => {
.getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createProductInChannel(
productName,
defaultChannel.id,
null,
null,
productType.id,
attribute.id,
category.id
);
productsUtils.createProductInChannel({
name: productName,
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id
});
})
.then(() => {
product = productsUtils.getCreatedProduct();

View file

@ -39,19 +39,15 @@ describe("Products displayed in listings", () => {
.getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createProductInChannel(
productName,
defaultChannel.id,
null,
null,
productType.id,
attribute.id,
category.id,
1,
true,
false,
false
);
productsUtils.createProductInChannel({
name: productName,
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
visibleInListings: false,
isAvailableForPurchase: false
});
})
.then(() => {
const product = productsUtils.getCreatedProduct();
@ -73,19 +69,14 @@ describe("Products displayed in listings", () => {
.getDefaultChannel()
.then(channel => {
defaultChannel = channel;
productsUtils.createProductInChannel(
productName,
defaultChannel.id,
null,
null,
productType.id,
attribute.id,
category.id,
1,
true,
false,
true
);
productsUtils.createProductInChannel({
name: productName,
channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
visibleInListings: true
});
})
.then(() => {
const product = productsUtils.getCreatedProduct();

View file

@ -1,12 +1,12 @@
import { HEADER_SELECTORS } from "../elements/header/header-selectors";
class HomePageSteps {
changeChannel(channelName) {
cy.get(HEADER_SELECTORS.channelSelect)
.click()
.get(HEADER_SELECTORS.channelSelectList)
cy.get(HEADER_SELECTORS.channelSelect).click();
cy.addAliasToGraphRequest("Home");
cy.get(HEADER_SELECTORS.channelSelectList)
.contains(channelName)
.click()
.waitForGraph("Home");
.click();
cy.wait("@Home");
}
}
export default HomePageSteps;

View file

@ -1,30 +1,20 @@
import { PRODUCTS_SELECTORS } from "../elements/catalog/product-selectors";
class ProductSteps {
valueTrue = PRODUCTS_SELECTORS.radioButtonsValueTrue;
valueFalse = PRODUCTS_SELECTORS.radioButtonsValueFalse;
updateProductIsAvailableForPurchase(productUrl, isAvailableForPurchase) {
let isAvailableForPurchaseSelector;
if (isAvailableForPurchase) {
isAvailableForPurchaseSelector = PRODUCTS_SELECTORS.radioButtonsValueTrue;
} else {
isAvailableForPurchaseSelector =
PRODUCTS_SELECTORS.radioButtonsValueFalse;
}
this.updateProductMenageInChannel(
productUrl,
`${PRODUCTS_SELECTORS.availableForPurchaseRadioButtons}${isAvailableForPurchaseSelector}`
);
const isAvailableForPurchaseSelector = isAvailableForPurchase
? this.valueTrue
: this.valueFalse;
const availableForPurchaseSelector = `${PRODUCTS_SELECTORS.availableForPurchaseRadioButtons}${isAvailableForPurchaseSelector}`;
this.updateProductMenageInChannel(productUrl, availableForPurchaseSelector);
}
updateProductPublish(productUrl, isPublished) {
let isPublishedSelector;
if (isPublished) {
isPublishedSelector = PRODUCTS_SELECTORS.radioButtonsValueTrue;
} else {
isPublishedSelector = PRODUCTS_SELECTORS.radioButtonsValueFalse;
}
this.updateProductMenageInChannel(
productUrl,
`${PRODUCTS_SELECTORS.publishedRadioButtons}${isPublishedSelector}`
);
const isPublishedSelector = isPublished ? this.valueTrue : this.valueFalse;
const publishedSelector = `${PRODUCTS_SELECTORS.publishedRadioButtons}${isPublishedSelector}`;
this.updateProductMenageInChannel(productUrl, publishedSelector);
}
updateProductVisibleInListings(productUrl) {
this.updateProductMenageInChannel(
@ -37,10 +27,11 @@ class ProductSteps {
.get(PRODUCTS_SELECTORS.assignedChannels)
.click()
.get(menageSelector)
.click();
cy.addAliasToGraphRequest("ProductChannelListingUpdate");
cy.get(PRODUCTS_SELECTORS.saveBtn)
.click()
.get(PRODUCTS_SELECTORS.saveBtn)
.click()
.waitForGraph("ProductChannelListingUpdate");
.wait("@ProductChannelListingUpdate");
}
}
export default ProductSteps;

View file

@ -21,7 +21,7 @@ Cypress.Commands.add("clearSessionData", () => {
});
});
Cypress.Commands.add("waitForGraph", operationName => {
Cypress.Commands.add("addAliasToGraphRequest", operationName => {
cy.intercept("POST", urlList.apiUri, req => {
req.statusCode = 200;
const requestBody = req.body;
@ -37,7 +37,6 @@ Cypress.Commands.add("waitForGraph", operationName => {
}
}
});
cy.wait(`@${operationName}`);
});
Cypress.Commands.add("sendRequestWithQuery", query => {

View file

@ -22,28 +22,28 @@ class ProductsUtils {
).then(() => this.createVariant(this.product.id, name));
}
createProductInChannel(
createProductInChannel({
name,
channelId,
warehouseId,
quantityInWarehouse,
warehouseId = null,
quantityInWarehouse = 10,
productTypeId,
attributeId,
categoryId,
price,
price = 1,
isPublished = true,
isAvailableForPurchase = true,
visibleInListings = true
) {
}) {
return this.createProduct(attributeId, name, productTypeId, categoryId)
.then(() =>
this.productRequest.updateChannelInProduct(
this.product.id,
this.productRequest.updateChannelInProduct({
productId: this.product.id,
channelId,
isPublished,
isAvailableForPurchase,
visibleInListings
)
})
)
.then(() => {
this.createVariant(

View file

@ -8,7 +8,7 @@ class ShippingUtils {
shippingZone;
warehouse;
createShipping(channelId, name, address, price) {
createShipping({ channelId, name, address, price = 1 }) {
return this.createShippingZone(name, address.country)
.then(() => this.createWarehouse(name, this.shippingZone.id, address))
.then(() => this.createShippingRate(name, this.shippingZone.id))