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