tests for collections
This commit is contained in:
parent
b6093e3fc5
commit
bc9d6a0666
7 changed files with 109 additions and 115 deletions
|
@ -2,6 +2,8 @@
|
||||||
import faker from "faker";
|
import faker from "faker";
|
||||||
|
|
||||||
import Product from "../apiRequests/Product";
|
import Product from "../apiRequests/Product";
|
||||||
|
import Collections from "../apiRequests/storeFront/Collections";
|
||||||
|
import Search from "../apiRequests/storeFront/Search";
|
||||||
import CollectionsSteps from "../steps/collectionsSteps";
|
import CollectionsSteps from "../steps/collectionsSteps";
|
||||||
import { urlList } from "../url/urlList";
|
import { urlList } from "../url/urlList";
|
||||||
import ChannelsUtils from "../utils/channelsUtils";
|
import ChannelsUtils from "../utils/channelsUtils";
|
||||||
|
@ -16,6 +18,8 @@ import { isProductVisibleInSearchResult } from "../utils/storeFront/storeFrontPr
|
||||||
|
|
||||||
describe("Collections", () => {
|
describe("Collections", () => {
|
||||||
const productRequest = new Product();
|
const productRequest = new Product();
|
||||||
|
const collectionsRequest = new Collections();
|
||||||
|
const search = new Search();
|
||||||
const channelsUtils = new ChannelsUtils();
|
const channelsUtils = new ChannelsUtils();
|
||||||
const productsUtils = new ProductsUtils();
|
const productsUtils = new ProductsUtils();
|
||||||
const collectionsUtils = new CollectionsUtils();
|
const collectionsUtils = new CollectionsUtils();
|
||||||
|
@ -73,25 +77,34 @@ describe("Collections", () => {
|
||||||
collectionsSteps.assignProductsToCollection(name);
|
collectionsSteps.assignProductsToCollection(name);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
isCollectionVisible(collection.id, defaultChannel.slug);
|
collectionsRequest.getCollection(collection.id, defaultChannel.slug);
|
||||||
})
|
})
|
||||||
.then(isVisible => expect(isVisible).to.equal(false));
|
.then(resp => {
|
||||||
|
const isVisible = isCollectionVisible(resp, collection.id);
|
||||||
|
expect(isVisible).to.equal(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should display collections", () => {
|
it("should display collections", () => {
|
||||||
const collectionName = `${startsWith}${faker.random.number()}`;
|
const collectionName = `${startsWith}${faker.random.number()}`;
|
||||||
|
let collection;
|
||||||
cy.visit(urlList.collections);
|
cy.visit(urlList.collections);
|
||||||
|
|
||||||
collectionsSteps
|
collectionsSteps
|
||||||
.createCollection(collectionName, true, defaultChannel)
|
.createCollection(collectionName, true, defaultChannel)
|
||||||
.then(collection => {
|
.then(collectionResp => {
|
||||||
|
collection = collectionResp;
|
||||||
collectionsSteps.assignProductsToCollection(name);
|
collectionsSteps.assignProductsToCollection(name);
|
||||||
isCollectionVisible(collection.id, defaultChannel.slug);
|
collectionsRequest.getCollection(collection.id, defaultChannel.slug);
|
||||||
})
|
})
|
||||||
.then(isVisible => expect(isVisible).to.equal(true));
|
.then(resp => {
|
||||||
|
const isVisible = isCollectionVisible(resp, collection.id);
|
||||||
|
expect(isVisible).to.equal(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it("should not display collection not set as available in channel", () => {
|
it("should not display collection not set as available in channel", () => {
|
||||||
const collectionName = `${startsWith}${faker.random.number()}`;
|
const collectionName = `${startsWith}${faker.random.number()}`;
|
||||||
|
let collection;
|
||||||
|
|
||||||
channelsUtils
|
channelsUtils
|
||||||
.createChannel({ name: collectionName })
|
.createChannel({ name: collectionName })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
@ -108,11 +121,15 @@ describe("Collections", () => {
|
||||||
channelsUtils.getCreatedChannel()
|
channelsUtils.getCreatedChannel()
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then(collection => {
|
.then(collectionResp => {
|
||||||
|
collection = collectionResp;
|
||||||
collectionsSteps.assignProductsToCollection(name);
|
collectionsSteps.assignProductsToCollection(name);
|
||||||
isCollectionVisible(collection.id, defaultChannel.slug);
|
collectionsRequest.getCollection(collection.id, defaultChannel.slug);
|
||||||
})
|
})
|
||||||
.then(isVisible => expect(isVisible).to.equal(false));
|
.then(resp => {
|
||||||
|
const isVisible = isCollectionVisible(resp, collection.id);
|
||||||
|
expect(isVisible).to.equal(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it("should display products hidden in listing", () => {
|
it("should display products hidden in listing", () => {
|
||||||
// Products "hidden in listings" are not displayed in Category listings or search results,
|
// Products "hidden in listings" are not displayed in Category listings or search results,
|
||||||
|
@ -137,22 +154,23 @@ describe("Collections", () => {
|
||||||
collectionsSteps.assignProductsToCollection(randomName);
|
collectionsSteps.assignProductsToCollection(randomName);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
isProductInCollectionVisible(
|
collectionsRequest.getCollection(collection.id, defaultChannel.slug);
|
||||||
collection.id,
|
})
|
||||||
defaultChannel.slug,
|
.then(resp => {
|
||||||
|
const isVisible = isProductInCollectionVisible(
|
||||||
|
resp,
|
||||||
hiddenProductUtils.getCreatedProduct().id
|
hiddenProductUtils.getCreatedProduct().id
|
||||||
);
|
);
|
||||||
})
|
|
||||||
.then(isVisible => {
|
|
||||||
expect(isVisible).to.equal(true);
|
expect(isVisible).to.equal(true);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
isProductVisibleInSearchResult(
|
search.searchInShop(hiddenProductUtils.getCreatedProduct().name);
|
||||||
hiddenProductUtils.getCreatedProduct().name,
|
|
||||||
defaultChannel.slug
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.then(isVisible => {
|
.then(resp => {
|
||||||
|
const isVisible = isProductVisibleInSearchResult(
|
||||||
|
resp,
|
||||||
|
hiddenProductUtils.getCreatedProduct().name
|
||||||
|
);
|
||||||
expect(isVisible).to.equal(false);
|
expect(isVisible).to.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import faker from "faker";
|
import faker from "faker";
|
||||||
|
|
||||||
|
import ProductDetails from "../../../apiRequests/storeFront/ProductDetails";
|
||||||
import ProductSteps from "../../../steps/products/productSteps";
|
import ProductSteps from "../../../steps/products/productSteps";
|
||||||
import { productDetailsUrl } from "../../../url/urlList";
|
import { productDetailsUrl } from "../../../url/urlList";
|
||||||
import ChannelsUtils from "../../../utils/channelsUtils";
|
import ChannelsUtils from "../../../utils/channelsUtils";
|
||||||
|
@ -9,6 +10,7 @@ import { isProductAvailableForPurchase } from "../../../utils/storeFront/storeFr
|
||||||
|
|
||||||
// <reference types="cypress" />
|
// <reference types="cypress" />
|
||||||
describe("Products available in listings", () => {
|
describe("Products available in listings", () => {
|
||||||
|
const productDetails = new ProductDetails();
|
||||||
const shippingUtils = new ShippingUtils();
|
const shippingUtils = new ShippingUtils();
|
||||||
const channelsUtils = new ChannelsUtils();
|
const channelsUtils = new ChannelsUtils();
|
||||||
const productsUtils = new ProductsUtils();
|
const productsUtils = new ProductsUtils();
|
||||||
|
@ -73,14 +75,13 @@ describe("Products available in listings", () => {
|
||||||
productSteps.updateProductIsAvailableForPurchase(productUrl, true);
|
productSteps.updateProductIsAvailableForPurchase(productUrl, true);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
isProductAvailableForPurchase(
|
productDetails.getProductDetails(
|
||||||
productsUtils.getCreatedProduct().id,
|
productsUtils.getCreatedProduct().id,
|
||||||
defaultChannel.slug,
|
defaultChannel.slug
|
||||||
productName
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then(isVisibleResp => {
|
.then(resp => {
|
||||||
expect(isVisibleResp).to.be.eq(true);
|
expect(isProductAvailableForPurchase(resp)).to.be.eq(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("should update product to not available for purchase", () => {
|
it("should update product to not available for purchase", () => {
|
||||||
|
@ -101,14 +102,13 @@ describe("Products available in listings", () => {
|
||||||
productSteps.updateProductIsAvailableForPurchase(productUrl, false);
|
productSteps.updateProductIsAvailableForPurchase(productUrl, false);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
isProductAvailableForPurchase(
|
productDetails.getProductDetails(
|
||||||
productsUtils.getCreatedProduct().id,
|
productsUtils.getCreatedProduct().id,
|
||||||
defaultChannel.slug,
|
defaultChannel.slug
|
||||||
productName
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then(isProductVisible => {
|
.then(resp => {
|
||||||
expect(isProductVisible).to.be.eq(false);
|
expect(isProductAvailableForPurchase(resp)).to.be.eq(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import faker from "faker";
|
import faker from "faker";
|
||||||
|
|
||||||
|
import ProductDetails from "../../../apiRequests/storeFront/ProductDetails";
|
||||||
import ProductSteps from "../../../steps/products/productSteps";
|
import ProductSteps from "../../../steps/products/productSteps";
|
||||||
import { productDetailsUrl } from "../../../url/urlList";
|
import { productDetailsUrl } from "../../../url/urlList";
|
||||||
import ChannelsUtils from "../../../utils/channelsUtils";
|
import ChannelsUtils from "../../../utils/channelsUtils";
|
||||||
|
@ -8,6 +9,7 @@ import { isProductVisible } from "../../../utils/storeFront/storeFrontProductUti
|
||||||
|
|
||||||
// <reference types="cypress" />
|
// <reference types="cypress" />
|
||||||
describe("Published products", () => {
|
describe("Published products", () => {
|
||||||
|
const productDetails = new ProductDetails();
|
||||||
const channelsUtils = new ChannelsUtils();
|
const channelsUtils = new ChannelsUtils();
|
||||||
const productsUtils = new ProductsUtils();
|
const productsUtils = new ProductsUtils();
|
||||||
const productSteps = new ProductSteps();
|
const productSteps = new ProductSteps();
|
||||||
|
@ -52,9 +54,10 @@ describe("Published products", () => {
|
||||||
const product = productsUtils.getCreatedProduct();
|
const product = productsUtils.getCreatedProduct();
|
||||||
const productUrl = productDetailsUrl(product.id);
|
const productUrl = productDetailsUrl(product.id);
|
||||||
productSteps.updateProductPublish(productUrl, true);
|
productSteps.updateProductPublish(productUrl, true);
|
||||||
isProductVisible(product.id, defaultChannel.slug, productName);
|
productDetails.getProductDetails(product.id, defaultChannel.slug);
|
||||||
})
|
})
|
||||||
.then(isVisible => {
|
.then(resp => {
|
||||||
|
const isVisible = isProductVisible(resp, productName);
|
||||||
expect(isVisible).to.be.eq(true);
|
expect(isVisible).to.be.eq(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -79,16 +82,18 @@ describe("Published products", () => {
|
||||||
product = productsUtils.getCreatedProduct();
|
product = productsUtils.getCreatedProduct();
|
||||||
const productUrl = productDetailsUrl(product.id);
|
const productUrl = productDetailsUrl(product.id);
|
||||||
productSteps.updateProductPublish(productUrl, false);
|
productSteps.updateProductPublish(productUrl, false);
|
||||||
isProductVisible(product.id, defaultChannel.slug, productName);
|
productDetails.getProductDetails(product.id, defaultChannel.slug);
|
||||||
})
|
})
|
||||||
.then(isVisible => {
|
.then(resp => {
|
||||||
|
const isVisible = isProductVisible(resp, productName);
|
||||||
expect(isVisible).to.be.eq(false);
|
expect(isVisible).to.be.eq(false);
|
||||||
cy.loginInShop();
|
cy.loginInShop();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
isProductVisible(product.id, defaultChannel.slug, productName);
|
productDetails.getProductDetails(product.id, defaultChannel.slug);
|
||||||
})
|
})
|
||||||
.then(isVisible => {
|
.then(resp => {
|
||||||
|
const isVisible = isProductVisible(resp, productName);
|
||||||
expect(isVisible).to.be.eq(true);
|
expect(isVisible).to.be.eq(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import faker from "faker";
|
import faker from "faker";
|
||||||
|
|
||||||
|
import Search from "../../../apiRequests/storeFront/Search";
|
||||||
import ProductSteps from "../../../steps/products/productSteps";
|
import ProductSteps from "../../../steps/products/productSteps";
|
||||||
import { productDetailsUrl } from "../../../url/urlList";
|
import { productDetailsUrl } from "../../../url/urlList";
|
||||||
import ChannelsUtils from "../../../utils/channelsUtils";
|
import ChannelsUtils from "../../../utils/channelsUtils";
|
||||||
|
@ -8,6 +9,7 @@ import { isProductVisibleInSearchResult } from "../../../utils/storeFront/storeF
|
||||||
|
|
||||||
// <reference types="cypress" />
|
// <reference types="cypress" />
|
||||||
describe("Products displayed in listings", () => {
|
describe("Products displayed in listings", () => {
|
||||||
|
const search = new Search();
|
||||||
const channelsUtils = new ChannelsUtils();
|
const channelsUtils = new ChannelsUtils();
|
||||||
const productsUtils = new ProductsUtils();
|
const productsUtils = new ProductsUtils();
|
||||||
const productSteps = new ProductSteps();
|
const productSteps = new ProductSteps();
|
||||||
|
@ -52,9 +54,13 @@ describe("Products displayed in listings", () => {
|
||||||
const product = productsUtils.getCreatedProduct();
|
const product = productsUtils.getCreatedProduct();
|
||||||
const productUrl = productDetailsUrl(product.id);
|
const productUrl = productDetailsUrl(product.id);
|
||||||
productSteps.updateProductVisibleInListings(productUrl);
|
productSteps.updateProductVisibleInListings(productUrl);
|
||||||
isProductVisibleInSearchResult(productName, defaultChannel.slug);
|
search.searchInShop(productName);
|
||||||
})
|
})
|
||||||
.then(isProductVisible => {
|
.then(resp => {
|
||||||
|
const isProductVisible = isProductVisibleInSearchResult(
|
||||||
|
resp,
|
||||||
|
productName
|
||||||
|
);
|
||||||
expect(isProductVisible).to.be.eq(true);
|
expect(isProductVisible).to.be.eq(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -78,17 +84,24 @@ describe("Products displayed in listings", () => {
|
||||||
const product = productsUtils.getCreatedProduct();
|
const product = productsUtils.getCreatedProduct();
|
||||||
const productUrl = productDetailsUrl(product.id);
|
const productUrl = productDetailsUrl(product.id);
|
||||||
productSteps.updateProductVisibleInListings(productUrl);
|
productSteps.updateProductVisibleInListings(productUrl);
|
||||||
isProductVisibleInSearchResult(productName, defaultChannel.slug).then(
|
|
||||||
isProductVisible => {
|
search.searchInShop(productName).then(resp => {
|
||||||
expect(isProductVisible).to.be.eq(false);
|
const isProductVisible = isProductVisibleInSearchResult(
|
||||||
}
|
resp,
|
||||||
);
|
productName
|
||||||
|
);
|
||||||
|
expect(isProductVisible).to.be.eq(false);
|
||||||
|
});
|
||||||
cy.loginInShop();
|
cy.loginInShop();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
isProductVisibleInSearchResult(productName, defaultChannel.slug);
|
search.searchInShop(productName);
|
||||||
})
|
})
|
||||||
.then(isProductVisible => {
|
.then(resp => {
|
||||||
|
const isProductVisible = isProductVisibleInSearchResult(
|
||||||
|
resp,
|
||||||
|
productName
|
||||||
|
);
|
||||||
expect(isProductVisible).to.be.eq(true);
|
expect(isProductVisible).to.be.eq(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,23 +1,11 @@
|
||||||
import Collections from "../../apiRequests/storeFront/Collections";
|
export const isCollectionVisible = (resp, collectionId) => {
|
||||||
import { isVisible } from "./utils";
|
const collection = resp.body.data.collection;
|
||||||
|
return collection !== null && collection.id === collectionId;
|
||||||
|
};
|
||||||
|
|
||||||
const collectionsRequest = new Collections();
|
export const isProductInCollectionVisible = (resp, productId) => {
|
||||||
|
const productsList = resp.body.data.collection.products;
|
||||||
export const isCollectionVisible = (collectionId, channelSlug) =>
|
return (
|
||||||
isVisible({
|
productsList.totalCount !== 0 && productsList.edges[0].node.id === productId
|
||||||
request: collectionsRequest.getCollection(collectionId, channelSlug),
|
);
|
||||||
respObjectKey: ["collection"],
|
};
|
||||||
responseValueKey: ["id"],
|
|
||||||
value: collectionId
|
|
||||||
});
|
|
||||||
export const isProductInCollectionVisible = (
|
|
||||||
collectionId,
|
|
||||||
channelSlug,
|
|
||||||
productId
|
|
||||||
) =>
|
|
||||||
isVisible({
|
|
||||||
request: collectionsRequest.getCollection(collectionId, channelSlug),
|
|
||||||
respObjectKey: ["collection", "products"],
|
|
||||||
responseValueKey: ["edges", 0, "node", "id"],
|
|
||||||
value: productId
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,37 +1,30 @@
|
||||||
import ProductDetails from "../../apiRequests/storeFront/ProductDetails";
|
import ProductDetails from "../../apiRequests/storeFront/ProductDetails";
|
||||||
import Search from "../../apiRequests/storeFront/Search";
|
|
||||||
import { isVisible } from "./utils";
|
|
||||||
|
|
||||||
const productDetails = new ProductDetails();
|
export const isProductVisible = (resp, name) => {
|
||||||
const search = new Search();
|
const product = resp.body.data.product;
|
||||||
|
return product !== null && product.name === name;
|
||||||
|
};
|
||||||
|
|
||||||
export const isProductVisible = (productId, channelSlug, name) =>
|
export const isProductAvailableForPurchase = resp => {
|
||||||
isVisible({
|
const product = resp.body.data.product;
|
||||||
request: productDetails.getProductDetails(productId, channelSlug),
|
return product.isAvailableForPurchase;
|
||||||
respObjectKey: ["product"],
|
};
|
||||||
responseValueKey: ["name"],
|
|
||||||
value: name
|
|
||||||
});
|
|
||||||
|
|
||||||
export const isProductAvailableForPurchase = (productId, channelSlug) =>
|
export const isProductVisibleInSearchResult = (resp, productName) => {
|
||||||
isVisible({
|
const productsList = resp.body.data.products;
|
||||||
request: productDetails.getProductDetails(productId, channelSlug),
|
return (
|
||||||
respObjectKey: ["product"],
|
productsList.totalCount !== 0 &&
|
||||||
responseValueKey: ["isAvailableForPurchase"]
|
productsList.edges[0].node.name === productName
|
||||||
});
|
);
|
||||||
export const isProductVisibleInSearchResult = (productName, channelSlug) =>
|
};
|
||||||
isVisible({
|
|
||||||
request: search.searchInShop(productName, channelSlug),
|
|
||||||
respObjectKey: ["products"],
|
|
||||||
responseValueKey: ["edges", 0, "node", "name"],
|
|
||||||
value: productName
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getProductVariants = (productId, channelSlug) =>
|
export const getProductVariants = (productId, channelSlug) => {
|
||||||
productDetails.getProductDetails(productId, channelSlug).then(resp => {
|
const productDetails = new ProductDetails();
|
||||||
|
return productDetails.getProductDetails(productId, channelSlug).then(resp => {
|
||||||
const variantsList = resp.body.data.product.variants;
|
const variantsList = resp.body.data.product.variants;
|
||||||
return variantsList.map(element => ({
|
return variantsList.map(element => ({
|
||||||
name: element.name,
|
name: element.name,
|
||||||
price: element.pricing.price.gross.amount
|
price: element.pricing.price.gross.amount
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
export const isVisible = ({
|
|
||||||
request,
|
|
||||||
respObjectKey,
|
|
||||||
responseValueKey,
|
|
||||||
value = true
|
|
||||||
}) =>
|
|
||||||
request.then(resp => {
|
|
||||||
resp = resp.body.data;
|
|
||||||
respObjectKey.forEach(element => {
|
|
||||||
resp = resp[element];
|
|
||||||
});
|
|
||||||
if (resp === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ("totalCount" in resp && resp.totalCount === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
let respValue = resp;
|
|
||||||
responseValueKey.forEach(element => {
|
|
||||||
respValue = respValue[element];
|
|
||||||
});
|
|
||||||
return respValue === value;
|
|
||||||
});
|
|
Loading…
Reference in a new issue