diff --git a/cypress/api/Product.js b/cypress/api/Product.js deleted file mode 100644 index bbffa4312..000000000 --- a/cypress/api/Product.js +++ /dev/null @@ -1,55 +0,0 @@ -class Product { - getFirstProducts(first) { - const query = `query{ - products(first:${first}){ - edges{ - node{ - id - name - variants{ - id - } - } - } - } - } - `; - return cy.sendRequestWithQuery(query); - } - - updateChannelInProduct(productId, channelId) { - const mutation = `mutation{ - productChannelListingUpdate(id:"${productId}", input:{ - addChannels:{ - channelId:"${channelId}" - isPublished: true - isAvailableForPurchase:true - visibleInListings:true - } - }){ - product{ - id - name - } - } - }`; - return cy.sendRequestWithQuery(mutation); - } - - updateChannelPriceInVariant(variantId, channelId) { - const mutation = `mutation{ - productVariantChannelListingUpdate(id: "${variantId}", input:{ - channelId: "${channelId}" - price: 10 - costPrice: 10 - }){ - productChannelListingErrors{ - message - } - } - }`; - return cy.sendRequestWithQuery(mutation); - } -} - -export default Product; diff --git a/cypress/apiRequests/Attribute.js b/cypress/apiRequests/Attribute.js new file mode 100644 index 000000000..a7253f8b8 --- /dev/null +++ b/cypress/apiRequests/Attribute.js @@ -0,0 +1,49 @@ +class Attribute { + createAttribute(name) { + const mutation = `mutation{ + attributeCreate(input:{ + name:"${name}" + valueRequired:false + type:PRODUCT_TYPE + }){ + attribute{ + id + } + attributeErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + + getAttributes(first, search) { + const mutation = `query{ + attributes(first:${first}, filter:{ + search:"${search}" + }){ + edges{ + node{ + id + name + } + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + + deleteAttribute(attributeId) { + const mutation = `mutation{ + attributeDelete(id:"${attributeId}"){ + attributeErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } +} +export default Attribute; diff --git a/cypress/apiRequests/Category.js b/cypress/apiRequests/Category.js new file mode 100644 index 000000000..7ea65eb7a --- /dev/null +++ b/cypress/apiRequests/Category.js @@ -0,0 +1,43 @@ +class Category { + createCategory(name, slug = name) { + const mutation = `mutation{ + categoryCreate(input:{name:"${name}", slug: "${slug}"}){ + productErrors{ + field + message + } + category{ + id + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + getCategories(first, search) { + const mutation = `query{ + categories(first:${first}, filter:{ + search:"${search}" + }){ + edges{ + node{ + id + name + } + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + deleteCategory(categoryId) { + const mutation = `mutation{ + categoryDelete(id:"${categoryId}"){ + productErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } +} +export default Category; diff --git a/cypress/apiRequests/Channels.js b/cypress/apiRequests/Channels.js new file mode 100644 index 000000000..9afa7cc6b --- /dev/null +++ b/cypress/apiRequests/Channels.js @@ -0,0 +1,74 @@ +class Channels { + createChannel(isActive, name, slug, currencyCode) { + const createChannelMutation = `mutation{ + channelCreate(input: { + isActive: ${isActive} + name: "${name}" + slug: "${slug}" + currencyCode: "${currencyCode}" + }){ + channel{ + id + name + slug + } + channelErrors{ + code + message + } + } + }`; + return cy.sendRequestWithQuery(createChannelMutation); + } + + deleteTestChannels(nameStartsWith) { + const getChannelsInfoQuery = `query{ + channels{ + name + id + isActive + slug + currencyCode + } + } + `; + cy.sendRequestWithQuery(getChannelsInfoQuery).then(resp => { + const channels = new Set(resp.body.data.channels); + if (channels) { + channels.forEach(element => { + if (element.name.startsWith(nameStartsWith)) { + const targetChannels = Array.from(channels).filter(function( + channel + ) { + return ( + element.currencyCode === channel.currencyCode && + element.id !== channel.id + ); + }); + if (targetChannels[0]) { + this.deleteChannel(element.id, targetChannels[0].id); + channels.delete(element); + } + } + }); + } + }); + } + + deleteChannel(channelId, targetChennelId) { + const deleteChannelMutation = `mutation{ + channelDelete(id: "${channelId}", input:{ + targetChannel: "${targetChennelId}" + }){ + channel{ + name + } + channelErrors{ + message + } + } + }`; + return cy.sendRequestWithQuery(deleteChannelMutation); + } +} +export default Channels; diff --git a/cypress/apiRequests/Checkout.js b/cypress/apiRequests/Checkout.js new file mode 100644 index 000000000..ca63560f4 --- /dev/null +++ b/cypress/apiRequests/Checkout.js @@ -0,0 +1,70 @@ +class Checkout { + createCheckout(channelSlug, email, productQuantity, variantsList) { + const lines = []; + variantsList.forEach(variant => { + lines.push(`{quantity:${productQuantity} + variantId:"${variant.id}"}`); + }); + const mutation = `mutation{ + checkoutCreate(input:{ + channel:"${channelSlug}" + email:"${email}" + lines: [${lines.join()}] + }){ + checkoutErrors{ + field + message + } + created + checkout{ + id + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + addShippingMethod(checkoutId, shippingMethodId) { + const mutation = `mutation{ + checkoutShippingMethodUpdate(checkoutId:"${checkoutId}", + shippingMethodId:"${shippingMethodId}"){ + checkoutErrors{ + message + field + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + addPayment(checkoutId, gateway, token) { + const mutation = `mutation{ + checkoutPaymentCreate(checkoutId:"${checkoutId}", + input:{ + gateway: "${gateway}" + token:"${token}" + }){ + paymentErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + compliteCheckout(checkoutId) { + const mutation = `mutation{ + checkoutComplete(checkoutId:"${checkoutId}"){ + order{ + id + } + confirmationNeeded + confirmationData + checkoutErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } +} +export default Checkout; diff --git a/cypress/api/Customer.js b/cypress/apiRequests/Customer.js similarity index 99% rename from cypress/api/Customer.js rename to cypress/apiRequests/Customer.js index c9beb7042..336dbf698 100644 --- a/cypress/api/Customer.js +++ b/cypress/apiRequests/Customer.js @@ -28,6 +28,7 @@ export class Customer { }){ user{ id + email } accountErrors{ code diff --git a/cypress/api/Order.js b/cypress/apiRequests/Order.js similarity index 96% rename from cypress/api/Order.js rename to cypress/apiRequests/Order.js index 571f27fb0..0005d344a 100644 --- a/cypress/api/Order.js +++ b/cypress/apiRequests/Order.js @@ -7,7 +7,7 @@ class Order { } } }`; - cy.sendRequestWithQuery(mutation); + return cy.sendRequestWithQuery(mutation); } addProductToOrder(orderId, variantId, quantity = 1) { diff --git a/cypress/apiRequests/Product.js b/cypress/apiRequests/Product.js new file mode 100644 index 000000000..b747d238f --- /dev/null +++ b/cypress/apiRequests/Product.js @@ -0,0 +1,178 @@ +class Product { + getFirstProducts(first, search) { + let filter = ""; + if (search) { + filter = `, filter:{ + search:"${search}" + }`; + } + const query = `query{ + products(first:${first}${filter}){ + edges{ + node{ + id + name + variants{ + id + } + } + } + } + } + `; + return cy.sendRequestWithQuery(query); + } + + updateChannelInProduct(productId, channelId) { + const mutation = `mutation{ + productChannelListingUpdate(id:"${productId}", + input:{ + addChannels:{ + channelId:"${channelId}" + isPublished:true + isAvailableForPurchase:true + } + }){ + product{ + id + name + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + + updateChannelPriceInVariant(variantId, channelId) { + const mutation = `mutation{ + productVariantChannelListingUpdate(id: "${variantId}", input:{ + channelId: "${channelId}" + price: 10 + costPrice: 10 + }){ + productChannelListingErrors{ + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + createProduct(attributeId, name, productType, category) { + const mutation = `mutation{ + productCreate(input:{ + attributes:[{ + id:"${attributeId}" + }] + name:"${name}" + productType:"${productType}" + category:"${category}" + }){ + product{ + id + } + productErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + + createVariant( + productId, + sku, + warehouseId, + quantity, + channelId, + price = 1, + costPrice = 1 + ) { + const mutation = `mutation{ + productVariantBulkCreate(product:"${productId}", variants:{ + attributes:[] + sku:"${sku}" + channelListings:{ + channelId:"${channelId}" + price:"${price}" + costPrice:"${costPrice}" + } + stocks:{ + warehouse:"${warehouseId}" + quantity:${quantity} + } + }){ + productVariants{ + id + name + } + bulkProductErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + + createTypeProduct(name, attributeId, slug = name) { + const mutation = `mutation{ + productTypeCreate(input:{ + name:"${name}" + slug: "${slug}" + isShippingRequired:true + productAttributes:"${attributeId}" + }){ + productErrors{ + field + message + } + productType{ + id + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + + deleteProduct(productId) { + const mutation = `mutation{ + productDelete(id:"${productId}"){ + productErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + + getProductTypes(first, search) { + const query = `query{ + productTypes(first:${first}, filter:{ + search:"${search}" + }){ + edges{ + node{ + id + name + } + } + } + }`; + return cy.sendRequestWithQuery(query); + } + + deleteProductType(productTypeId) { + const mutation = `mutation{ + productTypeDelete(id:"${productTypeId}"){ + productErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } +} + +export default Product; diff --git a/cypress/api/ShippingMethod.js b/cypress/apiRequests/ShippingMethod.js similarity index 80% rename from cypress/api/ShippingMethod.js rename to cypress/apiRequests/ShippingMethod.js index 179f1b824..93ecb8f80 100644 --- a/cypress/api/ShippingMethod.js +++ b/cypress/apiRequests/ShippingMethod.js @@ -32,13 +32,13 @@ class ShippingMethod { return cy.sendRequestWithQuery(mutation); } - addChannelToShippingMethod(shippingRateId, channelId) { + addChannelToShippingMethod(shippingRateId, channelId, price) { const mutation = ` mutation{ shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{ addChannels: { channelId:"${channelId}" - price:10 + price: ${price} } }){ shippingMethod{ @@ -54,19 +54,6 @@ class ShippingMethod { return cy.sendRequestWithQuery(mutation); } - deleteShippingZones(startsWith) { - this.getShippingZones().then(resp => { - if (resp.body.data.shippingZones) { - const shippingZone = resp.body.data.shippingZones.edges; - shippingZone.forEach(element => { - if (element.node.name.includes(startsWith)) { - this.deleteShippingZone(element.node.id); - } - }); - } - }); - } - deleteShippingZone(shippingZoneId) { const mutation = `mutation{ shippingZoneDelete(id:"${shippingZoneId}"){ diff --git a/cypress/apiRequests/Warehouse.js b/cypress/apiRequests/Warehouse.js new file mode 100644 index 000000000..478d28726 --- /dev/null +++ b/cypress/apiRequests/Warehouse.js @@ -0,0 +1,55 @@ +class Warehouse { + createWarehouse(name, shippingZone, address, slug = name) { + const mutation = `mutation{ + createWarehouse(input:{ + name:"${name}" + slug:"${slug}" + shippingZones:"${shippingZone}" + address:{ + streetAddress1: "${address.streetAddress1}" + streetAddress2: "${address.streetAddress2}" + city: "${address.city}" + postalCode: "${address.postalCode}" + country: ${address.country} + phone: "${address.phone}" + } + }){ + warehouseErrors{ + field + message + } + warehouse{ + id + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } + getWarehouses(first, search) { + const query = `query{ + warehouses(first:${first}, filter:{ + search:"${search}" + }){ + edges{ + node{ + id + name + } + } + } + }`; + return cy.sendRequestWithQuery(query); + } + deleteWarehouse(warehouseId) { + const mutation = `mutation{ + deleteWarehouse(id:"${warehouseId}"){ + warehouseErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); + } +} +export default Warehouse; diff --git a/cypress/elements/header/header-selectors.js b/cypress/elements/header/header-selectors.js new file mode 100644 index 000000000..935421c34 --- /dev/null +++ b/cypress/elements/header/header-selectors.js @@ -0,0 +1,4 @@ +export const HEADER_SELECTORS = { + channelSelect: "[data-test-id='app-channel-select']", + channelSelectList: "[class*='MuiMenu-paper']" +}; diff --git a/cypress/fixtures/addresses.json b/cypress/fixtures/addresses.json index 742bd227e..08fad0466 100644 --- a/cypress/fixtures/addresses.json +++ b/cypress/fixtures/addresses.json @@ -7,6 +7,7 @@ "postalCode": "53-346", "country": "PL", "countryArea": "Dolny Śląsk", - "phone": "123456787" + "phone": "123456787", + "currency": "PLN" } } \ No newline at end of file diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json deleted file mode 100644 index da18d9352..000000000 --- a/cypress/fixtures/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Using fixtures to represent data", - "email": "hello@cypress.io", - "body": "Fixtures are a great way to mock data for responses to routes" -} \ No newline at end of file diff --git a/cypress/integration/dashboard.js b/cypress/integration/dashboard.js index 44213df2e..4251afa72 100644 --- a/cypress/integration/dashboard.js +++ b/cypress/integration/dashboard.js @@ -1,23 +1,29 @@ import faker from "faker"; -import Customer from "../api/Customer"; -import Order from "../api/Order"; -import Product from "../api/Product"; -import ShippingMethod from "../api/ShippingMethod"; +import Channels from "../apiRequests/Channels"; +import Customer from "../apiRequests/Customer"; import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors"; +import { HEADER_SELECTORS } from "../elements/header/header-selectors"; +import OrdersUtils from "../utils/ordersUtils"; +import ProductsUtils from "../utils/productsUtils"; +import ShippingUtils from "../utils/shippingUtils"; // describe("User authorization", () => { const startsWith = "Cy-"; const customer = new Customer(); - const product = new Product(); - const order = new Order(); - const shippingMethod = new ShippingMethod(); + const channels = new Channels(); + const productsUtils = new ProductsUtils(); + const shippingUtils = new ShippingUtils(); + const ordersUtils = new OrdersUtils(); before(() => { + cy.clearSessionData().loginUserViaRequest(); customer.deleteCustomers(startsWith); - shippingMethod.deleteShippingZones(startsWith); + shippingUtils.deleteShipping(startsWith); + productsUtils.deleteProducts(startsWith); + channels.deleteTestChannels(startsWith); }); beforeEach(() => { @@ -36,84 +42,87 @@ describe("User authorization", () => { }); it("should correct amount of orders be displayed", () => { - faker = require("faker"); const randomName = startsWith + faker.random.number(); const randomEmail = randomName + "@example.com"; - product.getFirstProducts(3).then(productsResp => { - const productsList = productsResp.body.data.products.edges; - productsList.forEach(productElement => { - product.updateChannelInProduct( - "Q2hhbm5lbDoxNzk=", - productElement.node.id - ); - const variants = productElement.node.variants; - variants.forEach(variant => { - product.updateChannelPriceInVariant(variant.id, "Q2hhbm5lbDoxNzk="); + const randomNameProductOutOfStock = `${startsWith}${faker.random.number()}`; + const shippingPrice = 12; + const productPrice = 22; + cy.fixture("addresses").then(json => { + channels + .createChannel(true, randomName, randomName, json.plAddress.currency) + .then(channelsResp => { + const channelId = channelsResp.body.data.channelCreate.channel.id; + const channelSlug = channelsResp.body.data.channelCreate.channel.slug; + customer + .createCustomer(randomEmail, randomName, json.plAddress) + .then(resp => { + const customerId = resp.body.data.customerCreate.user.id; + const customerEmail = resp.body.data.customerCreate.user.email; + shippingUtils + .createShipping( + channelId, + randomName, + json.plAddress, + shippingPrice + ) + .then(() => { + const shippingId = shippingUtils.getShippingMethodId(); + const warehouseId = shippingUtils.getWarehouseId(); + productsUtils + .createTypeAttributeAndCategoryForProduct(randomName) + .then(() => { + const productTypeId = productsUtils.getProductTypeId(); + const attributeId = productsUtils.getAttributeId(); + const categoryId = productsUtils.getCategoryId(); + productsUtils + .createProductInChannel( + randomName, + channelId, + warehouseId, + 10, + productTypeId, + attributeId, + categoryId, + productPrice + ) + .then(() => { + const variantsList = productsUtils.getCreatedVariants(); + ordersUtils.createReadyToFullfillOrder( + customerId, + shippingId, + channelId, + variantsList + ); + ordersUtils.createWaitingForCaptureOrder( + channelSlug, + customerEmail, + variantsList, + shippingId + ); + }); + productsUtils.createProductInChannel( + randomNameProductOutOfStock, + channelId, + warehouseId, + 0, + productTypeId, + attributeId, + categoryId, + productPrice + ); + }); + }); + }); }); - }); - cy.fixture("addresses").then(json => { - customer - .createCustomer(randomEmail, randomName, json.plAddress) - .as("createCustomerResponse") - .then(resp => { - const customerId = resp.body.data.customerCreate.user.id; - shippingMethod - .createShippingZone(randomName, "PL") - .then(shippingZoneResp => { - shippingMethod - .createShippingRate( - randomName, - shippingZoneResp.body.data.shippingZoneCreate.shippingZone - .id - ) - .then(rateResp => { - const shippingMethodId = - rateResp.body.data.shippingPriceCreate.shippingMethod.id; - shippingMethod - .addChannelToShippingMethod( - shippingMethodId, - "Q2hhbm5lbDoxNzk=" - ) - .then(shippingMethodResp => { - createReadyToFullfillOrder( - customerId, - shippingMethodId, - "Q2hhbm5lbDoxNzk=", - productsList - ); - }); - }); - }); - }); - }); }); cy.visit("/"); - softAssertMatch(DASHBOARD_SELECTORS.orders, /^0/); - softAssertMatch(DASHBOARD_SELECTORS.ordersReadyToFulfill, /^Brak/); - softAssertMatch(DASHBOARD_SELECTORS.paymentsWaitingForCapture, /^Brak/); - softAssertMatch(DASHBOARD_SELECTORS.productsOutOfStock, /^Brak/); + cy.get(HEADER_SELECTORS.channelSelect) + .click() + .get(HEADER_SELECTORS.channelSelectList) + .contains(randomName) + .click(); }); - function createReadyToFullfillOrder( - customerId, - shippingMethodId, - channelId, - productsList - ) { - order - .createDraftOrder(customerId, shippingMethodId, channelId) - .then(draftOrderResp => { - const orderId = draftOrderResp.body.data.draftOrderCreate.order.id; - productsList.forEach(productElement => { - productElement.node.variants.forEach(variantElement => { - order.addProductToOrder(orderId, variantElement.id); - }); - }); - order.markOrderAsPaid(orderId); - order.completeOrder(orderId); - }); - } - function softAssertVisibility(selector) { cy.get(selector).then(element => chai.softExpect(element).to.be.visible); } diff --git a/cypress/utils/ordersUtils.js b/cypress/utils/ordersUtils.js new file mode 100644 index 000000000..dad9ebc29 --- /dev/null +++ b/cypress/utils/ordersUtils.js @@ -0,0 +1,46 @@ +import Checkout from "../apiRequests/Checkout"; +import Order from "../apiRequests/Order"; + +class OrdersUtils { + createWaitingForCaptureOrder( + channelSlug, + email, + variantsList, + shippingMethodId + ) { + const checkout = new Checkout(); + return checkout + .createCheckout(channelSlug, email, 1, variantsList) + .then(createCheckoutResp => { + const checkoutId = + createCheckoutResp.body.data.checkoutCreate.checkout.id; + return checkout + .addShippingMethod(checkoutId, shippingMethodId) + .then(() => + checkout + .addPayment(checkoutId, "mirumee.payments.dummy", "not-charged") + .then(() => checkout.compliteCheckout(checkoutId)) + ); + }); + } + createReadyToFullfillOrder( + customerId, + shippingMethodId, + channelId, + variantsList + ) { + const order = new Order(); + return order + .createDraftOrder(customerId, shippingMethodId, channelId) + .then(draftOrderResp => { + const orderId = draftOrderResp.body.data.draftOrderCreate.order.id; + variantsList.forEach(variantElement => { + order.addProductToOrder(orderId, variantElement.id); + }); + return order + .markOrderAsPaid(orderId) + .then(() => order.completeOrder(orderId)); + }); + } +} +export default OrdersUtils; diff --git a/cypress/utils/productsUtils.js b/cypress/utils/productsUtils.js new file mode 100644 index 000000000..d02efde08 --- /dev/null +++ b/cypress/utils/productsUtils.js @@ -0,0 +1,124 @@ +import Attribute from "../apiRequests/Attribute"; +import Category from "../apiRequests/Category"; +import Product from "../apiRequests/Product"; + +class ProductsUtils { + createdVariantId; + productTypeId; + attributeId; + categoryId; + + updateChannelInProduct(productsList, channelId) { + const product = new Product(); + productsList.forEach(productElement => { + product.updateChannelInProduct(productElement.node.id, channelId); + const variants = productElement.node.variants; + variants.forEach(variant => { + product.updateChannelPriceInVariant(variant.id, channelId); + }); + }); + } + createProductInChannel( + name, + channelId, + warehouseId, + quantityInWarehouse, + productTypeId, + attributeId, + categoryId, + price + ) { + const product = new Product(); + return product + .createProduct(attributeId, name, productTypeId, categoryId) + .then(createProductResp => { + const productId = createProductResp.body.data.productCreate.product.id; + return product.updateChannelInProduct(productId, channelId).then(() => + product + .createVariant( + productId, + name, + warehouseId, + quantityInWarehouse, + channelId, + price + ) + .then(createVariantResp => { + this.createdVariantId = + createVariantResp.body.data.productVariantBulkCreate.productVariants; + }) + ); + }); + } + + createTypeAttributeAndCategoryForProduct(name) { + const attribute = new Attribute(); + const category = new Category(); + const product = new Product(); + return attribute.createAttribute(name).then(createAttributeResp => { + this.attributeId = + createAttributeResp.body.data.attributeCreate.attribute.id; + return product + .createTypeProduct(name, this.attributeId) + .then(createTypeProductResp => { + this.productTypeId = + createTypeProductResp.body.data.productTypeCreate.productType.id; + return category.createCategory(name).then(categoryResp => { + this.categoryId = categoryResp.body.data.categoryCreate.category.id; + }); + }); + }); + } + + getCreatedVariants() { + return this.createdVariantId; + } + getProductTypeId() { + return this.productTypeId; + } + getAttributeId() { + return this.attributeId; + } + getCategoryId() { + return this.categoryId; + } + + deleteProducts(startsWith) { + const product = new Product(); + const attribute = new Attribute(); + const category = new Category(); + product.getProductTypes(100, startsWith).then(resp => { + const productTypes = resp.body.data.productTypes.edges; + productTypes.forEach(productType => { + if (productType.node.name.includes(startsWith)) { + product.deleteProductType(productType.node.id); + } + }); + }); + attribute.getAttributes(100, startsWith).then(resp => { + const attributes = resp.body.data.attributes.edges; + attributes.forEach(attributeElement => { + if (attributeElement.node.name.includes(startsWith)) { + attribute.deleteAttribute(attributeElement.node.id); + } + }); + }); + category.getCategories(100, startsWith).then(resp => { + const categories = resp.body.data.categories.edges; + categories.forEach(categoryElement => { + if (categoryElement.node.name.includes(startsWith)) { + category.deleteCategory(categoryElement.node.id); + } + }); + }); + product.getFirstProducts(100, startsWith).then(getProductResp => { + const products = getProductResp.body.data.products.edges; + products.forEach(productElement => { + if (productElement.node.name.includes(startsWith)) { + product.deleteProducts(productElement.node.id); + } + }); + }); + } +} +export default productsUtils; diff --git a/cypress/utils/shippingUtils.js b/cypress/utils/shippingUtils.js new file mode 100644 index 000000000..5806ac82d --- /dev/null +++ b/cypress/utils/shippingUtils.js @@ -0,0 +1,71 @@ +import ShippingMethod from "../apiRequests/ShippingMethod"; +import Warehouse from "../apiRequests/Warehouse"; +class ShippingUtils { + shippingMethodId; + shippingZoneId; + warehouseId; + + createShipping(channelId, name, address, price) { + const shippingMethod = new ShippingMethod(); + const warehouse = new Warehouse(); + return shippingMethod + .createShippingZone(name, address.country) + .then(shippingZoneResp => { + this.shippingZoneId = + shippingZoneResp.body.data.shippingZoneCreate.shippingZone.id; + return warehouse + .createWarehouse(name, this.shippingZoneId, address) + .then(createWarehouseResp => { + this.warehouseId = + createWarehouseResp.body.data.createWarehouse.warehouse.id; + return shippingMethod + .createShippingRate(name, this.shippingZoneId) + .then(rateResp => { + this.shippingMethodId = + rateResp.body.data.shippingPriceCreate.shippingMethod.id; + return shippingMethod.addChannelToShippingMethod( + this.shippingMethodId, + channelId, + price + ); + }); + }); + }); + } + + getShippingMethodId() { + return this.shippingMethodId; + } + + getShippingZoneId() { + return this.shippingZoneId; + } + + getWarehouseId() { + return this.warehouseId; + } + + deleteShipping(startsWith) { + const shippingMethod = new ShippingMethod(); + const warehouse = new Warehouse(); + shippingMethod.getShippingZones().then(resp => { + if (resp.body.data.shippingZones) { + const shippingZone = resp.body.data.shippingZones.edges; + shippingZone.forEach(element => { + if (element.node.name.includes(startsWith)) { + shippingMethod.deleteShippingZone(element.node.id); + } + }); + } + }); + warehouse.getWarehouses(100, startsWith).then(resp => { + const warehouses = resp.body.data.warehouses.edges; + warehouses.forEach(warehouseElement => { + if (warehouseElement.node.name.includes(startsWith)) { + warehouse.deleteWarehouse(warehouseElement.node.id); + } + }); + }); + } +} +export default ShippingUtils;