Saleor 2590 remove classes from cypress tests (#1003)

* remove classes in shipping & products utils

* remove classes

* add const

* remove getters in ProductsUtils

* remove getters in Utils

* remove getters in Utils
This commit is contained in:
Karolina 2021-03-12 13:14:18 +01:00 committed by GitHub
parent 88f51a1d31
commit fc597a7a7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 967 additions and 1090 deletions

View file

@ -1,12 +1,11 @@
class Attribute { export function createAttribute(name, attributeValues = ["value"]) {
createAttribute(name, attributeValues = ["value"]) { const values = attributeValues.map(element => `{name:"${element}"}`);
attributeValues = attributeValues.map(element => `{name:"${element}"}`);
const mutation = `mutation{ const mutation = `mutation{
attributeCreate(input:{ attributeCreate(input:{
name:"${name}" name:"${name}"
valueRequired:false valueRequired:false
type:PRODUCT_TYPE type:PRODUCT_TYPE
values: [${attributeValues}] values: [${values}]
}){ }){
attribute{ attribute{
id id
@ -20,9 +19,9 @@ class Attribute {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
getAttributes(first, search) { export function getAttributes(first, search) {
const mutation = `query{ const mutation = `query{
attributes(first:${first}, filter:{ attributes(first:${first}, filter:{
search:"${search}" search:"${search}"
@ -38,9 +37,9 @@ class Attribute {
return cy return cy
.sendRequestWithQuery(mutation) .sendRequestWithQuery(mutation)
.then(resp => resp.body.data.attributes.edges); .then(resp => resp.body.data.attributes.edges);
} }
deleteAttribute(attributeId) { export function deleteAttribute(attributeId) {
const mutation = `mutation{ const mutation = `mutation{
attributeDelete(id:"${attributeId}"){ attributeDelete(id:"${attributeId}"){
attributeErrors{ attributeErrors{
@ -50,6 +49,4 @@ class Attribute {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Attribute;

View file

@ -1,5 +1,4 @@
class Category { export function createCategory(name, slug = name) {
createCategory(name, slug = name) {
const mutation = `mutation{ const mutation = `mutation{
categoryCreate(input:{name:"${name}", slug: "${slug}"}){ categoryCreate(input:{name:"${name}", slug: "${slug}"}){
productErrors{ productErrors{
@ -12,8 +11,8 @@ class Category {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
getCategories(first, search) { export function getCategories(first, search) {
const mutation = `query{ const mutation = `query{
categories(first:${first}, filter:{ categories(first:${first}, filter:{
search:"${search}" search:"${search}"
@ -29,8 +28,8 @@ class Category {
return cy return cy
.sendRequestWithQuery(mutation) .sendRequestWithQuery(mutation)
.then(resp => resp.body.data.categories.edges); .then(resp => resp.body.data.categories.edges);
} }
deleteCategory(categoryId) { export function deleteCategory(categoryId) {
const mutation = `mutation{ const mutation = `mutation{
categoryDelete(id:"${categoryId}"){ categoryDelete(id:"${categoryId}"){
productErrors{ productErrors{
@ -40,6 +39,4 @@ class Category {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Category;

View file

@ -1,5 +1,4 @@
class Channels { export function createChannel(isActive, name, slug, currencyCode) {
createChannel(isActive, name, slug, currencyCode) {
const createChannelMutation = `mutation{ const createChannelMutation = `mutation{
channelCreate(input: { channelCreate(input: {
isActive: ${isActive} isActive: ${isActive}
@ -19,8 +18,8 @@ class Channels {
} }
}`; }`;
return cy.sendRequestWithQuery(createChannelMutation); return cy.sendRequestWithQuery(createChannelMutation);
} }
getChannels() { export function getChannels() {
const getChannelsInfoQuery = `query{ const getChannelsInfoQuery = `query{
channels{ channels{
name name
@ -32,9 +31,9 @@ class Channels {
} }
`; `;
return cy.sendRequestWithQuery(getChannelsInfoQuery); return cy.sendRequestWithQuery(getChannelsInfoQuery);
} }
deleteChannel(channelId, targetChannelId) { export function deleteChannel(channelId, targetChannelId) {
const deleteChannelMutation = `mutation{ const deleteChannelMutation = `mutation{
channelDelete(id: "${channelId}", input:{ channelDelete(id: "${channelId}", input:{
targetChannel: "${targetChannelId}" targetChannel: "${targetChannelId}"
@ -48,6 +47,4 @@ class Channels {
} }
}`; }`;
return cy.sendRequestWithQuery(deleteChannelMutation); return cy.sendRequestWithQuery(deleteChannelMutation);
}
} }
export default Channels;

View file

@ -1,5 +1,9 @@
class Checkout { export function createCheckout(
createCheckout(channelSlug, email, productQuantity, variantsList) { channelSlug,
email,
productQuantity,
variantsList
) {
const lines = variantsList.map( const lines = variantsList.map(
variant => `{quantity:${productQuantity} variant => `{quantity:${productQuantity}
variantId:"${variant.id}"}` variantId:"${variant.id}"}`
@ -21,8 +25,8 @@ class Checkout {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
addShippingMethod(checkoutId, shippingMethodId) { export function addShippingMethod(checkoutId, shippingMethodId) {
const mutation = `mutation{ const mutation = `mutation{
checkoutShippingMethodUpdate(checkoutId:"${checkoutId}", checkoutShippingMethodUpdate(checkoutId:"${checkoutId}",
shippingMethodId:"${shippingMethodId}"){ shippingMethodId:"${shippingMethodId}"){
@ -33,8 +37,8 @@ class Checkout {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
addPayment(checkoutId, gateway, token) { export function addPayment(checkoutId, gateway, token) {
const mutation = `mutation{ const mutation = `mutation{
checkoutPaymentCreate(checkoutId:"${checkoutId}", checkoutPaymentCreate(checkoutId:"${checkoutId}",
input:{ input:{
@ -48,8 +52,8 @@ class Checkout {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
completeCheckout(checkoutId) { export function completeCheckout(checkoutId) {
const mutation = `mutation{ const mutation = `mutation{
checkoutComplete(checkoutId:"${checkoutId}"){ checkoutComplete(checkoutId:"${checkoutId}"){
order{ order{
@ -64,6 +68,4 @@ class Checkout {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Checkout;

View file

@ -1,5 +1,4 @@
class Collections { export function getCollections(search) {
getCollections(search) {
const filter = search const filter = search
? `, filter:{ ? `, filter:{
search:"" search:""
@ -18,8 +17,8 @@ class Collections {
return cy return cy
.sendRequestWithQuery(query) .sendRequestWithQuery(query)
.then(resp => resp.body.data.collections.edges); .then(resp => resp.body.data.collections.edges);
} }
deleteCollection(collectionId) { export function deleteCollection(collectionId) {
const mutation = `mutation{ const mutation = `mutation{
collectionDelete(id:"${collectionId}"){ collectionDelete(id:"${collectionId}"){
collection{ collection{
@ -32,6 +31,4 @@ class Collections {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Collections;

View file

@ -1,5 +1,4 @@
export class Customer { export function createCustomer(email, customerName, address, isActive = false) {
createCustomer(email, customerName, address, isActive = false) {
const mutation = ` const mutation = `
mutation{ mutation{
customerCreate(input:{ customerCreate(input:{
@ -38,22 +37,22 @@ export class Customer {
} }
`; `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
deleteCustomers(startsWith) { export function deleteCustomers(startsWith) {
this.getCustomers(startsWith).then(resp => { getCustomers(startsWith).then(resp => {
if (resp.body.data.customers) { if (resp.body.data.customers) {
const customers = resp.body.data.customers.edges; const customers = resp.body.data.customers.edges;
customers.forEach(element => { customers.forEach(element => {
if (element.node.email.includes(startsWith)) { if (element.node.email.includes(startsWith)) {
this.deleteCustomer(element.node.id); deleteCustomer(element.node.id);
} }
}); });
} }
}); });
} }
deleteCustomer(customerId) { export function deleteCustomer(customerId) {
const mutation = `mutation{ const mutation = `mutation{
customerDelete(id:"${customerId}"){ customerDelete(id:"${customerId}"){
accountErrors{ accountErrors{
@ -63,9 +62,9 @@ export class Customer {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
getCustomers(startsWith) { export function getCustomers(startsWith) {
const query = `query{ const query = `query{
customers(first:100, filter: { customers(first:100, filter: {
search: "${startsWith}" search: "${startsWith}"
@ -80,6 +79,4 @@ export class Customer {
} }
`; `;
return cy.sendRequestWithQuery(query); return cy.sendRequestWithQuery(query);
}
} }
export default Customer;

View file

@ -1,5 +1,4 @@
class HomePage { export function getSalesForChannel(channelSlug, period) {
getSalesForChannel(channelSlug, period) {
const query = `query{ const query = `query{
ordersTotal(period: ${period}, channel:"${channelSlug}"){ ordersTotal(period: ${period}, channel:"${channelSlug}"){
gross{ gross{
@ -8,30 +7,28 @@ class HomePage {
} }
}`; }`;
return cy.sendRequestWithQuery(query); return cy.sendRequestWithQuery(query);
} }
getOrdersForChannel(channelSlug, created) { export function getOrdersForChannel(channelSlug, created) {
const query = `query{ const query = `query{
orders(created: ${created}, channel:"${channelSlug}"){ orders(created: ${created}, channel:"${channelSlug}"){
totalCount totalCount
} }
}`; }`;
return cy.sendRequestWithQuery(query); return cy.sendRequestWithQuery(query);
} }
getOrdersWithStatus(status, channelSlug) { export function getOrdersWithStatus(status, channelSlug) {
const query = `query{ const query = `query{
orders(status: ${status}, channel:"${channelSlug}"){ orders(status: ${status}, channel:"${channelSlug}"){
totalCount totalCount
} }
}`; }`;
return cy.sendRequestWithQuery(query); return cy.sendRequestWithQuery(query);
} }
getProductsOutOfStock(channelSlug) { export function getProductsOutOfStock(channelSlug) {
const query = `query{ const query = `query{
products(stockAvailability: OUT_OF_STOCK, channel:"${channelSlug}"){ products(stockAvailability: OUT_OF_STOCK, channel:"${channelSlug}"){
totalCount totalCount
} }
}`; }`;
return cy.sendRequestWithQuery(query); return cy.sendRequestWithQuery(query);
}
} }
export default HomePage;

View file

@ -1,5 +1,4 @@
class Order { export function markOrderAsPaid(orderId) {
markOrderAsPaid(orderId) {
const mutation = `mutation{ const mutation = `mutation{
orderMarkAsPaid(id:"${orderId}"){ orderMarkAsPaid(id:"${orderId}"){
orderErrors{ orderErrors{
@ -8,9 +7,9 @@ class Order {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
addProductToOrder(orderId, variantId, quantity = 1) { export function addProductToOrder(orderId, variantId, quantity = 1) {
const mutation = `mutation{ const mutation = `mutation{
draftOrderLinesCreate(id:"${orderId}", input:{ draftOrderLinesCreate(id:"${orderId}", input:{
quantity:${quantity} quantity:${quantity}
@ -22,9 +21,9 @@ class Order {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
createDraftOrder(customerId, shippingMethodId, channelId) { export function createDraftOrder(customerId, shippingMethodId, channelId) {
const mutation = ` const mutation = `
mutation{ mutation{
draftOrderCreate(input:{ draftOrderCreate(input:{
@ -42,8 +41,8 @@ class Order {
} }
`; `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
completeOrder(orderId) { export function completeOrder(orderId) {
const mutation = `mutation{ const mutation = `mutation{
draftOrderComplete(id:"${orderId}"){ draftOrderComplete(id:"${orderId}"){
order{ order{
@ -55,6 +54,4 @@ class Order {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Order;

View file

@ -1,7 +1,6 @@
import { getValueWithDefault } from "./utils/Utils"; import { getValueWithDefault } from "./utils/Utils";
class Product { export function getFirstProducts(first, search) {
getFirstProducts(first, search) {
const filter = search const filter = search
? `, filter:{ ? `, filter:{
search:"${search}" search:"${search}"
@ -23,15 +22,15 @@ class Product {
return cy return cy
.sendRequestWithQuery(query) .sendRequestWithQuery(query)
.then(resp => resp.body.data.products.edges); .then(resp => resp.body.data.products.edges);
} }
updateChannelInProduct({ export function updateChannelInProduct({
productId, productId,
channelId, channelId,
isPublished = true, isPublished = true,
isAvailableForPurchase = true, isAvailableForPurchase = true,
visibleInListings = true visibleInListings = true
}) { }) {
const mutation = `mutation{ const mutation = `mutation{
productChannelListingUpdate(id:"${productId}", productChannelListingUpdate(id:"${productId}",
input:{ input:{
@ -49,9 +48,9 @@ class Product {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
updateChannelPriceInVariant(variantId, channelId) { export function updateChannelPriceInVariant(variantId, channelId) {
const mutation = `mutation{ const mutation = `mutation{
productVariantChannelListingUpdate(id: "${variantId}", input: { productVariantChannelListingUpdate(id: "${variantId}", input: {
channelId: "${channelId}" channelId: "${channelId}"
@ -64,8 +63,8 @@ class Product {
} }
} `; } `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
createProduct(attributeId, name, productType, category) { export function createProduct(attributeId, name, productType, category) {
const mutation = `mutation{ const mutation = `mutation{
productCreate(input:{ productCreate(input:{
attributes:[{ attributes:[{
@ -85,9 +84,9 @@ class Product {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
createVariant({ export function createVariant({
productId, productId,
sku, sku,
warehouseId, warehouseId,
@ -95,7 +94,7 @@ class Product {
channelId, channelId,
price = 1, price = 1,
costPrice = 1 costPrice = 1
}) { }) {
const channelListings = getValueWithDefault( const channelListings = getValueWithDefault(
channelId, channelId,
`channelListings:{ `channelListings:{
@ -131,9 +130,9 @@ class Product {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
createTypeProduct(name, attributeId, slug = name) { export function createTypeProduct(name, attributeId, slug = name) {
const mutation = `mutation{ const mutation = `mutation{
productTypeCreate(input: { productTypeCreate(input: {
name: "${name}" name: "${name}"
@ -152,9 +151,9 @@ class Product {
} }
} `; } `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
deleteProduct(productId) { export function deleteProduct(productId) {
const mutation = `mutation{ const mutation = `mutation{
productDelete(id: "${productId}"){ productDelete(id: "${productId}"){
productErrors{ productErrors{
@ -164,9 +163,9 @@ class Product {
} }
} `; } `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
getProductTypes(first, search) { export function getProductTypes(first, search) {
const query = `query{ const query = `query{
productTypes(first:${first}, filter:{ productTypes(first:${first}, filter:{
search:"${search}" search:"${search}"
@ -182,9 +181,9 @@ class Product {
return cy return cy
.sendRequestWithQuery(query) .sendRequestWithQuery(query)
.then(resp => resp.body.data.productTypes.edges); .then(resp => resp.body.data.productTypes.edges);
} }
deleteProductType(productTypeId) { export function deleteProductType(productTypeId) {
const mutation = `mutation{ const mutation = `mutation{
productTypeDelete(id:"${productTypeId}"){ productTypeDelete(id:"${productTypeId}"){
productErrors{ productErrors{
@ -194,7 +193,4 @@ class Product {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Product;

View file

@ -1,5 +1,4 @@
class ShippingMethod { export function createShippingRate(name, shippingZone) {
createShippingRate(name, shippingZone) {
const mutation = ` const mutation = `
mutation{ mutation{
shippingPriceCreate(input:{ shippingPriceCreate(input:{
@ -14,9 +13,9 @@ class ShippingMethod {
} }
`; `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
createShippingZone(name, country) { export function createShippingZone(name, country) {
const mutation = ` const mutation = `
mutation{ mutation{
shippingZoneCreate(input:{ shippingZoneCreate(input:{
@ -30,9 +29,9 @@ class ShippingMethod {
} }
`; `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
addChannelToShippingMethod(shippingRateId, channelId, price) { export function addChannelToShippingMethod(shippingRateId, channelId, price) {
const mutation = ` const mutation = `
mutation{ mutation{
shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{ shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{
@ -52,9 +51,9 @@ class ShippingMethod {
} }
`; `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
deleteShippingZone(shippingZoneId) { export function deleteShippingZone(shippingZoneId) {
const mutation = `mutation{ const mutation = `mutation{
shippingZoneDelete(id:"${shippingZoneId}"){ shippingZoneDelete(id:"${shippingZoneId}"){
shippingErrors{ shippingErrors{
@ -64,9 +63,9 @@ class ShippingMethod {
} }
`; `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
getShippingZones() { export function getShippingZones() {
const query = `query{ const query = `query{
shippingZones(first:100){ shippingZones(first:100){
edges{ edges{
@ -81,6 +80,4 @@ class ShippingMethod {
return cy return cy
.sendRequestWithQuery(query) .sendRequestWithQuery(query)
.then(resp => resp.body.data.shippingZones.edges); .then(resp => resp.body.data.shippingZones.edges);
}
} }
export default ShippingMethod;

View file

@ -1,5 +1,4 @@
class Warehouse { export function createWarehouse(name, shippingZone, address, slug = name) {
createWarehouse(name, shippingZone, address, slug = name) {
const mutation = `mutation{ const mutation = `mutation{
createWarehouse(input:{ createWarehouse(input:{
name:"${name}" name:"${name}"
@ -25,8 +24,8 @@ class Warehouse {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
getWarehouses(first, search) { export function getWarehouses(first, search) {
const query = `query{ const query = `query{
warehouses(first:${first}, filter:{ warehouses(first:${first}, filter:{
search:"${search}" search:"${search}"
@ -42,8 +41,8 @@ class Warehouse {
return cy return cy
.sendRequestWithQuery(query) .sendRequestWithQuery(query)
.then(resp => resp.body.data.warehouses.edges); .then(resp => resp.body.data.warehouses.edges);
} }
deleteWarehouse(warehouseId) { export function deleteWarehouse(warehouseId) {
const mutation = `mutation{ const mutation = `mutation{
deleteWarehouse(id:"${warehouseId}"){ deleteWarehouse(id:"${warehouseId}"){
warehouseErrors{ warehouseErrors{
@ -53,6 +52,4 @@ class Warehouse {
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Warehouse;

View file

@ -1,5 +1,4 @@
class Collections { export function getCollection(collectionId, channelSlug) {
getCollection(collectionId, channelSlug) {
const query = `query Collection{ const query = `query Collection{
collection(id: "${collectionId}", channel: "${channelSlug}") { collection(id: "${collectionId}", channel: "${channelSlug}") {
id id
@ -17,6 +16,4 @@ class Collections {
} }
}`; }`;
return cy.sendRequestWithQuery(query, "token"); return cy.sendRequestWithQuery(query, "token");
}
} }
export default Collections;

View file

@ -1,5 +1,4 @@
class ProductDetails { export function getProductDetails(productId, channelId) {
getProductDetails(productId, channelId) {
const query = `fragment BasicProductFields on Product { const query = `fragment BasicProductFields on Product {
id id
name name
@ -35,6 +34,4 @@ class ProductDetails {
} }
}`; }`;
return cy.sendRequestWithQuery(query, "token"); return cy.sendRequestWithQuery(query, "token");
}
} }
export default ProductDetails;

View file

@ -1,5 +1,4 @@
class Search { export function searchInShop(searchQuery) {
searchInShop(searchQuery) {
const query = `query SearchProducts { const query = `query SearchProducts {
products(channel: "default-channel", filter:{ products(channel: "default-channel", filter:{
search: "${searchQuery}" search: "${searchQuery}"
@ -15,6 +14,4 @@ class Search {
}`; }`;
return cy.sendRequestWithQuery(query, "token"); return cy.sendRequestWithQuery(query, "token");
}
} }
export default Search;

View file

@ -1,7 +1,7 @@
// <reference types="cypress" /> // <reference types="cypress" />
import faker from "faker"; import faker from "faker";
import Channels from "../apiRequests/Channels"; import { createChannel } from "../apiRequests/Channels";
import { LEFT_MENU_SELECTORS } from "../elements/account/left-menu/left-menu-selectors"; import { LEFT_MENU_SELECTORS } from "../elements/account/left-menu/left-menu-selectors";
import { PRODUCTS_SELECTORS } from "../elements/catalog/products/product-selectors"; import { PRODUCTS_SELECTORS } from "../elements/catalog/products/product-selectors";
import { ADD_CHANNEL_FORM_SELECTORS } from "../elements/channels/add-channel-form-selectors"; import { ADD_CHANNEL_FORM_SELECTORS } from "../elements/channels/add-channel-form-selectors";
@ -12,20 +12,17 @@ import { HEADER_SELECTORS } from "../elements/header/header-selectors";
import { DRAFT_ORDER_SELECTORS } from "../elements/orders/draft-order-selectors"; import { DRAFT_ORDER_SELECTORS } from "../elements/orders/draft-order-selectors";
import { ORDERS_SELECTORS } from "../elements/orders/orders-selectors"; import { ORDERS_SELECTORS } from "../elements/orders/orders-selectors";
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
import ChannelsSteps from "../steps/channelsSteps"; import { createChannelByView } from "../steps/channelsSteps";
import { urlList } from "../url/urlList"; import { urlList } from "../url/urlList";
import ChannelsUtils from "../utils/channelsUtils"; import { deleteChannelsStartsWith } from "../utils/channelsUtils";
describe("Channels", () => { describe("Channels", () => {
const channelStartsWith = "Cypress:"; const channelStartsWith = "Cypress:";
const currency = "PLN"; const currency = "PLN";
const channels = new Channels();
const channelsUtils = new ChannelsUtils();
const channelsSteps = new ChannelsSteps();
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
channelsUtils.deleteChannels(channelStartsWith); deleteChannelsStartsWith(channelStartsWith);
}); });
beforeEach(() => { beforeEach(() => {
@ -48,7 +45,7 @@ describe("Channels", () => {
cy.visit(urlList.channels); cy.visit(urlList.channels);
cy.wait("@Channels"); cy.wait("@Channels");
cy.addAliasToGraphRequest("Channel"); cy.addAliasToGraphRequest("Channel");
channelsSteps.createChannelByView(randomChannel, currency); createChannelByView(randomChannel, currency);
// New channel should be visible in channels list // New channel should be visible in channels list
cy.wait("@Channel") cy.wait("@Channel")
.get(ADD_CHANNEL_FORM_SELECTORS.backToChannelsList) .get(ADD_CHANNEL_FORM_SELECTORS.backToChannelsList)
@ -79,22 +76,18 @@ describe("Channels", () => {
it("should validate slug name", () => { it("should validate slug name", () => {
const randomChannel = `${channelStartsWith} ${faker.random.number()}`; const randomChannel = `${channelStartsWith} ${faker.random.number()}`;
channels.createChannel(false, randomChannel, randomChannel, currency); createChannel(false, randomChannel, randomChannel, currency);
cy.visit(urlList.channels); cy.visit(urlList.channels);
channelsSteps.createChannelByView(randomChannel, currency); createChannelByView(randomChannel, currency);
cy.get(ADD_CHANNEL_FORM_SELECTORS.slugValidationMessage).should( cy.get(ADD_CHANNEL_FORM_SELECTORS.slugValidationMessage).should(
"be.visible" "be.visible"
); );
}); });
it("should validate currency", () => { it("should validate duplicated currency", () => {
const randomChannel = `${channelStartsWith} ${faker.random.number()}`; const randomChannel = `${channelStartsWith} ${faker.random.number()}`;
cy.visit(urlList.channels); cy.visit(urlList.channels);
channelsSteps.createChannelByView( createChannelByView(randomChannel, "notExistingCurrency");
randomChannel,
currency,
"notExistingCurrency"
);
cy.get(ADD_CHANNEL_FORM_SELECTORS.currencyValidationMessage).should( cy.get(ADD_CHANNEL_FORM_SELECTORS.currencyValidationMessage).should(
"be.visible" "be.visible"
); );
@ -102,7 +95,7 @@ describe("Channels", () => {
it("should delete channel", () => { it("should delete channel", () => {
const randomChannelToDelete = `${channelStartsWith} ${faker.random.number()}`; const randomChannelToDelete = `${channelStartsWith} ${faker.random.number()}`;
channels.createChannel( createChannel(
false, false,
randomChannelToDelete, randomChannelToDelete,
randomChannelToDelete, randomChannelToDelete,
@ -126,7 +119,7 @@ describe("Channels", () => {
it("should not be possible to add products to order with inactive channel", () => { it("should not be possible to add products to order with inactive channel", () => {
const randomChannel = `${channelStartsWith} ${faker.random.number()}`; const randomChannel = `${channelStartsWith} ${faker.random.number()}`;
channels.createChannel(false, randomChannel, randomChannel, currency); createChannel(false, randomChannel, randomChannel, currency);
cy.visit(urlList.orders) cy.visit(urlList.orders)
.get(ORDERS_SELECTORS.createOrder) .get(ORDERS_SELECTORS.createOrder)
.click() .click()

View file

@ -1,15 +1,18 @@
// <reference types="cypress" /> // <reference types="cypress" />
import faker from "faker"; import faker from "faker";
import Product from "../apiRequests/Product"; import { updateChannelInProduct } from "../apiRequests/Product";
import Collections from "../apiRequests/storeFront/Collections"; import { getCollection } from "../apiRequests/storeFront/Collections";
import Search from "../apiRequests/storeFront/Search"; import { searchInShop } from "../apiRequests/storeFront/Search";
import CollectionsSteps from "../steps/collectionsSteps"; import {
assignProductsToCollection,
createCollection
} from "../steps/collectionsSteps";
import { urlList } from "../url/urlList"; import { urlList } from "../url/urlList";
import ChannelsUtils from "../utils/channelsUtils"; import * as channelsUtils from "../utils/channelsUtils";
import CollectionsUtils from "../utils/collectionsUtils"; import { deleteCollectionsStartsWith } from "../utils/collectionsUtils";
import ProductsUtils from "../utils/productsUtils"; import * as productsUtils from "../utils/productsUtils";
import ShippingUtils from "../utils/shippingUtils"; import { deleteShippingStartsWith } from "../utils/shippingUtils";
import { import {
isCollectionVisible, isCollectionVisible,
isProductInCollectionVisible isProductInCollectionVisible
@ -17,29 +20,21 @@ import {
import { isProductVisibleInSearchResult } from "../utils/storeFront/storeFrontProductUtils"; import { isProductVisibleInSearchResult } from "../utils/storeFront/storeFrontProductUtils";
describe("Collections", () => { 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();
const shippingUtils = new ShippingUtils();
const collectionsSteps = new CollectionsSteps();
const startsWith = "Cy-"; const startsWith = "Cy-";
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
let attribute; let attribute;
let productType; let productType;
let category; let category;
let product;
let defaultChannel; let defaultChannel;
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
productsUtils.deleteProperProducts(startsWith); productsUtils.deleteProductsStartsWith(startsWith);
collectionsUtils.deleteProperCollections(startsWith); deleteCollectionsStartsWith(startsWith);
shippingUtils.deleteShipping(startsWith); deleteShippingStartsWith(startsWith);
channelsUtils channelsUtils
.getDefaultChannel() .getDefaultChannel()
@ -47,10 +42,15 @@ describe("Collections", () => {
defaultChannel = channel; defaultChannel = channel;
productsUtils.createTypeAttributeAndCategoryForProduct(name); productsUtils.createTypeAttributeAndCategoryForProduct(name);
}) })
.then(() => { .then(
attribute = productsUtils.getAttribute(); ({
productType = productsUtils.getProductType(); attribute: attributeResp,
category = productsUtils.getCategory(); productType: productTypeResp,
category: categoryResp
}) => {
attribute = attributeResp;
productType = productTypeResp;
category = categoryResp;
productsUtils.createProductInChannel({ productsUtils.createProductInChannel({
name, name,
channelId: defaultChannel.id, channelId: defaultChannel.id,
@ -58,7 +58,9 @@ describe("Collections", () => {
attributeId: attribute.id, attributeId: attribute.id,
categoryId: category.id categoryId: category.id
}); });
}); }
)
.then(({ product: productResp }) => (product = productResp));
}); });
beforeEach(() => { beforeEach(() => {
@ -70,14 +72,13 @@ describe("Collections", () => {
cy.visit(urlList.collections); cy.visit(urlList.collections);
let collection; let collection;
collectionsSteps createCollection(collectionName, false, defaultChannel)
.createCollection(collectionName, false, defaultChannel)
.then(collectionResp => { .then(collectionResp => {
collection = collectionResp; collection = collectionResp;
collectionsSteps.assignProductsToCollection(name); assignProductsToCollection(name);
}) })
.then(() => { .then(() => {
collectionsRequest.getCollection(collection.id, defaultChannel.slug); getCollection(collection.id, defaultChannel.slug);
}) })
.then(resp => { .then(resp => {
const isVisible = isCollectionVisible(resp, collection.id); const isVisible = isCollectionVisible(resp, collection.id);
@ -89,12 +90,12 @@ describe("Collections", () => {
const collectionName = `${startsWith}${faker.random.number()}`; const collectionName = `${startsWith}${faker.random.number()}`;
let collection; let collection;
cy.visit(urlList.collections); cy.visit(urlList.collections);
collectionsSteps
.createCollection(collectionName, true, defaultChannel) createCollection(collectionName, true, defaultChannel)
.then(collectionResp => { .then(collectionResp => {
collection = collectionResp; collection = collectionResp;
collectionsSteps.assignProductsToCollection(name); assignProductsToCollection(name);
collectionsRequest.getCollection(collection.id, defaultChannel.slug); getCollection(collection.id, defaultChannel.slug);
}) })
.then(resp => { .then(resp => {
const isVisible = isCollectionVisible(resp, collection.id); const isVisible = isCollectionVisible(resp, collection.id);
@ -104,27 +105,22 @@ describe("Collections", () => {
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; let collection;
let channel;
channelsUtils channelsUtils
.createChannel({ name: collectionName }) .createChannel({ name: collectionName })
.then(() => { .then(channelResp => {
productRequest.updateChannelInProduct( channel = channelResp;
productsUtils.getCreatedProduct().id, updateChannelInProduct(product.id, channel.id);
channelsUtils.getCreatedChannel().id
);
}) })
.then(() => { .then(() => {
cy.visit(urlList.collections); cy.visit(urlList.collections);
collectionsSteps.createCollection( createCollection(collectionName, true, channel);
collectionName,
true,
channelsUtils.getCreatedChannel()
);
}) })
.then(collectionResp => { .then(collectionResp => {
collection = collectionResp; collection = collectionResp;
collectionsSteps.assignProductsToCollection(name); assignProductsToCollection(name);
collectionsRequest.getCollection(collection.id, defaultChannel.slug); getCollection(collection.id, defaultChannel.slug);
}) })
.then(resp => { .then(resp => {
const isVisible = isCollectionVisible(resp, collection.id); const isVisible = isCollectionVisible(resp, collection.id);
@ -135,41 +131,39 @@ describe("Collections", () => {
// 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,
// but are listed on Collections // but are listed on Collections
const randomName = `${startsWith}${faker.random.number()}`; const randomName = `${startsWith}${faker.random.number()}`;
const hiddenProductUtils = new ProductsUtils();
let collection; let collection;
let createdProduct;
hiddenProductUtils.createProductInChannel({ productsUtils
.createProductInChannel({
name: randomName, name: randomName,
channelId: defaultChannel.id, channelId: defaultChannel.id,
productTypeId: productType.id, productTypeId: productType.id,
attributeId: attribute.id, attributeId: attribute.id,
categoryId: category.id, categoryId: category.id,
visibleInListings: false visibleInListings: false
}); })
.then(({ product: productResp }) => (createdProduct = productResp));
cy.visit(urlList.collections); cy.visit(urlList.collections);
collectionsSteps createCollection(randomName, true, defaultChannel)
.createCollection(randomName, true, defaultChannel)
.then(collectionResp => { .then(collectionResp => {
collection = collectionResp; collection = collectionResp;
collectionsSteps.assignProductsToCollection(randomName); assignProductsToCollection(randomName);
}) })
.then(() => { .then(() => {
collectionsRequest.getCollection(collection.id, defaultChannel.slug); getCollection(collection.id, defaultChannel.slug);
}) })
.then(resp => { .then(resp => {
const isVisible = isProductInCollectionVisible( const isVisible = isProductInCollectionVisible(resp, createdProduct.id);
resp,
hiddenProductUtils.getCreatedProduct().id
);
expect(isVisible).to.equal(true); expect(isVisible).to.equal(true);
}) })
.then(() => { .then(() => {
search.searchInShop(hiddenProductUtils.getCreatedProduct().name); searchInShop(createdProduct.name);
}) })
.then(resp => { .then(resp => {
const isVisible = isProductVisibleInSearchResult( const isVisible = isProductVisibleInSearchResult(
resp, resp,
hiddenProductUtils.getCreatedProduct().name createdProduct.name
); );
expect(isVisible).to.equal(false); expect(isVisible).to.equal(false);
}); });

View file

@ -1,29 +1,31 @@
import faker from "faker"; import faker from "faker";
import Customer from "../apiRequests/Customer"; import { createCustomer, deleteCustomers } from "../apiRequests/Customer";
import { HOMEPAGE_SELECTORS } from "../elements/homePage/homePage-selectors"; import { HOMEPAGE_SELECTORS } from "../elements/homePage/homePage-selectors";
import HomePageSteps from "../steps/homePageSteps"; import { changeChannel } from "../steps/homePageSteps";
import { urlList } from "../url/urlList"; import { urlList } from "../url/urlList";
import ChannelsUtils from "../utils/channelsUtils"; import { getDefaultChannel } from "../utils/channelsUtils";
import HomePageUtils from "../utils/homePageUtils"; import * as homePageUtils from "../utils/homePageUtils";
import OrdersUtils from "../utils/ordersUtils"; import {
import ProductsUtils from "../utils/productsUtils"; createReadyToFulfillOrder,
import ShippingUtils from "../utils/shippingUtils"; createWaitingForCaptureOrder
} from "../utils/ordersUtils";
import * as productsUtils from "../utils/productsUtils";
import * as shippingUtils from "../utils/shippingUtils";
// <reference types="cypress" /> // <reference types="cypress" />
describe("Homepage analytics", () => { describe("Homepage analytics", () => {
const startsWith = "Cy-"; const startsWith = "Cy-";
const customer = new Customer();
const productsUtils = new ProductsUtils();
const shippingUtils = new ShippingUtils();
const ordersUtils = new OrdersUtils();
const channelsUtils = new ChannelsUtils();
const homePageUtils = new HomePageUtils();
const homePageSteps = new HomePageSteps();
let customerId; let customerId;
let defaultChannel; let defaultChannel;
let createdVariants;
let productType;
let attribute;
let category;
let warehouse;
let shippingMethod;
const productPrice = 22; const productPrice = 22;
const shippingPrice = 12; const shippingPrice = 12;
const randomName = startsWith + faker.random.number(); const randomName = startsWith + faker.random.number();
@ -31,21 +33,18 @@ describe("Homepage analytics", () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
productsUtils.deleteProperProducts(startsWith); productsUtils.deleteProductsStartsWith(startsWith);
customer.deleteCustomers(startsWith); deleteCustomers(startsWith);
shippingUtils.deleteShipping(startsWith); shippingUtils.deleteShippingStartsWith(startsWith);
let addresses; let addresses;
channelsUtils getDefaultChannel()
.getDefaultChannel()
.then(channel => { .then(channel => {
defaultChannel = channel; defaultChannel = channel;
cy.fixture("addresses"); cy.fixture("addresses");
}) })
.then(addressesFixture => (addresses = addressesFixture)) .then(addressesFixture => (addresses = addressesFixture))
.then(() => .then(() => createCustomer(randomEmail, randomName, addresses.plAddress))
customer.createCustomer(randomEmail, randomName, addresses.plAddress)
)
.then(resp => { .then(resp => {
customerId = resp.body.data.customerCreate.user.id; customerId = resp.body.data.customerCreate.user.id;
shippingUtils.createShipping({ shippingUtils.createShipping({
@ -55,14 +54,22 @@ describe("Homepage analytics", () => {
price: shippingPrice price: shippingPrice
}); });
}) })
.then(() => { .then(
({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => {
warehouse = warehouseResp;
shippingMethod = shippingMethodResp;
productsUtils.createTypeAttributeAndCategoryForProduct(randomName); productsUtils.createTypeAttributeAndCategoryForProduct(randomName);
}) }
.then(() => { )
const warehouse = shippingUtils.getWarehouse(); .then(
const productType = productsUtils.getProductType(); ({
const attribute = productsUtils.getAttribute(); productType: productTypeResp,
const category = productsUtils.getCategory(); attribute: attributeResp,
category: categoryResp
}) => {
productType = productTypeResp;
attribute = attributeResp;
category = categoryResp;
productsUtils.createProductInChannel({ productsUtils.createProductInChannel({
name: randomName, name: randomName,
channelId: defaultChannel.id, channelId: defaultChannel.id,
@ -73,6 +80,10 @@ describe("Homepage analytics", () => {
categoryId: category.id, categoryId: category.id,
price: productPrice price: productPrice
}); });
}
)
.then(({ variants: variantsResp }) => {
createdVariants = variantsResp;
}); });
}); });
@ -96,11 +107,11 @@ describe("Homepage analytics", () => {
.getOrdersReadyToFulfill(defaultChannel.slug) .getOrdersReadyToFulfill(defaultChannel.slug)
.as("ordersReadyToFulfill"); .as("ordersReadyToFulfill");
ordersUtils.createReadyToFulfillOrder( createReadyToFulfillOrder(
customerId, customerId,
shippingUtils.getShippingMethod().id, shippingMethod.id,
defaultChannel.id, defaultChannel.id,
productsUtils.getCreatedVariants() createdVariants
); );
cy.get("@ordersReadyToFulfill").then(ordersReadyToFulfillBefore => { cy.get("@ordersReadyToFulfill").then(ordersReadyToFulfillBefore => {
const allOrdersReadyToFulfill = ordersReadyToFulfillBefore + 1; const allOrdersReadyToFulfill = ordersReadyToFulfillBefore + 1;
@ -109,7 +120,7 @@ describe("Homepage analytics", () => {
`${notANumberRegex}${allOrdersReadyToFulfill}${notANumberRegex}` `${notANumberRegex}${allOrdersReadyToFulfill}${notANumberRegex}`
); );
cy.visit(urlList.homePage); cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name); changeChannel(defaultChannel.name);
cy.contains( cy.contains(
HOMEPAGE_SELECTORS.ordersReadyToFulfill, HOMEPAGE_SELECTORS.ordersReadyToFulfill,
ordersReadyToFulfillRegexp ordersReadyToFulfillRegexp
@ -120,13 +131,12 @@ describe("Homepage analytics", () => {
homePageUtils homePageUtils
.getOrdersReadyForCapture(defaultChannel.slug) .getOrdersReadyForCapture(defaultChannel.slug)
.as("ordersReadyForCapture"); .as("ordersReadyForCapture");
const variantsList = productsUtils.getCreatedVariants();
ordersUtils.createWaitingForCaptureOrder( createWaitingForCaptureOrder(
defaultChannel.slug, defaultChannel.slug,
randomEmail, randomEmail,
variantsList, createdVariants,
shippingUtils.getShippingMethod().id shippingMethod.id
); );
cy.get("@ordersReadyForCapture").then(ordersReadyForCaptureBefore => { cy.get("@ordersReadyForCapture").then(ordersReadyForCaptureBefore => {
@ -136,7 +146,7 @@ describe("Homepage analytics", () => {
`${notANumberRegex}${allOrdersReadyForCapture}${notANumberRegex}` `${notANumberRegex}${allOrdersReadyForCapture}${notANumberRegex}`
); );
cy.visit(urlList.homePage); cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name); changeChannel(defaultChannel.name);
cy.contains( cy.contains(
HOMEPAGE_SELECTORS.ordersReadyForCapture, HOMEPAGE_SELECTORS.ordersReadyForCapture,
ordersReadyForCaptureRegexp ordersReadyForCaptureRegexp
@ -148,13 +158,8 @@ describe("Homepage analytics", () => {
.getProductsOutOfStock(defaultChannel.slug) .getProductsOutOfStock(defaultChannel.slug)
.as("productsOutOfStock"); .as("productsOutOfStock");
const productOutOfStockRandomName = startsWith + faker.random.number(); const productOutOfStockRandomName = startsWith + faker.random.number();
const productsOutOfStockUtils = new ProductsUtils();
const warehouse = shippingUtils.getWarehouse();
const productType = productsUtils.getProductType();
const attribute = productsUtils.getAttribute();
const category = productsUtils.getCategory();
productsOutOfStockUtils.createProductInChannel({ productsUtils.createProductInChannel({
name: productOutOfStockRandomName, name: productOutOfStockRandomName,
channelId: defaultChannel.id, channelId: defaultChannel.id,
warehouseId: warehouse.id, warehouseId: warehouse.id,
@ -172,7 +177,7 @@ describe("Homepage analytics", () => {
`${notANumberRegex}${allProductsOutOfStock}${notANumberRegex}` `${notANumberRegex}${allProductsOutOfStock}${notANumberRegex}`
); );
cy.visit(urlList.homePage); cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name); changeChannel(defaultChannel.name);
cy.contains( cy.contains(
HOMEPAGE_SELECTORS.productsOutOfStock, HOMEPAGE_SELECTORS.productsOutOfStock,
productsOutOfStockRegexp productsOutOfStockRegexp
@ -182,11 +187,11 @@ describe("Homepage analytics", () => {
it("should correct amount of sales be displayed", () => { it("should correct amount of sales be displayed", () => {
homePageUtils.getSalesAmount(defaultChannel.slug).as("salesAmount"); homePageUtils.getSalesAmount(defaultChannel.slug).as("salesAmount");
ordersUtils.createReadyToFulfillOrder( createReadyToFulfillOrder(
customerId, customerId,
shippingUtils.getShippingMethod().id, shippingMethod.id,
defaultChannel.id, defaultChannel.id,
productsUtils.getCreatedVariants() createdVariants
); );
cy.get("@salesAmount").then(salesAmount => { cy.get("@salesAmount").then(salesAmount => {
@ -205,7 +210,7 @@ describe("Homepage analytics", () => {
`${notANumberRegex}${totalAmountWithSeparators}${notANumberRegex}` `${notANumberRegex}${totalAmountWithSeparators}${notANumberRegex}`
); );
cy.visit(urlList.homePage); cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name); changeChannel(defaultChannel.name);
cy.contains(HOMEPAGE_SELECTORS.sales, salesAmountRegexp).should( cy.contains(HOMEPAGE_SELECTORS.sales, salesAmountRegexp).should(
"be.visible" "be.visible"
); );
@ -214,11 +219,11 @@ describe("Homepage analytics", () => {
it("should correct amount of orders be displayed", () => { it("should correct amount of orders be displayed", () => {
homePageUtils.getTodaysOrders(defaultChannel.slug).as("todaysOrders"); homePageUtils.getTodaysOrders(defaultChannel.slug).as("todaysOrders");
ordersUtils.createReadyToFulfillOrder( createReadyToFulfillOrder(
customerId, customerId,
shippingUtils.getShippingMethod().id, shippingMethod.id,
defaultChannel.id, defaultChannel.id,
productsUtils.getCreatedVariants() createdVariants
); );
cy.get("@todaysOrders").then(ordersBefore => { cy.get("@todaysOrders").then(ordersBefore => {
@ -228,7 +233,7 @@ describe("Homepage analytics", () => {
`${notANumberRegex}${allOrders}${notANumberRegex}` `${notANumberRegex}${allOrders}${notANumberRegex}`
); );
cy.visit(urlList.homePage); cy.visit(urlList.homePage);
homePageSteps.changeChannel(defaultChannel.name); changeChannel(defaultChannel.name);
cy.contains(HOMEPAGE_SELECTORS.orders, ordersRegexp).should("be.visible"); cy.contains(HOMEPAGE_SELECTORS.orders, ordersRegexp).should("be.visible");
}); });
}); });

View file

@ -1,20 +1,15 @@
import faker from "faker"; import faker from "faker";
import ProductDetails from "../../../apiRequests/storeFront/ProductDetails"; import { getProductDetails } from "../../../apiRequests/storeFront/ProductDetails";
import ProductSteps from "../../../steps/products/productSteps"; import { updateProductIsAvailableForPurchase } from "../../../steps/products/productSteps";
import { productDetailsUrl } from "../../../url/urlList"; import { productDetailsUrl } from "../../../url/urlList";
import ChannelsUtils from "../../../utils/channelsUtils"; import { getDefaultChannel } from "../../../utils/channelsUtils";
import ProductsUtils from "../../../utils/productsUtils"; import * as productsUtils from "../../../utils/productsUtils";
import ShippingUtils from "../../../utils/shippingUtils"; import * as shippingUtils from "../../../utils/shippingUtils";
import { isProductAvailableForPurchase } from "../../../utils/storeFront/storeFrontProductUtils"; import { isProductAvailableForPurchase } from "../../../utils/storeFront/storeFrontProductUtils";
// <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 channelsUtils = new ChannelsUtils();
const productsUtils = new ProductsUtils();
const productSteps = new ProductSteps();
const startsWith = "Cy-"; const startsWith = "Cy-";
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
let productType; let productType;
@ -25,11 +20,10 @@ describe("Products available in listings", () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
shippingUtils.deleteShipping(startsWith); shippingUtils.deleteShippingStartsWith(startsWith);
productsUtils.deleteProperProducts(startsWith); productsUtils.deleteProductsStartsWith(startsWith);
channelsUtils getDefaultChannel()
.getDefaultChannel()
.then(channel => { .then(channel => {
defaultChannel = channel; defaultChannel = channel;
cy.fixture("addresses"); cy.fixture("addresses");
@ -41,15 +35,23 @@ describe("Products available in listings", () => {
address: addressesFixture.plAddress address: addressesFixture.plAddress
}); });
}) })
.then(() => { .then(({ warehouse: warehouseResp }) => {
warehouse = shippingUtils.getWarehouse(); warehouse = warehouseResp;
}); });
productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => { productsUtils
productType = productsUtils.getProductType(); .createTypeAttributeAndCategoryForProduct(name)
attribute = productsUtils.getAttribute(); .then(
category = productsUtils.getCategory(); ({
}); attribute: attributeResp,
productType: productTypeResp,
category: categoryResp
}) => {
productType = productTypeResp;
attribute = attributeResp;
category = categoryResp;
}
);
}); });
beforeEach(() => { beforeEach(() => {
@ -58,6 +60,8 @@ describe("Products available in listings", () => {
it("should update product to available for purchase", () => { it("should update product to available for purchase", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
let product;
productsUtils productsUtils
.createProductInChannel({ .createProductInChannel({
name: productName, name: productName,
@ -68,17 +72,13 @@ describe("Products available in listings", () => {
categoryId: category.id, categoryId: category.id,
isAvailableForPurchase: false isAvailableForPurchase: false
}) })
.then(() => { .then(({ product: productResp }) => {
const productUrl = productDetailsUrl( product = productResp;
productsUtils.getCreatedProduct().id const productUrl = productDetailsUrl(product.id);
); updateProductIsAvailableForPurchase(productUrl, true);
productSteps.updateProductIsAvailableForPurchase(productUrl, true);
}) })
.then(() => { .then(() => {
productDetails.getProductDetails( getProductDetails(product.id, defaultChannel.slug);
productsUtils.getCreatedProduct().id,
defaultChannel.slug
);
}) })
.then(resp => { .then(resp => {
expect(isProductAvailableForPurchase(resp)).to.be.eq(true); expect(isProductAvailableForPurchase(resp)).to.be.eq(true);
@ -86,6 +86,8 @@ describe("Products available in listings", () => {
}); });
it("should update product to not available for purchase", () => { it("should update product to not available for purchase", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
let product;
productsUtils productsUtils
.createProductInChannel({ .createProductInChannel({
name: productName, name: productName,
@ -95,17 +97,13 @@ describe("Products available in listings", () => {
attributeId: attribute.id, attributeId: attribute.id,
categoryId: category.id categoryId: category.id
}) })
.then(() => { .then(({ product: productResp }) => {
const productUrl = productDetailsUrl( product = productResp;
productsUtils.getCreatedProduct().id const productUrl = productDetailsUrl(product.id);
); updateProductIsAvailableForPurchase(productUrl, false);
productSteps.updateProductIsAvailableForPurchase(productUrl, false);
}) })
.then(() => { .then(() => {
productDetails.getProductDetails( getProductDetails(product.id, defaultChannel.slug);
productsUtils.getCreatedProduct().id,
defaultChannel.slug
);
}) })
.then(resp => { .then(resp => {
expect(isProductAvailableForPurchase(resp)).to.be.eq(false); expect(isProductAvailableForPurchase(resp)).to.be.eq(false);

View file

@ -1,19 +1,14 @@
import faker from "faker"; import faker from "faker";
import ProductDetails from "../../../apiRequests/storeFront/ProductDetails"; import { getProductDetails } from "../../../apiRequests/storeFront/ProductDetails";
import ProductSteps from "../../../steps/products/productSteps"; import { updateProductPublish } from "../../../steps/products/productSteps";
import { productDetailsUrl } from "../../../url/urlList"; import { productDetailsUrl } from "../../../url/urlList";
import ChannelsUtils from "../../../utils/channelsUtils"; import { getDefaultChannel } from "../../../utils/channelsUtils";
import ProductsUtils from "../../../utils/productsUtils"; import * as productsUtils from "../../../utils/productsUtils";
import { isProductVisible } from "../../../utils/storeFront/storeFrontProductUtils"; import { isProductVisible } from "../../../utils/storeFront/storeFrontProductUtils";
// <reference types="cypress" /> // <reference types="cypress" />
describe("Published products", () => { describe("Published products", () => {
const productDetails = new ProductDetails();
const channelsUtils = new ChannelsUtils();
const productsUtils = new ProductsUtils();
const productSteps = new ProductSteps();
const startsWith = "Cy-"; const startsWith = "Cy-";
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
let productType; let productType;
@ -22,12 +17,20 @@ describe("Published products", () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
productsUtils.deleteProperProducts(startsWith); productsUtils.deleteProductsStartsWith(startsWith);
productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => { productsUtils
productType = productsUtils.getProductType(); .createTypeAttributeAndCategoryForProduct(name)
attribute = productsUtils.getAttribute(); .then(
category = productsUtils.getCategory(); ({
}); attribute: attributeResp,
productType: productTypeResp,
category: categoryResp
}) => {
productType = productTypeResp;
attribute = attributeResp;
category = categoryResp;
}
);
}); });
beforeEach(() => { beforeEach(() => {
@ -36,8 +39,7 @@ describe("Published products", () => {
it("should update product to published", () => { it("should update product to published", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
let defaultChannel; let defaultChannel;
channelsUtils getDefaultChannel()
.getDefaultChannel()
.then(channel => { .then(channel => {
defaultChannel = channel; defaultChannel = channel;
productsUtils.createProductInChannel({ productsUtils.createProductInChannel({
@ -50,11 +52,11 @@ describe("Published products", () => {
isAvailableForPurchase: false isAvailableForPurchase: false
}); });
}) })
.then(() => { .then(({ product: productResp }) => {
const product = productsUtils.getCreatedProduct(); const product = productResp;
const productUrl = productDetailsUrl(product.id); const productUrl = productDetailsUrl(product.id);
productSteps.updateProductPublish(productUrl, true); updateProductPublish(productUrl, true);
productDetails.getProductDetails(product.id, defaultChannel.slug); getProductDetails(product.id, defaultChannel.slug);
}) })
.then(resp => { .then(resp => {
const isVisible = isProductVisible(resp, productName); const isVisible = isProductVisible(resp, productName);
@ -66,8 +68,7 @@ describe("Published products", () => {
let defaultChannel; let defaultChannel;
let product; let product;
channelsUtils getDefaultChannel()
.getDefaultChannel()
.then(channel => { .then(channel => {
defaultChannel = channel; defaultChannel = channel;
productsUtils.createProductInChannel({ productsUtils.createProductInChannel({
@ -78,11 +79,11 @@ describe("Published products", () => {
categoryId: category.id categoryId: category.id
}); });
}) })
.then(() => { .then(({ product: productResp }) => {
product = productsUtils.getCreatedProduct(); product = productResp;
const productUrl = productDetailsUrl(product.id); const productUrl = productDetailsUrl(product.id);
productSteps.updateProductPublish(productUrl, false); updateProductPublish(productUrl, false);
productDetails.getProductDetails(product.id, defaultChannel.slug); getProductDetails(product.id, defaultChannel.slug);
}) })
.then(resp => { .then(resp => {
const isVisible = isProductVisible(resp, productName); const isVisible = isProductVisible(resp, productName);
@ -90,7 +91,7 @@ describe("Published products", () => {
cy.loginInShop(); cy.loginInShop();
}) })
.then(() => { .then(() => {
productDetails.getProductDetails(product.id, defaultChannel.slug); getProductDetails(product.id, defaultChannel.slug);
}) })
.then(resp => { .then(resp => {
const isVisible = isProductVisible(resp, productName); const isVisible = isProductVisible(resp, productName);

View file

@ -1,19 +1,14 @@
import faker from "faker"; import faker from "faker";
import Search from "../../../apiRequests/storeFront/Search"; import { searchInShop } from "../../../apiRequests/storeFront/Search";
import ProductSteps from "../../../steps/products/productSteps"; import { updateProductVisibleInListings } from "../../../steps/products/productSteps";
import { productDetailsUrl } from "../../../url/urlList"; import { productDetailsUrl } from "../../../url/urlList";
import ChannelsUtils from "../../../utils/channelsUtils"; import { getDefaultChannel } from "../../../utils/channelsUtils";
import ProductsUtils from "../../../utils/productsUtils"; import * as productsUtils from "../../../utils/productsUtils";
import { isProductVisibleInSearchResult } from "../../../utils/storeFront/storeFrontProductUtils"; import { isProductVisibleInSearchResult } from "../../../utils/storeFront/storeFrontProductUtils";
// <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 productsUtils = new ProductsUtils();
const productSteps = new ProductSteps();
const startsWith = "Cy-"; const startsWith = "Cy-";
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
let productType; let productType;
@ -22,12 +17,20 @@ describe("Products displayed in listings", () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
productsUtils.deleteProperProducts(startsWith); productsUtils.deleteProductsStartsWith(startsWith);
productsUtils.createTypeAttributeAndCategoryForProduct(name).then(() => { productsUtils
productType = productsUtils.getProductType(); .createTypeAttributeAndCategoryForProduct(name)
attribute = productsUtils.getAttribute(); .then(
category = productsUtils.getCategory(); ({
}); attribute: attributeResp,
productType: productTypeResp,
category: categoryResp
}) => {
productType = productTypeResp;
attribute = attributeResp;
category = categoryResp;
}
);
}); });
beforeEach(() => { beforeEach(() => {
@ -36,8 +39,7 @@ describe("Products displayed in listings", () => {
it("should update product to visible in listings", () => { it("should update product to visible in listings", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
let defaultChannel; let defaultChannel;
channelsUtils getDefaultChannel()
.getDefaultChannel()
.then(channel => { .then(channel => {
defaultChannel = channel; defaultChannel = channel;
productsUtils.createProductInChannel({ productsUtils.createProductInChannel({
@ -50,11 +52,11 @@ describe("Products displayed in listings", () => {
isAvailableForPurchase: false isAvailableForPurchase: false
}); });
}) })
.then(() => { .then(({ product: productResp }) => {
const product = productsUtils.getCreatedProduct(); const product = productResp;
const productUrl = productDetailsUrl(product.id); const productUrl = productDetailsUrl(product.id);
productSteps.updateProductVisibleInListings(productUrl); updateProductVisibleInListings(productUrl);
search.searchInShop(productName); searchInShop(productName);
}) })
.then(resp => { .then(resp => {
const isProductVisible = isProductVisibleInSearchResult( const isProductVisible = isProductVisibleInSearchResult(
@ -67,8 +69,7 @@ describe("Products displayed in listings", () => {
it("should update product to not visible in listings", () => { it("should update product to not visible in listings", () => {
const productName = `${startsWith}${faker.random.number()}`; const productName = `${startsWith}${faker.random.number()}`;
let defaultChannel; let defaultChannel;
channelsUtils getDefaultChannel()
.getDefaultChannel()
.then(channel => { .then(channel => {
defaultChannel = channel; defaultChannel = channel;
productsUtils.createProductInChannel({ productsUtils.createProductInChannel({
@ -80,12 +81,12 @@ describe("Products displayed in listings", () => {
visibleInListings: true visibleInListings: true
}); });
}) })
.then(() => { .then(({ product: productResp }) => {
const product = productsUtils.getCreatedProduct(); const product = productResp;
const productUrl = productDetailsUrl(product.id); const productUrl = productDetailsUrl(product.id);
productSteps.updateProductVisibleInListings(productUrl); updateProductVisibleInListings(productUrl);
search.searchInShop(productName).then(resp => { searchInShop(productName).then(resp => {
const isProductVisible = isProductVisibleInSearchResult( const isProductVisible = isProductVisibleInSearchResult(
resp, resp,
productName productName
@ -95,7 +96,7 @@ describe("Products displayed in listings", () => {
cy.loginInShop(); cy.loginInShop();
}) })
.then(() => { .then(() => {
search.searchInShop(productName); searchInShop(productName);
}) })
.then(resp => { .then(resp => {
const isProductVisible = isProductVisibleInSearchResult( const isProductVisible = isProductVisibleInSearchResult(

View file

@ -1,27 +1,28 @@
import faker from "faker"; import faker from "faker";
import Channels from "../../apiRequests/Channels"; import { createChannel } from "../../apiRequests/Channels";
import Product from "../../apiRequests/Product"; import {
import VariantsSteps from "../../steps/products/VariantsSteps"; createProduct,
updateChannelInProduct
} from "../../apiRequests/Product";
import {
createFirstVariant,
createVariant
} from "../../steps/products/VariantsSteps";
import { urlList } from "../../url/urlList"; import { urlList } from "../../url/urlList";
import ChannelsUtils from "../../utils/channelsUtils"; import {
import ProductsUtils from "../../utils/productsUtils"; deleteChannelsStartsWith,
import ShippingUtils from "../../utils/shippingUtils"; getDefaultChannel
} from "../../utils/channelsUtils";
import * as productUtils from "../../utils/productsUtils";
import * as shippingUtils from "../../utils/shippingUtils";
import { getProductVariants } from "../../utils/storeFront/storeFrontProductUtils"; import { getProductVariants } from "../../utils/storeFront/storeFrontProductUtils";
// <reference types="cypress" /> // <reference types="cypress" />
describe("creating variants", () => { describe("Creating variants", () => {
const startsWith = "Cy-"; const startsWith = "Cy-";
const attributeValues = ["value1", "value2"]; const attributeValues = ["value1", "value2"];
const productUtils = new ProductsUtils();
const channelsUtils = new ChannelsUtils();
const shippingUtils = new ShippingUtils();
const product = new Product();
const channels = new Channels();
const variantsSteps = new VariantsSteps();
let defaultChannel; let defaultChannel;
let warehouse; let warehouse;
let attribute; let attribute;
@ -30,13 +31,12 @@ describe("creating variants", () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
shippingUtils.deleteShipping(startsWith); shippingUtils.deleteShippingStartsWith(startsWith);
productUtils.deleteProperProducts(startsWith); productUtils.deleteProductsStartsWith(startsWith);
channelsUtils.deleteChannels(startsWith); deleteChannelsStartsWith(startsWith);
const name = `${startsWith}${faker.random.number()}`; const name = `${startsWith}${faker.random.number()}`;
channelsUtils getDefaultChannel()
.getDefaultChannel()
.then(channel => { .then(channel => {
defaultChannel = channel; defaultChannel = channel;
cy.fixture("addresses"); cy.fixture("addresses");
@ -48,15 +48,21 @@ describe("creating variants", () => {
address: fixtureAddresses.plAddress address: fixtureAddresses.plAddress
}) })
) )
.then(() => (warehouse = shippingUtils.getWarehouse())); .then(({ warehouse: warehouseResp }) => (warehouse = warehouseResp));
productUtils productUtils
.createTypeAttributeAndCategoryForProduct(name, attributeValues) .createTypeAttributeAndCategoryForProduct(name, attributeValues)
.then(() => { .then(
attribute = productUtils.getAttribute(); ({
productType = productUtils.getProductType(); attribute: attributeResp,
category = productUtils.getCategory(); productType: productTypeResp,
}); category: categoryResp
}) => {
attribute = attributeResp;
productType = productTypeResp;
category = categoryResp;
}
);
}); });
beforeEach(() => { beforeEach(() => {
@ -68,16 +74,15 @@ describe("creating variants", () => {
const price = 10; const price = 10;
let createdProduct; let createdProduct;
product createProduct(attribute.id, name, productType.id, category.id)
.createProduct(attribute.id, name, productType.id, category.id)
.then(resp => { .then(resp => {
createdProduct = resp.body.data.productCreate.product; createdProduct = resp.body.data.productCreate.product;
product.updateChannelInProduct({ updateChannelInProduct({
productId: createdProduct.id, productId: createdProduct.id,
channelId: defaultChannel.id channelId: defaultChannel.id
}); });
cy.visit(`${urlList.products}${createdProduct.id}`); cy.visit(`${urlList.products}${createdProduct.id}`);
variantsSteps.createFirstVariant({ createFirstVariant({
sku: name, sku: name,
warehouseId: warehouse.id, warehouseId: warehouse.id,
price, price,
@ -106,10 +111,10 @@ describe("creating variants", () => {
categoryId: category.id, categoryId: category.id,
price: variants[0].price price: variants[0].price
}) })
.then(() => { .then(({ product: productResp }) => {
createdProduct = productUtils.getCreatedProduct(); createdProduct = productResp;
cy.visit(`${urlList.products}${createdProduct.id}`); cy.visit(`${urlList.products}${createdProduct.id}`);
variantsSteps.createVariant({ createVariant({
sku: secondVariantSku, sku: secondVariantSku,
warehouseName: warehouse.name, warehouseName: warehouse.name,
attributeName: variants[1].name, attributeName: variants[1].name,
@ -128,8 +133,7 @@ describe("creating variants", () => {
const variantsPrice = 10; const variantsPrice = 10;
let newChannel; let newChannel;
let createdProduct; let createdProduct;
channels createChannel(true, name, name, "PLN")
.createChannel(true, name, name, "PLN")
.then(resp => { .then(resp => {
newChannel = resp.body.data.channelCreate.channel; newChannel = resp.body.data.channelCreate.channel;
productUtils.createProduct( productUtils.createProduct(
@ -139,22 +143,22 @@ describe("creating variants", () => {
category.id category.id
); );
}) })
.then(() => { .then(productResp => {
createdProduct = productUtils.getCreatedProduct(); createdProduct = productResp;
product.updateChannelInProduct({ updateChannelInProduct({
productId: createdProduct.id, productId: createdProduct.id,
channelId: defaultChannel.id channelId: defaultChannel.id
}); });
}) })
.then(() => { .then(() => {
product.updateChannelInProduct({ updateChannelInProduct({
productId: createdProduct.id, productId: createdProduct.id,
channelId: newChannel.id channelId: newChannel.id
}); });
}) })
.then(() => { .then(() => {
cy.visit(`${urlList.products}${createdProduct.id}`); cy.visit(`${urlList.products}${createdProduct.id}`);
variantsSteps.createFirstVariant({ createFirstVariant({
sku: name, sku: name,
warehouseId: warehouse.id, warehouseId: warehouse.id,
price: variantsPrice, price: variantsPrice,

View file

@ -1,8 +1,7 @@
import { ADD_CHANNEL_FORM_SELECTORS } from "../elements/channels/add-channel-form-selectors"; import { ADD_CHANNEL_FORM_SELECTORS } from "../elements/channels/add-channel-form-selectors";
import { CHANNELS_SELECTORS } from "../elements/channels/channels-selectors"; import { CHANNELS_SELECTORS } from "../elements/channels/channels-selectors";
class ChannelsSteps { export function createChannelByView(name, currency, slug = name) {
createChannelByView(name, currency, otherCurrency, slug = name) {
cy.get(CHANNELS_SELECTORS.createChannelButton) cy.get(CHANNELS_SELECTORS.createChannelButton)
.click() .click()
.get(ADD_CHANNEL_FORM_SELECTORS.channelName) .get(ADD_CHANNEL_FORM_SELECTORS.channelName)
@ -11,16 +10,13 @@ class ChannelsSteps {
.type(slug) .type(slug)
.get(ADD_CHANNEL_FORM_SELECTORS.currency) .get(ADD_CHANNEL_FORM_SELECTORS.currency)
.click(); .click();
if (!otherCurrency) {
cy.get(ADD_CHANNEL_FORM_SELECTORS.currency).type(currency); cy.get(ADD_CHANNEL_FORM_SELECTORS.currency).type(currency);
cy.get(`[data-test-value=${currency}]`).click(); cy.get("body").then($body => {
if ($body.find(currency).length) {
cy.contains(ADD_CHANNEL_FORM_SELECTORS.currencyOptions, currency).click();
} else { } else {
cy.get(ADD_CHANNEL_FORM_SELECTORS.currency) cy.get(ADD_CHANNEL_FORM_SELECTORS.currencyAutocompleteDropdown).click();
.type(otherCurrency)
.get(ADD_CHANNEL_FORM_SELECTORS.currencyAutocompleteDropdown)
.click();
} }
});
cy.get(ADD_CHANNEL_FORM_SELECTORS.saveButton).click(); cy.get(ADD_CHANNEL_FORM_SELECTORS.saveButton).click();
}
} }
export default ChannelsSteps;

View file

@ -2,8 +2,8 @@ import { COLLECTION_SELECTORS } from "../elements/catalog/collection-selectors";
import { ASSIGN_PRODUCTS_SELECTORS } from "../elements/catalog/products/assign-products-selectors"; import { ASSIGN_PRODUCTS_SELECTORS } from "../elements/catalog/products/assign-products-selectors";
import { MENAGE_CHANNEL_AVAILABILITY_FORM } from "../elements/channels/menage-channel-availability-form"; import { MENAGE_CHANNEL_AVAILABILITY_FORM } from "../elements/channels/menage-channel-availability-form";
import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../elements/shared/button-selectors";
class CollectionsSteps {
createCollection(collectionName, isPublished, channel) { export function createCollection(collectionName, isPublished, channel) {
const publishedSelector = isPublished const publishedSelector = isPublished
? MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueTrue ? MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueTrue
: MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueFalse; : MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueFalse;
@ -32,8 +32,8 @@ class CollectionsSteps {
return cy return cy
.wait("@CreateCollection") .wait("@CreateCollection")
.its("response.body.data.collectionCreate.collection"); .its("response.body.data.collectionCreate.collection");
} }
assignProductsToCollection(productName) { export function assignProductsToCollection(productName) {
cy.get(COLLECTION_SELECTORS.addProductButton) cy.get(COLLECTION_SELECTORS.addProductButton)
.click() .click()
.get(ASSIGN_PRODUCTS_SELECTORS.searchInput) .get(ASSIGN_PRODUCTS_SELECTORS.searchInput)
@ -44,6 +44,4 @@ class CollectionsSteps {
cy.addAliasToGraphRequest("CollectionAssignProduct"); cy.addAliasToGraphRequest("CollectionAssignProduct");
cy.get(ASSIGN_PRODUCTS_SELECTORS.submitButton).click(); cy.get(ASSIGN_PRODUCTS_SELECTORS.submitButton).click();
cy.wait("@CollectionAssignProduct"); cy.wait("@CollectionAssignProduct");
}
} }
export default CollectionsSteps;

View file

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

View file

@ -1,8 +1,7 @@
import { PRODUCTS_SELECTORS } from "../../elements/catalog/products/product-selectors"; import { PRODUCTS_SELECTORS } from "../../elements/catalog/products/product-selectors";
import { VARIANTS_SELECTORS } from "../../elements/catalog/variants-selectors"; import { VARIANTS_SELECTORS } from "../../elements/catalog/variants-selectors";
class VariantsSteps { export function createFirstVariant({ sku, warehouseId, price, attribute }) {
createFirstVariant({ sku, warehouseId, price, attribute }) {
cy.get(PRODUCTS_SELECTORS.addVariantsButton).click(); cy.get(PRODUCTS_SELECTORS.addVariantsButton).click();
cy.get(VARIANTS_SELECTORS.valueContainer) cy.get(VARIANTS_SELECTORS.valueContainer)
.contains(attribute) .contains(attribute)
@ -23,14 +22,14 @@ class VariantsSteps {
cy.addAliasToGraphRequest("ProductVariantBulkCreate"); cy.addAliasToGraphRequest("ProductVariantBulkCreate");
cy.get(VARIANTS_SELECTORS.nextButton).click(); cy.get(VARIANTS_SELECTORS.nextButton).click();
cy.wait("@ProductVariantBulkCreate"); cy.wait("@ProductVariantBulkCreate");
} }
createVariant({ export function createVariant({
sku, sku,
warehouseName, warehouseName,
attributeName, attributeName,
price, price,
costPrice = price costPrice = price
}) { }) {
cy.get(PRODUCTS_SELECTORS.addVariantsButton) cy.get(PRODUCTS_SELECTORS.addVariantsButton)
.click() .click()
.get(VARIANTS_SELECTORS.attributeSelector) .get(VARIANTS_SELECTORS.attributeSelector)
@ -50,6 +49,4 @@ class VariantsSteps {
cy.addAliasToGraphRequest("ProductVariantDetails"); cy.addAliasToGraphRequest("ProductVariantDetails");
cy.get(VARIANTS_SELECTORS.saveButton).click(); cy.get(VARIANTS_SELECTORS.saveButton).click();
cy.wait("@ProductVariantDetails"); cy.wait("@ProductVariantDetails");
}
} }
export default VariantsSteps;

View file

@ -1,28 +1,30 @@
import { PRODUCTS_SELECTORS } from "../../elements/catalog/products/product-selectors"; import { PRODUCTS_SELECTORS } from "../../elements/catalog/products/product-selectors";
class ProductSteps { const valueTrue = PRODUCTS_SELECTORS.radioButtonsValueTrue;
valueTrue = PRODUCTS_SELECTORS.radioButtonsValueTrue; const valueFalse = PRODUCTS_SELECTORS.radioButtonsValueFalse;
valueFalse = PRODUCTS_SELECTORS.radioButtonsValueFalse;
updateProductIsAvailableForPurchase(productUrl, isAvailableForPurchase) { export function updateProductIsAvailableForPurchase(
productUrl,
isAvailableForPurchase
) {
const isAvailableForPurchaseSelector = isAvailableForPurchase const isAvailableForPurchaseSelector = isAvailableForPurchase
? this.valueTrue ? valueTrue
: this.valueFalse; : valueFalse;
const availableForPurchaseSelector = `${PRODUCTS_SELECTORS.availableForPurchaseRadioButtons}${isAvailableForPurchaseSelector}`; const availableForPurchaseSelector = `${PRODUCTS_SELECTORS.availableForPurchaseRadioButtons}${isAvailableForPurchaseSelector}`;
this.updateProductMenageInChannel(productUrl, availableForPurchaseSelector); updateProductMenageInChannel(productUrl, availableForPurchaseSelector);
} }
updateProductPublish(productUrl, isPublished) { export function updateProductPublish(productUrl, isPublished) {
const isPublishedSelector = isPublished ? this.valueTrue : this.valueFalse; const isPublishedSelector = isPublished ? valueTrue : valueFalse;
const publishedSelector = `${PRODUCTS_SELECTORS.publishedRadioButtons}${isPublishedSelector}`; const publishedSelector = `${PRODUCTS_SELECTORS.publishedRadioButtons}${isPublishedSelector}`;
this.updateProductMenageInChannel(productUrl, publishedSelector); updateProductMenageInChannel(productUrl, publishedSelector);
} }
updateProductVisibleInListings(productUrl) { export function updateProductVisibleInListings(productUrl) {
this.updateProductMenageInChannel( updateProductMenageInChannel(
productUrl, productUrl,
PRODUCTS_SELECTORS.visibleInListingsButton PRODUCTS_SELECTORS.visibleInListingsButton
); );
} }
updateProductMenageInChannel(productUrl, menageSelector) { function updateProductMenageInChannel(productUrl, menageSelector) {
cy.visit(productUrl) cy.visit(productUrl)
.get(PRODUCTS_SELECTORS.assignedChannels) .get(PRODUCTS_SELECTORS.assignedChannels)
.click() .click()
@ -32,6 +34,4 @@ class ProductSteps {
cy.get(PRODUCTS_SELECTORS.saveBtn) cy.get(PRODUCTS_SELECTORS.saveBtn)
.click() .click()
.wait("@ProductChannelListingUpdate"); .wait("@ProductChannelListingUpdate");
}
} }
export default ProductSteps;

View file

@ -7,7 +7,7 @@ Cypress.Commands.add(
} }
); );
Cypress.Commands.add( Cypress.Commands.add(
"deleteProperElements", "deleteElementsStartsWith",
(deleteFunction, getFunction, startsWith, name) => { (deleteFunction, getFunction, startsWith, name) => {
getFunction(100, startsWith).then(elements => { getFunction(100, startsWith).then(elements => {
elements.forEach(element => { elements.forEach(element => {

View file

@ -1,11 +1,7 @@
import Channels from "../apiRequests/Channels"; import * as channels from "../apiRequests/Channels";
class ChannelsUtils { export function deleteChannelsStartsWith(nameStartsWith) {
channels = new Channels(); channels.getChannels().then(resp => {
createdChannel;
deleteChannels(nameStartsWith) {
this.channels.getChannels().then(resp => {
const channelsArray = new Set(resp.body.data.channels); const channelsArray = new Set(resp.body.data.channels);
if (!channelsArray) { if (!channelsArray) {
return; return;
@ -21,32 +17,28 @@ class ChannelsUtils {
); );
}); });
if (targetChannels[0]) { if (targetChannels[0]) {
this.channels.deleteChannel(element.id, targetChannels[0].id); channels.deleteChannel(element.id, targetChannels[0].id);
channelsArray.delete(element); channelsArray.delete(element);
} }
} }
}); });
}); });
}
getDefaultChannel() {
return this.channels.getChannels().then(resp => {
const channelsArray = resp.body.data.channels;
return (this.defaultChannel = channelsArray.find(function(
channelElement
) {
return channelElement.slug === "default-channel";
}));
});
}
createChannel({ isActive = true, name, slug = name, currencyCode = "PLN" }) {
return this.channels
.createChannel(isActive, name, slug, currencyCode)
.then(
resp => (this.createdChannel = resp.body.data.channelCreate.channel)
);
}
getCreatedChannel() {
return this.createdChannel;
}
} }
export default ChannelsUtils; export function getDefaultChannel() {
return channels.getChannels().then(resp => {
const channelsArray = resp.body.data.channels;
return channelsArray.find(function(channelElement) {
return channelElement.slug === "default-channel";
});
});
}
export function createChannel({
isActive = true,
name,
slug = name,
currencyCode = "PLN"
}) {
return channels
.createChannel(isActive, name, slug, currencyCode)
.its("body.data.channelCreate.channel");
}

View file

@ -1,15 +1,10 @@
import Collections from "../apiRequests/Collections"; import { deleteCollection, getCollections } from "../apiRequests/Collections";
class CollectionsUtils { export function deleteCollectionsStartsWith(startsWith) {
collectionsRequest = new Collections(); cy.deleteElementsStartsWith(
deleteCollection,
deleteProperCollections(startsWith) { getCollections,
cy.deleteProperElements(
this.collectionsRequest.deleteCollection,
this.collectionsRequest.getCollections,
startsWith, startsWith,
"collection" "collection"
); );
}
} }
export default CollectionsUtils;

View file

@ -1,30 +1,27 @@
import HomePage from "../apiRequests/HomePage"; import * as homePage from "../apiRequests/HomePage";
class HomePageUtils {
homePage = new HomePage(); export function getOrdersReadyToFulfill(channelSlug) {
getOrdersReadyToFulfill(channelSlug) { return homePage
return this.homePage
.getOrdersWithStatus("READY_TO_FULFILL", channelSlug) .getOrdersWithStatus("READY_TO_FULFILL", channelSlug)
.then(resp => resp.body.data.orders.totalCount); .its("body.data.orders.totalCount");
} }
getOrdersReadyForCapture(channelSlug) { export function getOrdersReadyForCapture(channelSlug) {
return this.homePage return homePage
.getOrdersWithStatus("READY_TO_CAPTURE", channelSlug) .getOrdersWithStatus("READY_TO_CAPTURE", channelSlug)
.then(resp => resp.body.data.orders.totalCount); .its("body.data.orders.totalCount");
} }
getProductsOutOfStock(channelSlug) { export function getProductsOutOfStock(channelSlug) {
return this.homePage return homePage
.getProductsOutOfStock(channelSlug) .getProductsOutOfStock(channelSlug)
.then(resp => resp.body.data.products.totalCount); .its("body.data.products.totalCount");
} }
getSalesAmount(channelSlug) { export function getSalesAmount(channelSlug) {
return this.homePage return homePage
.getSalesForChannel(channelSlug, "TODAY") .getSalesForChannel(channelSlug, "TODAY")
.then(resp => resp.body.data.ordersTotal.gross.amount); .its("body.data.ordersTotal.gross.amount");
} }
getTodaysOrders(channelSlug) { export function getTodaysOrders(channelSlug) {
return this.homePage return homePage
.getOrdersForChannel(channelSlug, "TODAY") .getOrdersForChannel(channelSlug, "TODAY")
.then(resp => resp.body.data.orders.totalCount); .its("body.data.orders.totalCount");
}
} }
export default HomePageUtils;

View file

@ -1,60 +1,53 @@
import Checkout from "../apiRequests/Checkout"; import * as checkoutRequest from "../apiRequests/Checkout";
import Order from "../apiRequests/Order"; import * as orderRequest from "../apiRequests/Order";
class OrdersUtils { export function createWaitingForCaptureOrder(
checkoutRequest = new Checkout();
orderRequest = new Order();
checkout;
order;
createWaitingForCaptureOrder(
channelSlug, channelSlug,
email, email,
variantsList, variantsList,
shippingMethodId shippingMethodId
) { ) {
return this.createCheckout(channelSlug, email, variantsList) let checkout;
.then(() => return createCheckout(channelSlug, email, variantsList)
this.checkoutRequest.addShippingMethod( .then(checkoutResp => {
this.checkout.id, checkout = checkoutResp;
shippingMethodId checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
) })
) .then(() => addPayment(checkout.id))
.then(() => this.addPayment(this.checkout.id)) .then(() => checkoutRequest.completeCheckout(checkout.id))
.then(() => this.checkoutRequest.completeCheckout(this.checkout.id)); .then(() => checkout);
} }
createReadyToFulfillOrder( export function createReadyToFulfillOrder(
customerId, customerId,
shippingMethodId, shippingMethodId,
channelId, channelId,
variantsList variantsList
) { ) {
return this.createDraftOrder(customerId, shippingMethodId, channelId) let order;
.then(() => { return createDraftOrder(customerId, shippingMethodId, channelId)
.then(orderResp => {
order = orderResp;
variantsList.forEach(variantElement => { variantsList.forEach(variantElement => {
this.orderRequest.addProductToOrder(this.order.id, variantElement.id); orderRequest.addProductToOrder(order.id, variantElement.id);
}); });
}) })
.then(() => this.orderRequest.markOrderAsPaid(this.order.id)) .then(() => orderRequest.markOrderAsPaid(order.id))
.then(() => this.orderRequest.completeOrder(this.order.id)); .then(() => orderRequest.completeOrder(order.id));
} }
createDraftOrder(customerId, shippingMethodId, channelId) { export function createDraftOrder(customerId, shippingMethodId, channelId) {
return this.orderRequest return orderRequest
.createDraftOrder(customerId, shippingMethodId, channelId) .createDraftOrder(customerId, shippingMethodId, channelId)
.then(resp => (this.order = resp.body.data.draftOrderCreate.order)); .its("body.data.draftOrderCreate.order");
} }
createCheckout(channelSlug, email, variantsList) { export function createCheckout(channelSlug, email, variantsList) {
return this.checkoutRequest return checkoutRequest
.createCheckout(channelSlug, email, 1, variantsList) .createCheckout(channelSlug, email, 1, variantsList)
.then(resp => (this.checkout = resp.body.data.checkoutCreate.checkout)); .its("body.data.checkoutCreate.checkout");
} }
addPayment(checkoutId) { export function addPayment(checkoutId) {
return this.checkoutRequest.addPayment( return checkoutRequest.addPayment(
checkoutId, checkoutId,
"mirumee.payments.dummy", "mirumee.payments.dummy",
"not-charged" "not-charged"
); );
}
} }
export default OrdersUtils;

View file

@ -1,28 +1,8 @@
import Attribute from "../apiRequests/Attribute"; import * as attributeRequest from "../apiRequests/Attribute";
import Category from "../apiRequests/Category"; import * as categoryRequest from "../apiRequests/Category";
import Product from "../apiRequests/Product"; import * as productRequest from "../apiRequests/Product";
class ProductsUtils { export function createProductInChannel({
productRequest = new Product();
attributeRequest = new Attribute();
categoryRequest = new Category();
product;
variants;
productType;
attribute;
category;
createProductWithVariant(name, attributeId, productTypeId, categoryId) {
return this.createProduct(
attributeId,
name,
productTypeId,
categoryId
).then(() => this.createVariant(this.product.id, name, attributeId));
}
createProductInChannel({
name, name,
channelId, channelId,
warehouseId = null, warehouseId = null,
@ -34,68 +14,86 @@ class ProductsUtils {
isPublished = true, isPublished = true,
isAvailableForPurchase = true, isAvailableForPurchase = true,
visibleInListings = true visibleInListings = true
}) { }) {
return this.createProduct(attributeId, name, productTypeId, categoryId) let product;
.then(() => let variants;
this.productRequest.updateChannelInProduct({ return createProduct(attributeId, name, productTypeId, categoryId)
productId: this.product.id, .then(productResp => {
product = productResp;
productRequest.updateChannelInProduct({
productId: product.id,
channelId, channelId,
isPublished, isPublished,
isAvailableForPurchase, isAvailableForPurchase,
visibleInListings visibleInListings
});
}) })
)
.then(() => { .then(() => {
this.createVariant({ createVariant({
productId: this.product.id, productId: product.id,
sku: name, sku: name,
warehouseId, warehouseId,
quantityInWarehouse, quantityInWarehouse,
channelId, channelId,
price price
}); });
})
.then(variantsResp => {
variants = variantsResp;
return { product, variants };
}); });
} }
createTypeAttributeAndCategoryForProduct(name, attributeValues) { export function createTypeAttributeAndCategoryForProduct(
return this.createAttribute(name, attributeValues) name,
.then(() => this.createTypeProduct(name, this.attribute.id)) attributeValues
.then(() => this.createCategory(name)); ) {
} let attribute;
createAttribute(name, attributeValues) { let productType;
return this.attributeRequest let category;
return createAttribute(name, attributeValues)
.then(attributeResp => {
attribute = attributeResp;
createTypeProduct(name, attributeResp.id);
})
.then(productTypeResp => {
productType = productTypeResp;
createCategory(name);
})
.then(categoryResp => {
category = categoryResp;
return { attribute, category, productType };
});
}
export function createAttribute(name, attributeValues) {
return attributeRequest
.createAttribute(name, attributeValues) .createAttribute(name, attributeValues)
.then( .its("body.data.attributeCreate.attribute");
resp => (this.attribute = resp.body.data.attributeCreate.attribute) }
); export function createTypeProduct(name, attributeId) {
} return productRequest
createTypeProduct(name, attributeId) {
return this.productRequest
.createTypeProduct(name, attributeId) .createTypeProduct(name, attributeId)
.then( .its("body.data.productTypeCreate.productType");
resp => }
(this.productType = resp.body.data.productTypeCreate.productType) export function createCategory(name) {
); return categoryRequest
}
createCategory(name) {
return this.categoryRequest
.createCategory(name) .createCategory(name)
.then(resp => (this.category = resp.body.data.categoryCreate.category)); .its("body.data.categoryCreate.category");
} }
createProduct(attributeId, name, productTypeId, categoryId) { export function createProduct(attributeId, name, productTypeId, categoryId) {
return this.productRequest return productRequest
.createProduct(attributeId, name, productTypeId, categoryId) .createProduct(attributeId, name, productTypeId, categoryId)
.then(resp => (this.product = resp.body.data.productCreate.product)); .its("body.data.productCreate.product");
} }
createVariant({ export function createVariant({
productId, productId,
sku, sku,
warehouseId, warehouseId,
quantityInWarehouse, quantityInWarehouse,
channelId, channelId,
price price
}) { }) {
return this.productRequest return productRequest
.createVariant({ .createVariant({
productId, productId,
sku, sku,
@ -104,49 +102,26 @@ class ProductsUtils {
channelId, channelId,
price price
}) })
.then( .its("body.data.productVariantBulkCreate.productVariants");
resp => }
(this.variants =
resp.body.data.productVariantBulkCreate.productVariants) export function deleteProductsStartsWith(startsWith) {
); cy.deleteElementsStartsWith(
} productRequest.deleteProductType,
getCreatedProduct() { productRequest.getProductTypes,
return this.product;
}
getCreatedVariants() {
return this.variants;
}
getProductType() {
return this.productType;
}
getAttribute() {
return this.attribute;
}
getCategory() {
return this.category;
}
deleteProperProducts(startsWith) {
const product = new Product();
const attribute = new Attribute();
const category = new Category();
cy.deleteProperElements(
product.deleteProductType,
product.getProductTypes,
startsWith, startsWith,
"productType" "productType"
); );
cy.deleteProperElements( cy.deleteElementsStartsWith(
attribute.deleteAttribute, attributeRequest.deleteAttribute,
attribute.getAttributes, attributeRequest.getAttributes,
startsWith, startsWith,
"attributes" "attributes"
); );
cy.deleteProperElements( cy.deleteElementsStartsWith(
category.deleteCategory, categoryRequest.deleteCategory,
category.getCategories, categoryRequest.getCategories,
startsWith, startsWith,
"categories" "categories"
); );
}
} }
export default ProductsUtils;

View file

@ -1,77 +1,58 @@
import ShippingMethod from "../apiRequests/ShippingMethod"; import * as shippingMethodRequest from "../apiRequests/ShippingMethod";
import Warehouse from "../apiRequests/Warehouse"; import * as warehouseRequest from "../apiRequests/Warehouse";
class ShippingUtils {
shippingMethodRequest = new ShippingMethod();
warehouseRequest = new Warehouse();
shippingMethod; export function createShipping({ channelId, name, address, price = 1 }) {
shippingZone; let shippingMethod;
warehouse; let shippingZone;
let warehouse;
createShipping({ channelId, name, address, price = 1 }) { return createShippingZone(name, address.country)
return this.createShippingZone(name, address.country) .then(shippingZoneResp => {
.then(() => this.createWarehouse(name, this.shippingZone.id, address)) shippingZone = shippingZoneResp;
.then(() => this.createShippingRate(name, this.shippingZone.id)) createWarehouse(name, shippingZone.id, address);
.then(() => })
this.shippingMethodRequest.addChannelToShippingMethod( .then(warehouseResp => {
this.shippingMethod.id, warehouse = warehouseResp;
createShippingRate(name, shippingZone.id);
})
.then(sippingMethodResp => {
shippingMethod = sippingMethodResp;
shippingMethodRequest.addChannelToShippingMethod(
shippingMethod.id,
channelId, channelId,
price price
)
); );
} })
.then(() => ({ shippingMethod, shippingZone, warehouse }));
}
createShippingZone(name, country) { export function createShippingZone(name, country) {
return this.shippingMethodRequest return shippingMethodRequest
.createShippingZone(name, country) .createShippingZone(name, country)
.then(resp => { .its("body.data.shippingZoneCreate.shippingZone");
this.shippingZone = resp.body.data.shippingZoneCreate.shippingZone; }
}); export function createWarehouse(name, shippingZoneId, address) {
} return warehouseRequest
createWarehouse(name, shippingZoneId, address) {
return this.warehouseRequest
.createWarehouse(name, shippingZoneId, address) .createWarehouse(name, shippingZoneId, address)
.then(resp => { .its("body.data.createWarehouse.warehouse");
this.warehouse = resp.body.data.createWarehouse.warehouse; }
}); export function createShippingRate(name, shippingZoneId) {
} return shippingMethodRequest
createShippingRate(name, shippingZoneId) {
return this.shippingMethodRequest
.createShippingRate(name, shippingZoneId) .createShippingRate(name, shippingZoneId)
.then( .its("body.data.shippingPriceCreate.shippingMethod");
resp => }
(this.shippingMethod =
resp.body.data.shippingPriceCreate.shippingMethod)
);
}
getShippingMethod() { export function deleteShippingStartsWith(startsWith) {
return this.shippingMethod; cy.deleteElementsStartsWith(
} shippingMethodRequest.deleteShippingZone,
shippingMethodRequest.getShippingZones,
getShippingZone() {
return this.shippingZone;
}
getWarehouse() {
return this.warehouse;
}
deleteShipping(startsWith) {
const shippingMethod = new ShippingMethod();
const warehouse = new Warehouse();
cy.deleteProperElements(
shippingMethod.deleteShippingZone,
shippingMethod.getShippingZones,
startsWith, startsWith,
"shippingZONE" "shippingZONE"
); );
cy.deleteProperElements( cy.deleteElementsStartsWith(
warehouse.deleteWarehouse, warehouseRequest.deleteWarehouse,
warehouse.getWarehouses, warehouseRequest.getWarehouses,
startsWith, startsWith,
"Warehouse" "Warehouse"
); );
}
} }
export default ShippingUtils;

View file

@ -1,4 +1,4 @@
import ProductDetails from "../../apiRequests/storeFront/ProductDetails"; import { getProductDetails } from "../../apiRequests/storeFront/ProductDetails";
export const isProductVisible = (resp, name) => { export const isProductVisible = (resp, name) => {
const product = resp.body.data.product; const product = resp.body.data.product;
@ -18,13 +18,11 @@ export const isProductVisibleInSearchResult = (resp, productName) => {
); );
}; };
export const getProductVariants = (productId, channelSlug) => { export const getProductVariants = (productId, channelSlug) =>
const productDetails = new ProductDetails(); getProductDetails(productId, channelSlug).then(resp => {
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
})); }));
}); });
};