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
@ -19,11 +18,11 @@ 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}"
}){ }){
@ -35,13 +34,13 @@ 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{
field field
@ -49,7 +48,5 @@ class Attribute {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Attribute;

View file

@ -1,6 +1,5 @@
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{
field field
@ -11,10 +10,10 @@ 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}"
}){ }){
@ -26,12 +25,12 @@ 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{
field field
@ -39,7 +38,5 @@ class Category {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Category;

View file

@ -1,6 +1,5 @@
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}
name: "${name}" name: "${name}"
@ -18,10 +17,10 @@ class Channels {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(createChannelMutation); return cy.sendRequestWithQuery(createChannelMutation);
} }
getChannels() { export function getChannels() {
const getChannelsInfoQuery = `query{ const getChannelsInfoQuery = `query{
channels{ channels{
name name
id id
@ -31,11 +30,11 @@ 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}"
}){ }){
@ -47,7 +46,5 @@ class Channels {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(deleteChannelMutation); return cy.sendRequestWithQuery(deleteChannelMutation);
}
} }
export default Channels;

View file

@ -1,10 +1,14 @@
class Checkout { export function createCheckout(
createCheckout(channelSlug, email, productQuantity, variantsList) { channelSlug,
const lines = variantsList.map( email,
variant => `{quantity:${productQuantity} productQuantity,
variantsList
) {
const lines = variantsList.map(
variant => `{quantity:${productQuantity}
variantId:"${variant.id}"}` variantId:"${variant.id}"}`
); );
const mutation = `mutation{ const mutation = `mutation{
checkoutCreate(input:{ checkoutCreate(input:{
channel:"${channelSlug}" channel:"${channelSlug}"
email:"${email}" email:"${email}"
@ -20,10 +24,10 @@ 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}"){
checkoutErrors{ checkoutErrors{
@ -32,10 +36,10 @@ 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:{
gateway: "${gateway}" gateway: "${gateway}"
@ -47,10 +51,10 @@ 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{
id id
@ -63,7 +67,5 @@ class Checkout {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Checkout;

View file

@ -1,11 +1,10 @@
class Collections { export function getCollections(search) {
getCollections(search) { const filter = search
const filter = search ? `, filter:{
? `, filter:{
search:"" search:""
}` }`
: ""; : "";
const query = `query{ const query = `query{
collections(first:100 ${filter}){ collections(first:100 ${filter}){
edges{ edges{
node{ node{
@ -15,12 +14,12 @@ 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{
id id
@ -31,7 +30,5 @@ class Collections {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Collections;

View file

@ -1,6 +1,5 @@
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:{
firstName: "${customerName}" firstName: "${customerName}"
@ -37,24 +36,24 @@ 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{
code code
@ -62,11 +61,11 @@ 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}"
}){ }){
@ -79,7 +78,5 @@ export class Customer {
} }
} }
`; `;
return cy.sendRequestWithQuery(query); return cy.sendRequestWithQuery(query);
}
} }
export default Customer;

View file

@ -1,37 +1,34 @@
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{
amount amount
} }
} }
}`; }`;
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,17 +1,16 @@
class Order { export function markOrderAsPaid(orderId) {
markOrderAsPaid(orderId) { const mutation = `mutation{
const mutation = `mutation{
orderMarkAsPaid(id:"${orderId}"){ orderMarkAsPaid(id:"${orderId}"){
orderErrors{ orderErrors{
message message
} }
} }
}`; }`;
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}
variantId: "${variantId}" variantId: "${variantId}"
@ -21,11 +20,11 @@ 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:{
user:"${customerId}" user:"${customerId}"
@ -41,10 +40,10 @@ 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{
id id
@ -54,7 +53,5 @@ class Order {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Order;

View file

@ -1,13 +1,12 @@
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}"
}` }`
: ""; : "";
const query = `query{ const query = `query{
products(first:${first}${filter}){ products(first:${first}${filter}){
edges{ edges{
node{ node{
@ -20,19 +19,19 @@ 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:{
addChannels:{ addChannels:{
@ -48,11 +47,11 @@ 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}"
price: 10 price: 10
@ -63,10 +62,10 @@ 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:[{
id:"${attributeId}" id:"${attributeId}"
@ -84,36 +83,36 @@ class Product {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
createVariant({ export function createVariant({
productId, productId,
sku, sku,
warehouseId, warehouseId,
quantity, quantity,
channelId,
price = 1,
costPrice = 1
}) {
const channelListings = getValueWithDefault(
channelId, channelId,
price = 1, `channelListings:{
costPrice = 1
}) {
const channelListings = getValueWithDefault(
channelId,
`channelListings:{
channelId:"${channelId}" channelId:"${channelId}"
price:"${price}" price:"${price}"
costPrice:"${costPrice}" costPrice:"${costPrice}"
}` }`
); );
const stocks = getValueWithDefault( const stocks = getValueWithDefault(
warehouseId, warehouseId,
`stocks:{ `stocks:{
warehouse:"${warehouseId}" warehouse:"${warehouseId}"
quantity:${quantity} quantity:${quantity}
}` }`
); );
const mutation = `mutation{ const mutation = `mutation{
productVariantBulkCreate(product: "${productId}", variants: { productVariantBulkCreate(product: "${productId}", variants: {
attributes: [] attributes: []
sku: "${sku}" sku: "${sku}"
@ -130,11 +129,11 @@ 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}"
slug: "${slug}" slug: "${slug}"
@ -151,11 +150,11 @@ 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{
field field
@ -163,11 +162,11 @@ 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}"
}){ }){
@ -179,13 +178,13 @@ 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{
field field
@ -193,8 +192,5 @@ class Product {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Product;

View file

@ -1,6 +1,5 @@
class ShippingMethod { export function createShippingRate(name, shippingZone) {
createShippingRate(name, shippingZone) { const mutation = `
const mutation = `
mutation{ mutation{
shippingPriceCreate(input:{ shippingPriceCreate(input:{
name: "${name}" name: "${name}"
@ -13,11 +12,11 @@ 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:{
name: "${name}" name: "${name}"
@ -29,11 +28,11 @@ 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:{
addChannels: { addChannels: {
@ -51,11 +50,11 @@ 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{
message message
@ -63,11 +62,11 @@ 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{
node{ node{
@ -78,9 +77,7 @@ 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,6 +1,5 @@
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}"
slug:"${slug}" slug:"${slug}"
@ -24,10 +23,10 @@ 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}"
}){ }){
@ -39,12 +38,12 @@ 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{
field field
@ -52,7 +51,5 @@ class Warehouse {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
}
} }
export default Warehouse;

View file

@ -1,6 +1,5 @@
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
slug slug
@ -16,7 +15,5 @@ class Collections {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(query, "token"); return cy.sendRequestWithQuery(query, "token");
}
} }
export default Collections;

View file

@ -1,6 +1,5 @@
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
} }
@ -34,7 +33,5 @@ class ProductDetails {
availableForPurchase availableForPurchase
} }
}`; }`;
return cy.sendRequestWithQuery(query, "token"); return cy.sendRequestWithQuery(query, "token");
}
} }
export default ProductDetails;

View file

@ -1,6 +1,5 @@
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}"
}, first:10){ }, first:10){
@ -14,7 +13,5 @@ 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,18 +42,25 @@ 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,
productsUtils.createProductInChannel({ category: categoryResp
name, }) => {
channelId: defaultChannel.id, attribute = attributeResp;
productTypeId: productType.id, productType = productTypeResp;
attributeId: attribute.id, category = categoryResp;
categoryId: category.id productsUtils.createProductInChannel({
}); name,
}); channelId: defaultChannel.id,
productTypeId: productType.id,
attributeId: attribute.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
name: randomName, .createProductInChannel({
channelId: defaultChannel.id, name: randomName,
productTypeId: productType.id, channelId: defaultChannel.id,
attributeId: attribute.id, productTypeId: productType.id,
categoryId: category.id, attributeId: attribute.id,
visibleInListings: false categoryId: category.id,
}); 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,24 +54,36 @@ describe("Homepage analytics", () => {
price: shippingPrice price: shippingPrice
}); });
}) })
.then(() => { .then(
productsUtils.createTypeAttributeAndCategoryForProduct(randomName); ({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => {
}) warehouse = warehouseResp;
.then(() => { shippingMethod = shippingMethodResp;
const warehouse = shippingUtils.getWarehouse(); productsUtils.createTypeAttributeAndCategoryForProduct(randomName);
const productType = productsUtils.getProductType(); }
const attribute = productsUtils.getAttribute(); )
const category = productsUtils.getCategory(); .then(
productsUtils.createProductInChannel({ ({
name: randomName, productType: productTypeResp,
channelId: defaultChannel.id, attribute: attributeResp,
warehouseId: warehouse.id, category: categoryResp
quantityInWarehouse: 20, }) => {
productTypeId: productType.id, productType = productTypeResp;
attributeId: attribute.id, attribute = attributeResp;
categoryId: category.id, category = categoryResp;
price: productPrice productsUtils.createProductInChannel({
}); name: randomName,
channelId: defaultChannel.id,
warehouseId: warehouse.id,
quantityInWarehouse: 20,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
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,26 +1,22 @@
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) .type(name)
.type(name) .get(ADD_CHANNEL_FORM_SELECTORS.slug)
.get(ADD_CHANNEL_FORM_SELECTORS.slug) .type(slug)
.type(slug) .get(ADD_CHANNEL_FORM_SELECTORS.currency)
.get(ADD_CHANNEL_FORM_SELECTORS.currency) .click();
.click(); cy.get(ADD_CHANNEL_FORM_SELECTORS.currency).type(currency);
if (!otherCurrency) { cy.get("body").then($body => {
cy.get(ADD_CHANNEL_FORM_SELECTORS.currency).type(currency); if ($body.find(currency).length) {
cy.get(`[data-test-value=${currency}]`).click(); 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,48 +2,46 @@ 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) {
const publishedSelector = isPublished
? MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueTrue
: MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueFalse;
cy.get(COLLECTION_SELECTORS.createCollectionButton) export function createCollection(collectionName, isPublished, channel) {
.click() const publishedSelector = isPublished
.get(COLLECTION_SELECTORS.nameInput) ? MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueTrue
.type(collectionName) : MENAGE_CHANNEL_AVAILABILITY_FORM.radioButtonsValueFalse;
.get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsMenageButton)
.click() cy.get(COLLECTION_SELECTORS.createCollectionButton)
.get(MENAGE_CHANNEL_AVAILABILITY_FORM.allChannelsCheckbox) .click()
.click(); .get(COLLECTION_SELECTORS.nameInput)
cy.contains(MENAGE_CHANNEL_AVAILABILITY_FORM.channelRow, channel.name) .type(collectionName)
.find(MENAGE_CHANNEL_AVAILABILITY_FORM.channelCheckbox) .get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsMenageButton)
.click() .click()
.get(BUTTON_SELECTORS.submit) .get(MENAGE_CHANNEL_AVAILABILITY_FORM.allChannelsCheckbox)
.click() .click();
.get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsAvailabilityItem) cy.contains(MENAGE_CHANNEL_AVAILABILITY_FORM.channelRow, channel.name)
.click() .find(MENAGE_CHANNEL_AVAILABILITY_FORM.channelCheckbox)
.get( .click()
`${MENAGE_CHANNEL_AVAILABILITY_FORM.publishedCheckbox}${publishedSelector}` .get(BUTTON_SELECTORS.submit)
) .click()
.click(); .get(MENAGE_CHANNEL_AVAILABILITY_FORM.channelsAvailabilityItem)
cy.addAliasToGraphRequest("CreateCollection"); .click()
cy.get(COLLECTION_SELECTORS.saveButton).click(); .get(
return cy `${MENAGE_CHANNEL_AVAILABILITY_FORM.publishedCheckbox}${publishedSelector}`
.wait("@CreateCollection") )
.its("response.body.data.collectionCreate.collection"); .click();
} cy.addAliasToGraphRequest("CreateCollection");
assignProductsToCollection(productName) { cy.get(COLLECTION_SELECTORS.saveButton).click();
cy.get(COLLECTION_SELECTORS.addProductButton) return cy
.click() .wait("@CreateCollection")
.get(ASSIGN_PRODUCTS_SELECTORS.searchInput) .its("response.body.data.collectionCreate.collection");
.type(productName); }
cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName) export function assignProductsToCollection(productName) {
.find(ASSIGN_PRODUCTS_SELECTORS.checkbox) cy.get(COLLECTION_SELECTORS.addProductButton)
.click(); .click()
cy.addAliasToGraphRequest("CollectionAssignProduct"); .get(ASSIGN_PRODUCTS_SELECTORS.searchInput)
cy.get(ASSIGN_PRODUCTS_SELECTORS.submitButton).click(); .type(productName);
cy.wait("@CollectionAssignProduct"); cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName)
} .find(ASSIGN_PRODUCTS_SELECTORS.checkbox)
.click();
cy.addAliasToGraphRequest("CollectionAssignProduct");
cy.get(ASSIGN_PRODUCTS_SELECTORS.submitButton).click();
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,55 +1,52 @@
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) .find(VARIANTS_SELECTORS.attributeCheckbox)
.find(VARIANTS_SELECTORS.attributeCheckbox) .click()
.click() .get(VARIANTS_SELECTORS.nextButton)
.get(VARIANTS_SELECTORS.nextButton) .click()
.click() .get(VARIANTS_SELECTORS.priceInput)
.get(VARIANTS_SELECTORS.priceInput) .each($priceInput => {
.each($priceInput => { cy.wrap($priceInput).type(price);
cy.wrap($priceInput).type(price); });
}); cy.get(`[name*='${warehouseId}']`)
cy.get(`[name*='${warehouseId}']`) .click()
.click() .get(VARIANTS_SELECTORS.nextButton)
.get(VARIANTS_SELECTORS.nextButton) .click()
.click() .get(VARIANTS_SELECTORS.skuInput)
.get(VARIANTS_SELECTORS.skuInput) .type(sku);
.type(sku); cy.addAliasToGraphRequest("ProductVariantBulkCreate");
cy.addAliasToGraphRequest("ProductVariantBulkCreate"); cy.get(VARIANTS_SELECTORS.nextButton).click();
cy.get(VARIANTS_SELECTORS.nextButton).click(); cy.wait("@ProductVariantBulkCreate");
cy.wait("@ProductVariantBulkCreate"); }
} export function createVariant({
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) .click()
.click() .get(VARIANTS_SELECTORS.attributeOption)
.get(VARIANTS_SELECTORS.attributeOption) .contains(attributeName)
.contains(attributeName) .click()
.click() .get(VARIANTS_SELECTORS.priceInput)
.get(VARIANTS_SELECTORS.priceInput) .type(price)
.type(price) .get(VARIANTS_SELECTORS.costPriceInput)
.get(VARIANTS_SELECTORS.costPriceInput) .type(costPrice)
.type(costPrice) .get(VARIANTS_SELECTORS.skuInputInAddVariant)
.get(VARIANTS_SELECTORS.skuInputInAddVariant) .type(sku)
.type(sku) .get(VARIANTS_SELECTORS.addWarehouseButton)
.get(VARIANTS_SELECTORS.addWarehouseButton) .click();
.click(); cy.contains(VARIANTS_SELECTORS.warehouseOption, warehouseName).click();
cy.contains(VARIANTS_SELECTORS.warehouseOption, warehouseName).click(); 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,37 +1,37 @@
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(
const isAvailableForPurchaseSelector = isAvailableForPurchase productUrl,
? this.valueTrue isAvailableForPurchase
: this.valueFalse; ) {
const availableForPurchaseSelector = `${PRODUCTS_SELECTORS.availableForPurchaseRadioButtons}${isAvailableForPurchaseSelector}`; const isAvailableForPurchaseSelector = isAvailableForPurchase
this.updateProductMenageInChannel(productUrl, availableForPurchaseSelector); ? valueTrue
} : valueFalse;
updateProductPublish(productUrl, isPublished) { const availableForPurchaseSelector = `${PRODUCTS_SELECTORS.availableForPurchaseRadioButtons}${isAvailableForPurchaseSelector}`;
const isPublishedSelector = isPublished ? this.valueTrue : this.valueFalse; updateProductMenageInChannel(productUrl, availableForPurchaseSelector);
const publishedSelector = `${PRODUCTS_SELECTORS.publishedRadioButtons}${isPublishedSelector}`; }
this.updateProductMenageInChannel(productUrl, publishedSelector); export function updateProductPublish(productUrl, isPublished) {
} const isPublishedSelector = isPublished ? valueTrue : valueFalse;
updateProductVisibleInListings(productUrl) { const publishedSelector = `${PRODUCTS_SELECTORS.publishedRadioButtons}${isPublishedSelector}`;
this.updateProductMenageInChannel( updateProductMenageInChannel(productUrl, publishedSelector);
productUrl, }
PRODUCTS_SELECTORS.visibleInListingsButton export function updateProductVisibleInListings(productUrl) {
); updateProductMenageInChannel(
} productUrl,
updateProductMenageInChannel(productUrl, menageSelector) { PRODUCTS_SELECTORS.visibleInListingsButton
cy.visit(productUrl) );
.get(PRODUCTS_SELECTORS.assignedChannels) }
.click() function updateProductMenageInChannel(productUrl, menageSelector) {
.get(menageSelector) cy.visit(productUrl)
.click(); .get(PRODUCTS_SELECTORS.assignedChannels)
cy.addAliasToGraphRequest("ProductChannelListingUpdate"); .click()
cy.get(PRODUCTS_SELECTORS.saveBtn) .get(menageSelector)
.click() .click();
.wait("@ProductChannelListingUpdate"); cy.addAliasToGraphRequest("ProductChannelListingUpdate");
} cy.get(PRODUCTS_SELECTORS.saveBtn)
.click()
.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,52 +1,44 @@
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; const channelsArray = new Set(resp.body.data.channels);
if (!channelsArray) {
deleteChannels(nameStartsWith) { return;
this.channels.getChannels().then(resp => { }
const channelsArray = new Set(resp.body.data.channels); channelsArray.forEach(element => {
if (!channelsArray) { if (element.name.startsWith(nameStartsWith)) {
return; const targetChannels = Array.from(channelsArray).filter(function(
} channelElement
channelsArray.forEach(element => { ) {
if (element.name.startsWith(nameStartsWith)) { return (
const targetChannels = Array.from(channelsArray).filter(function( element.currencyCode === channelElement.currencyCode &&
channelElement element.id !== channelElement.id
) { );
return ( });
element.currencyCode === channelElement.currencyCode && if (targetChannels[0]) {
element.id !== channelElement.id channels.deleteChannel(element.id, targetChannels[0].id);
); channelsArray.delete(element);
});
if (targetChannels[0]) {
this.channels.deleteChannel(element.id, targetChannels[0].id);
channelsArray.delete(element);
}
} }
}); }
}); });
} });
getDefaultChannel() { }
return this.channels.getChannels().then(resp => { export function getDefaultChannel() {
const channelsArray = resp.body.data.channels; return channels.getChannels().then(resp => {
return (this.defaultChannel = channelsArray.find(function( const channelsArray = resp.body.data.channels;
channelElement return channelsArray.find(function(channelElement) {
) { return channelElement.slug === "default-channel";
return channelElement.slug === "default-channel"; });
})); });
}); }
} export function createChannel({
createChannel({ isActive = true, name, slug = name, currencyCode = "PLN" }) { isActive = true,
return this.channels name,
.createChannel(isActive, name, slug, currencyCode) slug = name,
.then( currencyCode = "PLN"
resp => (this.createdChannel = resp.body.data.channelCreate.channel) }) {
); return channels
} .createChannel(isActive, name, slug, currencyCode)
getCreatedChannel() { .its("body.data.channelCreate.channel");
return this.createdChannel;
}
} }
export default ChannelsUtils;

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( startsWith,
this.collectionsRequest.deleteCollection, "collection"
this.collectionsRequest.getCollections, );
startsWith,
"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) .its("body.data.orders.totalCount");
.then(resp => resp.body.data.orders.totalCount); }
} export function getOrdersReadyForCapture(channelSlug) {
getOrdersReadyForCapture(channelSlug) { return homePage
return this.homePage .getOrdersWithStatus("READY_TO_CAPTURE", channelSlug)
.getOrdersWithStatus("READY_TO_CAPTURE", channelSlug) .its("body.data.orders.totalCount");
.then(resp => resp.body.data.orders.totalCount); }
} export function getProductsOutOfStock(channelSlug) {
getProductsOutOfStock(channelSlug) { return homePage
return this.homePage .getProductsOutOfStock(channelSlug)
.getProductsOutOfStock(channelSlug) .its("body.data.products.totalCount");
.then(resp => resp.body.data.products.totalCount); }
} export function getSalesAmount(channelSlug) {
getSalesAmount(channelSlug) { return homePage
return this.homePage .getSalesForChannel(channelSlug, "TODAY")
.getSalesForChannel(channelSlug, "TODAY") .its("body.data.ordersTotal.gross.amount");
.then(resp => resp.body.data.ordersTotal.gross.amount); }
} export function getTodaysOrders(channelSlug) {
getTodaysOrders(channelSlug) { return homePage
return this.homePage .getOrdersForChannel(channelSlug, "TODAY")
.getOrdersForChannel(channelSlug, "TODAY") .its("body.data.orders.totalCount");
.then(resp => resp.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(); channelSlug,
orderRequest = new Order(); email,
variantsList,
checkout; shippingMethodId
order; ) {
let checkout;
createWaitingForCaptureOrder( return createCheckout(channelSlug, email, variantsList)
channelSlug, .then(checkoutResp => {
email, checkout = checkoutResp;
variantsList, checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
shippingMethodId })
) { .then(() => addPayment(checkout.id))
return this.createCheckout(channelSlug, email, variantsList) .then(() => checkoutRequest.completeCheckout(checkout.id))
.then(() => .then(() => checkout);
this.checkoutRequest.addShippingMethod( }
this.checkout.id, export function createReadyToFulfillOrder(
shippingMethodId customerId,
) shippingMethodId,
) channelId,
.then(() => this.addPayment(this.checkout.id)) variantsList
.then(() => this.checkoutRequest.completeCheckout(this.checkout.id)); ) {
} let order;
createReadyToFulfillOrder( return createDraftOrder(customerId, shippingMethodId, channelId)
customerId, .then(orderResp => {
shippingMethodId, order = orderResp;
channelId, variantsList.forEach(variantElement => {
variantsList orderRequest.addProductToOrder(order.id, variantElement.id);
) { });
return this.createDraftOrder(customerId, shippingMethodId, channelId) })
.then(() => { .then(() => orderRequest.markOrderAsPaid(order.id))
variantsList.forEach(variantElement => { .then(() => orderRequest.completeOrder(order.id));
this.orderRequest.addProductToOrder(this.order.id, variantElement.id); }
}); export function createDraftOrder(customerId, shippingMethodId, channelId) {
}) return orderRequest
.then(() => this.orderRequest.markOrderAsPaid(this.order.id)) .createDraftOrder(customerId, shippingMethodId, channelId)
.then(() => this.orderRequest.completeOrder(this.order.id)); .its("body.data.draftOrderCreate.order");
} }
createDraftOrder(customerId, shippingMethodId, channelId) { export function createCheckout(channelSlug, email, variantsList) {
return this.orderRequest return checkoutRequest
.createDraftOrder(customerId, shippingMethodId, channelId) .createCheckout(channelSlug, email, 1, variantsList)
.then(resp => (this.order = resp.body.data.draftOrderCreate.order)); .its("body.data.checkoutCreate.checkout");
} }
createCheckout(channelSlug, email, variantsList) { export function addPayment(checkoutId) {
return this.checkoutRequest return checkoutRequest.addPayment(
.createCheckout(channelSlug, email, 1, variantsList) checkoutId,
.then(resp => (this.checkout = resp.body.data.checkoutCreate.checkout)); "mirumee.payments.dummy",
} "not-charged"
addPayment(checkoutId) { );
return this.checkoutRequest.addPayment(
checkoutId,
"mirumee.payments.dummy",
"not-charged"
);
}
} }
export default OrdersUtils;

View file

@ -1,152 +1,127 @@
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(); name,
attributeRequest = new Attribute(); channelId,
categoryRequest = new Category(); warehouseId = null,
quantityInWarehouse = 10,
product; productTypeId,
variants; attributeId,
productType; categoryId,
attribute; price = 1,
category; isPublished = true,
isAvailableForPurchase = true,
createProductWithVariant(name, attributeId, productTypeId, categoryId) { visibleInListings = true
return this.createProduct( }) {
attributeId, let product;
name, let variants;
productTypeId, return createProduct(attributeId, name, productTypeId, categoryId)
categoryId .then(productResp => {
).then(() => this.createVariant(this.product.id, name, attributeId)); product = productResp;
} productRequest.updateChannelInProduct({
productId: product.id,
createProductInChannel({ channelId,
name, isPublished,
channelId, isAvailableForPurchase,
warehouseId = null, visibleInListings
quantityInWarehouse = 10,
productTypeId,
attributeId,
categoryId,
price = 1,
isPublished = true,
isAvailableForPurchase = true,
visibleInListings = true
}) {
return this.createProduct(attributeId, name, productTypeId, categoryId)
.then(() =>
this.productRequest.updateChannelInProduct({
productId: this.product.id,
channelId,
isPublished,
isAvailableForPurchase,
visibleInListings
})
)
.then(() => {
this.createVariant({
productId: this.product.id,
sku: name,
warehouseId,
quantityInWarehouse,
channelId,
price
});
}); });
} })
.then(() => {
createTypeAttributeAndCategoryForProduct(name, attributeValues) { createVariant({
return this.createAttribute(name, attributeValues) productId: product.id,
.then(() => this.createTypeProduct(name, this.attribute.id)) sku: name,
.then(() => this.createCategory(name));
}
createAttribute(name, attributeValues) {
return this.attributeRequest
.createAttribute(name, attributeValues)
.then(
resp => (this.attribute = resp.body.data.attributeCreate.attribute)
);
}
createTypeProduct(name, attributeId) {
return this.productRequest
.createTypeProduct(name, attributeId)
.then(
resp =>
(this.productType = resp.body.data.productTypeCreate.productType)
);
}
createCategory(name) {
return this.categoryRequest
.createCategory(name)
.then(resp => (this.category = resp.body.data.categoryCreate.category));
}
createProduct(attributeId, name, productTypeId, categoryId) {
return this.productRequest
.createProduct(attributeId, name, productTypeId, categoryId)
.then(resp => (this.product = resp.body.data.productCreate.product));
}
createVariant({
productId,
sku,
warehouseId,
quantityInWarehouse,
channelId,
price
}) {
return this.productRequest
.createVariant({
productId,
sku,
warehouseId, warehouseId,
quantity: quantityInWarehouse, quantityInWarehouse,
channelId, channelId,
price price
}) });
.then( })
resp => .then(variantsResp => {
(this.variants = variants = variantsResp;
resp.body.data.productVariantBulkCreate.productVariants) return { product, variants };
); });
} }
getCreatedProduct() {
return this.product; export function createTypeAttributeAndCategoryForProduct(
} name,
getCreatedVariants() { attributeValues
return this.variants; ) {
} let attribute;
getProductType() { let productType;
return this.productType; let category;
} return createAttribute(name, attributeValues)
getAttribute() { .then(attributeResp => {
return this.attribute; attribute = attributeResp;
} createTypeProduct(name, attributeResp.id);
getCategory() { })
return this.category; .then(productTypeResp => {
} productType = productTypeResp;
deleteProperProducts(startsWith) { createCategory(name);
const product = new Product(); })
const attribute = new Attribute(); .then(categoryResp => {
const category = new Category(); category = categoryResp;
cy.deleteProperElements( return { attribute, category, productType };
product.deleteProductType, });
product.getProductTypes, }
startsWith, export function createAttribute(name, attributeValues) {
"productType" return attributeRequest
); .createAttribute(name, attributeValues)
cy.deleteProperElements( .its("body.data.attributeCreate.attribute");
attribute.deleteAttribute, }
attribute.getAttributes, export function createTypeProduct(name, attributeId) {
startsWith, return productRequest
"attributes" .createTypeProduct(name, attributeId)
); .its("body.data.productTypeCreate.productType");
cy.deleteProperElements( }
category.deleteCategory, export function createCategory(name) {
category.getCategories, return categoryRequest
startsWith, .createCategory(name)
"categories" .its("body.data.categoryCreate.category");
); }
} export function createProduct(attributeId, name, productTypeId, categoryId) {
return productRequest
.createProduct(attributeId, name, productTypeId, categoryId)
.its("body.data.productCreate.product");
}
export function createVariant({
productId,
sku,
warehouseId,
quantityInWarehouse,
channelId,
price
}) {
return productRequest
.createVariant({
productId,
sku,
warehouseId,
quantity: quantityInWarehouse,
channelId,
price
})
.its("body.data.productVariantBulkCreate.productVariants");
}
export function deleteProductsStartsWith(startsWith) {
cy.deleteElementsStartsWith(
productRequest.deleteProductType,
productRequest.getProductTypes,
startsWith,
"productType"
);
cy.deleteElementsStartsWith(
attributeRequest.deleteAttribute,
attributeRequest.getAttributes,
startsWith,
"attributes"
);
cy.deleteElementsStartsWith(
categoryRequest.deleteCategory,
categoryRequest.getCategories,
startsWith,
"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;
channelId, createShippingRate(name, shippingZone.id);
price })
) .then(sippingMethodResp => {
shippingMethod = sippingMethodResp;
shippingMethodRequest.addChannelToShippingMethod(
shippingMethod.id,
channelId,
price
); );
} })
.then(() => ({ shippingMethod, shippingZone, warehouse }));
createShippingZone(name, country) { }
return this.shippingMethodRequest
.createShippingZone(name, country) export function createShippingZone(name, country) {
.then(resp => { return shippingMethodRequest
this.shippingZone = resp.body.data.shippingZoneCreate.shippingZone; .createShippingZone(name, country)
}); .its("body.data.shippingZoneCreate.shippingZone");
} }
createWarehouse(name, shippingZoneId, address) { export function createWarehouse(name, shippingZoneId, address) {
return this.warehouseRequest return 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) { .createShippingRate(name, shippingZoneId)
return this.shippingMethodRequest .its("body.data.shippingPriceCreate.shippingMethod");
.createShippingRate(name, shippingZoneId) }
.then(
resp => export function deleteShippingStartsWith(startsWith) {
(this.shippingMethod = cy.deleteElementsStartsWith(
resp.body.data.shippingPriceCreate.shippingMethod) shippingMethodRequest.deleteShippingZone,
); shippingMethodRequest.getShippingZones,
} startsWith,
"shippingZONE"
getShippingMethod() { );
return this.shippingMethod; cy.deleteElementsStartsWith(
} warehouseRequest.deleteWarehouse,
warehouseRequest.getWarehouses,
getShippingZone() { startsWith,
return this.shippingZone; "Warehouse"
} );
getWarehouse() {
return this.warehouse;
}
deleteShipping(startsWith) {
const shippingMethod = new ShippingMethod();
const warehouse = new Warehouse();
cy.deleteProperElements(
shippingMethod.deleteShippingZone,
shippingMethod.getShippingZones,
startsWith,
"shippingZONE"
);
cy.deleteProperElements(
warehouse.deleteWarehouse,
warehouse.getWarehouses,
startsWith,
"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
})); }));
}); });
};