diff --git a/cypress/apiRequests/storeFront/Collections.js b/cypress/apiRequests/storeFront/Collections.js index 0b50dbf54..8bda6429e 100644 --- a/cypress/apiRequests/storeFront/Collections.js +++ b/cypress/apiRequests/storeFront/Collections.js @@ -15,7 +15,7 @@ class Collections { } } }`; - return cy.sendFrontShopRequestWithQuery(query); + return cy.sendRequestWithQuery(query, "token"); } } export default Collections; diff --git a/cypress/integration/collections.js b/cypress/integration/collections.js index 0e32fb2cc..768f7a947 100644 --- a/cypress/integration/collections.js +++ b/cypress/integration/collections.js @@ -8,16 +8,17 @@ import ChannelsUtils from "../utils/channelsUtils"; import CollectionsUtils from "../utils/collectionsUtils"; import ProductsUtils from "../utils/productsUtils"; import ShippingUtils from "../utils/shippingUtils"; -import StoreFrontCollectionUtils from "../utils/storeFront/collectionsUtils"; -import StoreFrontProductUtils from "../utils/storeFront/storeFrontProductUtils"; +import { + isCollectionVisible, + isProductInCollectionVisible +} from "../utils/storeFront/collectionsUtils"; +import { isProductVisibleInSearchResult } from "../utils/storeFront/storeFrontProductUtils"; describe("Collections", () => { const productRequest = new Product(); const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); - const storeFrontProductUtils = new StoreFrontProductUtils(); const collectionsUtils = new CollectionsUtils(); - const storeFrontCollectionUtils = new StoreFrontCollectionUtils(); const shippingUtils = new ShippingUtils(); const collectionsSteps = new CollectionsSteps(); @@ -63,15 +64,16 @@ describe("Collections", () => { it("should not display hidden collections", () => { const collectionName = `${startsWith}${faker.random.number()}`; cy.visit(urlList.collections); + let collection; collectionsSteps .createCollection(collectionName, false, defaultChannel) - .then(collection => { + .then(collectionResp => { + collection = collectionResp; collectionsSteps.assignProductsToCollection(name); - storeFrontCollectionUtils.isCollectionVisible( - collection.id, - defaultChannel.slug - ); + }) + .then(() => { + isCollectionVisible(collection.id, defaultChannel.slug); }) .then(isVisible => expect(isVisible).to.equal(false)); }); @@ -84,10 +86,7 @@ describe("Collections", () => { .createCollection(collectionName, true, defaultChannel) .then(collection => { collectionsSteps.assignProductsToCollection(name); - storeFrontCollectionUtils.isCollectionVisible( - collection.id, - defaultChannel.slug - ); + isCollectionVisible(collection.id, defaultChannel.slug); }) .then(isVisible => expect(isVisible).to.equal(true)); }); @@ -111,16 +110,15 @@ describe("Collections", () => { }) .then(collection => { collectionsSteps.assignProductsToCollection(name); - storeFrontCollectionUtils.isCollectionVisible( - collection.id, - defaultChannel.slug - ); + isCollectionVisible(collection.id, defaultChannel.slug); }) .then(isVisible => expect(isVisible).to.equal(false)); }); it("should display products hidden in listing, only in collection", () => { const randomName = `${startsWith}${faker.random.number()}`; const hiddenProductUtils = new ProductsUtils(); + let collection; + hiddenProductUtils.createProductInChannel({ name: randomName, channelId: defaultChannel.id, @@ -132,9 +130,12 @@ describe("Collections", () => { cy.visit(urlList.collections); collectionsSteps .createCollection(randomName, true, defaultChannel) - .then(collection => { + .then(collectionResp => { + collection = collectionResp; collectionsSteps.assignProductsToCollection(randomName); - storeFrontCollectionUtils.isProductInCollectionVisible( + }) + .then(() => { + isProductInCollectionVisible( collection.id, defaultChannel.slug, hiddenProductUtils.getCreatedProduct().id @@ -142,7 +143,7 @@ describe("Collections", () => { }) .then(isVisible => { expect(isVisible).to.equal(true); - storeFrontProductUtils.isProductVisibleInSearchResult( + isProductVisibleInSearchResult( hiddenProductUtils.getCreatedProduct().name, defaultChannel.slug ); diff --git a/cypress/utils/storeFront/collectionsUtils.js b/cypress/utils/storeFront/collectionsUtils.js index 3a25953c0..57d50b252 100644 --- a/cypress/utils/storeFront/collectionsUtils.js +++ b/cypress/utils/storeFront/collectionsUtils.js @@ -1,23 +1,24 @@ import Collections from "../../apiRequests/storeFront/Collections"; -class CollectionsUtils { - collectionsRequest = new Collections(); - - isCollectionVisible(collectionId, channelSlug) { - return this.collectionsRequest - .getCollection(collectionId, channelSlug) - .then(resp => { - const collection = resp.body.data.collection; - return collection !== null && collection.id === collectionId; - }); - } - isProductInCollectionVisible(collectionId, channelSlug, productId) { - return this.collectionsRequest - .getCollection(collectionId, channelSlug) - .then(resp => { - const product = resp.body.data.collection.products.edges[0].node; - return product !== null && product.id === productId; - }); - } -} -export default CollectionsUtils; +export const isCollectionVisible = (collectionId, channelSlug) => { + const collectionsRequest = new Collections(); + return collectionsRequest + .getCollection(collectionId, channelSlug) + .then(resp => { + const collection = resp.body.data.collection; + return collection !== null && collection.id === collectionId; + }); +}; +export const isProductInCollectionVisible = ( + collectionId, + channelSlug, + productId +) => { + const collectionsRequest = new Collections(); + return collectionsRequest + .getCollection(collectionId, channelSlug) + .then(resp => { + const product = resp.body.data.collection.products.edges[0].node; + return product !== null && product.id === productId; + }); +};