diff --git a/cypress/apiRequests/Attribute.js b/cypress/apiRequests/Attribute.js index 1c05d8c19..eec70b621 100644 --- a/cypress/apiRequests/Attribute.js +++ b/cypress/apiRequests/Attribute.js @@ -1,39 +1,39 @@ export function createAttribute(name, attributeValues = ["value"]) { const values = attributeValues.map(element => `{name:"${element}"}`); const mutation = `mutation{ - attributeCreate(input:{ - name:"${name}" - valueRequired:false - type:PRODUCT_TYPE - values: [${values}] - }){ - attribute{ - id - name - values{name} - } - attributeErrors{ - field - message - } - } - }`; + attributeCreate(input:{ + name:"${name}" + valueRequired:false + type:PRODUCT_TYPE + values: [${values}] + }){ + attribute{ + id + name + values{name} + } + attributeErrors{ + field + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function getAttributes(first, search) { const mutation = `query{ - attributes(first:${first}, filter:{ - search:"${search}" - }){ - edges{ - node{ - id - name - } - } - } - }`; + attributes(first:${first}, filter:{ + search:"${search}" + }){ + edges{ + node{ + id + name + } + } + } + }`; return cy .sendRequestWithQuery(mutation) .then(resp => resp.body.data.attributes.edges); @@ -41,12 +41,12 @@ export function getAttributes(first, search) { export function deleteAttribute(attributeId) { const mutation = `mutation{ - attributeDelete(id:"${attributeId}"){ - attributeErrors{ - field - message - } - } - }`; + attributeDelete(id:"${attributeId}"){ + attributeErrors{ + field + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } diff --git a/cypress/apiRequests/Category.js b/cypress/apiRequests/Category.js index 096e45a8b..ea02f4a18 100644 --- a/cypress/apiRequests/Category.js +++ b/cypress/apiRequests/Category.js @@ -1,42 +1,42 @@ export function createCategory(name, slug = name) { const mutation = `mutation{ - categoryCreate(input:{name:"${name}", slug: "${slug}"}){ - productErrors{ - field - message - } - category{ - id - } - } - }`; + categoryCreate(input:{name:"${name}", slug: "${slug}"}){ + productErrors{ + field + message + } + category{ + id + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function getCategories(first, search) { const mutation = `query{ - categories(first:${first}, filter:{ - search:"${search}" - }){ - edges{ - node{ - id - name - } - } - } - }`; + categories(first:${first}, filter:{ + search:"${search}" + }){ + edges{ + node{ + id + name + } + } + } + }`; return cy .sendRequestWithQuery(mutation) .then(resp => resp.body.data.categories.edges); } export function deleteCategory(categoryId) { const mutation = `mutation{ - categoryDelete(id:"${categoryId}"){ - productErrors{ - field - message - } - } - }`; + categoryDelete(id:"${categoryId}"){ + productErrors{ + field + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } diff --git a/cypress/apiRequests/Channels.js b/cypress/apiRequests/Channels.js index 436d9f479..c9780e2b6 100644 --- a/cypress/apiRequests/Channels.js +++ b/cypress/apiRequests/Channels.js @@ -1,50 +1,49 @@ export function 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 - } - } - }`; + channelCreate(input: { + isActive: ${isActive} + name: "${name}" + slug: "${slug}" + currencyCode: "${currencyCode}" + }){ + channel{ + id + name + slug + } + channelErrors{ + code + message + } + } + }`; return cy.sendRequestWithQuery(createChannelMutation); } export function getChannels() { const getChannelsInfoQuery = `query{ - channels{ - name - id - isActive - slug - currencyCode - } + channels{ + name + id + isActive + slug + currencyCode } - `; + }`; return cy.sendRequestWithQuery(getChannelsInfoQuery); } export function deleteChannel(channelId, targetChannelId) { const deleteChannelMutation = `mutation{ - channelDelete(id: "${channelId}", input:{ - targetChannel: "${targetChannelId}" - }){ - channel{ - name - } - channelErrors{ - message - } - } - }`; + channelDelete(id: "${channelId}", input:{ + targetChannel: "${targetChannelId}" + }){ + channel{ + name + } + channelErrors{ + message + } + } + }`; return cy.sendRequestWithQuery(deleteChannelMutation); } diff --git a/cypress/apiRequests/Checkout.js b/cypress/apiRequests/Checkout.js index 5315d82f6..1e1ec147d 100644 --- a/cypress/apiRequests/Checkout.js +++ b/cypress/apiRequests/Checkout.js @@ -9,63 +9,63 @@ export function createCheckout( variantId:"${variant.id}"}` ); const mutation = `mutation{ - checkoutCreate(input:{ - channel:"${channelSlug}" - email:"${email}" - lines: [${lines.join()}] - }){ - checkoutErrors{ - field - message - } - created - checkout{ - id - } - } - }`; + checkoutCreate(input:{ + channel:"${channelSlug}" + email:"${email}" + lines: [${lines.join()}] + }){ + checkoutErrors{ + field + message + } + created + checkout{ + id + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function addShippingMethod(checkoutId, shippingMethodId) { const mutation = `mutation{ - checkoutShippingMethodUpdate(checkoutId:"${checkoutId}", - shippingMethodId:"${shippingMethodId}"){ - checkoutErrors{ - message - field - } - } - }`; + checkoutShippingMethodUpdate(checkoutId:"${checkoutId}", + shippingMethodId:"${shippingMethodId}"){ + checkoutErrors{ + message + field + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function addPayment(checkoutId, gateway, token) { const mutation = `mutation{ - checkoutPaymentCreate(checkoutId:"${checkoutId}", - input:{ - gateway: "${gateway}" - token:"${token}" - }){ - paymentErrors{ - field - message - } - } - }`; + checkoutPaymentCreate(checkoutId:"${checkoutId}", + input:{ + gateway: "${gateway}" + token:"${token}" + }){ + paymentErrors{ + field + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function completeCheckout(checkoutId) { const mutation = `mutation{ - checkoutComplete(checkoutId:"${checkoutId}"){ - order{ - id - } - confirmationNeeded - confirmationData - checkoutErrors{ - field - message - } - } - }`; + checkoutComplete(checkoutId:"${checkoutId}"){ + order{ + id + } + confirmationNeeded + confirmationData + checkoutErrors{ + field + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } diff --git a/cypress/apiRequests/Collections.js b/cypress/apiRequests/Collections.js index b982f0808..d761a892d 100644 --- a/cypress/apiRequests/Collections.js +++ b/cypress/apiRequests/Collections.js @@ -5,30 +5,30 @@ export function getCollections(search) { }` : ""; const query = `query{ - collections(first:100 ${filter}){ - edges{ - node{ - id - name - } - } + collections(first:100 ${filter}){ + edges{ + node{ + id + name } - }`; + } + } + }`; return cy .sendRequestWithQuery(query) .then(resp => resp.body.data.collections.edges); } export function deleteCollection(collectionId) { const mutation = `mutation{ - collectionDelete(id:"${collectionId}"){ - collection{ - id - } - collectionErrors{ - field - message - } - } - }`; + collectionDelete(id:"${collectionId}"){ + collection{ + id + } + collectionErrors{ + field + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } diff --git a/cypress/apiRequests/Customer.js b/cypress/apiRequests/Customer.js index 011110631..783c7b47c 100644 --- a/cypress/apiRequests/Customer.js +++ b/cypress/apiRequests/Customer.js @@ -1,41 +1,40 @@ export function createCustomer(email, customerName, address, isActive = false) { const mutation = ` - mutation{ - customerCreate(input:{ - firstName: "${customerName}" - lastName: "${customerName}" - email: "${email}" - isActive: ${isActive} - defaultBillingAddress: { - companyName: "${address.companyName}" - streetAddress1: "${address.streetAddress1}" - streetAddress2: "${address.streetAddress2}" - city: "${address.city}" - postalCode: "${address.postalCode}" - country: ${address.country} - phone: "${address.phone}" - } - defaultShippingAddress: { - companyName: "${address.companyName}" - streetAddress1: "${address.streetAddress1}" - streetAddress2: "${address.streetAddress2}" - city: "${address.city}" - postalCode: "${address.postalCode}" - country: ${address.country} - phone: "${address.phone}" - } - }){ - user{ - id - email - } - accountErrors{ - code - message - } - } + mutation{ + customerCreate(input:{ + firstName: "${customerName}" + lastName: "${customerName}" + email: "${email}" + isActive: ${isActive} + defaultBillingAddress: { + companyName: "${address.companyName}" + streetAddress1: "${address.streetAddress1}" + streetAddress2: "${address.streetAddress2}" + city: "${address.city}" + postalCode: "${address.postalCode}" + country: ${address.country} + phone: "${address.phone}" + } + defaultShippingAddress: { + companyName: "${address.companyName}" + streetAddress1: "${address.streetAddress1}" + streetAddress2: "${address.streetAddress2}" + city: "${address.city}" + postalCode: "${address.postalCode}" + country: ${address.country} + phone: "${address.phone}" + } + }){ + user{ + id + email + } + accountErrors{ + code + message + } } - `; + }`; return cy.sendRequestWithQuery(mutation); } @@ -54,29 +53,28 @@ export function deleteCustomers(startsWith) { export function deleteCustomer(customerId) { const mutation = `mutation{ - customerDelete(id:"${customerId}"){ - accountErrors{ - code - message - } - } - }`; + customerDelete(id:"${customerId}"){ + accountErrors{ + code + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function getCustomers(startsWith) { const query = `query{ - customers(first:100, filter: { - search: "${startsWith}" - }){ - edges{ - node{ - id - email - } - } - } - } - `; + customers(first:100, filter: { + search: "${startsWith}" + }){ + edges{ + node{ + id + email + } + } + } + }`; return cy.sendRequestWithQuery(query); } diff --git a/cypress/apiRequests/HomePage.js b/cypress/apiRequests/HomePage.js index 36e2f2eb5..da5de89b3 100644 --- a/cypress/apiRequests/HomePage.js +++ b/cypress/apiRequests/HomePage.js @@ -1,34 +1,34 @@ export function getSalesForChannel(channelSlug, period) { const query = `query{ - ordersTotal(period: ${period}, channel:"${channelSlug}"){ - gross{ - amount - } - } - }`; + ordersTotal(period: ${period}, channel:"${channelSlug}"){ + gross{ + amount + } + } + }`; return cy.sendRequestWithQuery(query); } export function getOrdersForChannel(channelSlug, created) { const query = `query{ - orders(created: ${created}, channel:"${channelSlug}"){ - totalCount - } - }`; + orders(created: ${created}, channel:"${channelSlug}"){ + totalCount + } + }`; return cy.sendRequestWithQuery(query); } export function getOrdersWithStatus(status, channelSlug) { const query = `query{ - orders(status: ${status}, channel:"${channelSlug}"){ - totalCount - } - }`; + orders(status: ${status}, channel:"${channelSlug}"){ + totalCount + } + }`; return cy.sendRequestWithQuery(query); } export function getProductsOutOfStock(channelSlug) { const query = `query{ - products(stockAvailability: OUT_OF_STOCK, channel:"${channelSlug}"){ - totalCount - } - }`; + products(stockAvailability: OUT_OF_STOCK, channel:"${channelSlug}"){ + totalCount + } + }`; return cy.sendRequestWithQuery(query); } diff --git a/cypress/apiRequests/Order.js b/cypress/apiRequests/Order.js index 05d46173f..ebfa7c75b 100644 --- a/cypress/apiRequests/Order.js +++ b/cypress/apiRequests/Order.js @@ -1,57 +1,55 @@ export function markOrderAsPaid(orderId) { const mutation = `mutation{ - orderMarkAsPaid(id:"${orderId}"){ - orderErrors{ - message - } - } - }`; + orderMarkAsPaid(id:"${orderId}"){ + orderErrors{ + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function addProductToOrder(orderId, variantId, quantity = 1) { const mutation = `mutation{ - draftOrderLinesCreate(id:"${orderId}", input:{ - quantity:${quantity} - variantId: "${variantId}" - }){ - orderErrors{ - message - } - } - }`; + draftOrderLinesCreate(id:"${orderId}", input:{ + quantity:${quantity} + variantId: "${variantId}" + }){ + orderErrors{ + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function createDraftOrder(customerId, shippingMethodId, channelId) { - const mutation = ` - mutation{ - draftOrderCreate(input:{ - user:"${customerId}" - shippingMethod:"${shippingMethodId}" - channel: "${channelId}" - }){ - orderErrors{ - message - } - order{ - id - } - } - } - `; + const mutation = `mutation{ + draftOrderCreate(input:{ + user:"${customerId}" + shippingMethod:"${shippingMethodId}" + channel: "${channelId}" + }){ + orderErrors{ + message + } + order{ + id + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function completeOrder(orderId) { const mutation = `mutation{ - draftOrderComplete(id:"${orderId}"){ - order{ - id - } - orderErrors{ - message - } - } - }`; + draftOrderComplete(id:"${orderId}"){ + order{ + id + } + orderErrors{ + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } diff --git a/cypress/apiRequests/Product.js b/cypress/apiRequests/Product.js index ca4407536..fadd49c4e 100644 --- a/cypress/apiRequests/Product.js +++ b/cypress/apiRequests/Product.js @@ -7,18 +7,17 @@ export function getFirstProducts(first, search) { }` : ""; const query = `query{ - products(first:${first}${filter}){ - edges{ - node{ - id - name - variants{ - id - } - } - } - } - `; + products(first:${first}${filter}){ + edges{ + node{ + id + name + variants{ + id + } + } + } + }`; return cy .sendRequestWithQuery(query) .then(resp => resp.body.data.products.edges); @@ -32,57 +31,58 @@ export function updateChannelInProduct({ visibleInListings = true }) { const mutation = `mutation{ - productChannelListingUpdate(id:"${productId}", - input:{ - addChannels:{ - channelId:"${channelId}" - isPublished:${isPublished} - isAvailableForPurchase:${isAvailableForPurchase} - visibleInListings:${visibleInListings} - } - }){ - product{ - id - name - } - } - }`; + productChannelListingUpdate(id:"${productId}", + input:{ + addChannels:{ + channelId:"${channelId}" + isPublished:${isPublished} + isAvailableForPurchase:${isAvailableForPurchase} + visibleInListings:${visibleInListings} + } + }){ + product{ + id + name + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function updateChannelPriceInVariant(variantId, channelId) { const mutation = `mutation{ - productVariantChannelListingUpdate(id: "${variantId}", input: { - channelId: "${channelId}" - price: 10 - costPrice: 10 - }){ - productChannelListingErrors{ - message + productVariantChannelListingUpdate(id: "${variantId}", input: { + channelId: "${channelId}" + price: 10 + costPrice: 10 + }){ + productChannelListingErrors{ + message + } } - } -} `; + } `; return cy.sendRequestWithQuery(mutation); } export function createProduct(attributeId, name, productType, category) { const mutation = `mutation{ - productCreate(input:{ - attributes:[{ - id:"${attributeId}" - }] - name:"${name}" - productType:"${productType}" - category:"${category}" - }){ - product{ - id - } - productErrors{ - field - message - } + productCreate(input:{ + attributes:[{ + id:"${attributeId}" + }] + name:"${name}" + productType:"${productType}" + category:"${category}" + }){ + product{ + id + name } - }`; + productErrors{ + field + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } @@ -113,71 +113,71 @@ export function createVariant({ ); const mutation = `mutation{ - productVariantBulkCreate(product: "${productId}", variants: { - attributes: [] - sku: "${sku}" - ${channelListings} - ${stocks} - }) { - productVariants{ - id - name - } - bulkProductErrors{ - field - message - } - } - }`; + productVariantBulkCreate(product: "${productId}", variants: { + attributes: [] + sku: "${sku}" + ${channelListings} + ${stocks} + }) { + productVariants{ + id + name + } + bulkProductErrors{ + field + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function createTypeProduct(name, attributeId, slug = name) { const mutation = `mutation{ - productTypeCreate(input: { - name: "${name}" - slug: "${slug}" - isShippingRequired: true - productAttributes: "${attributeId}" - variantAttributes: "${attributeId}" - }){ - productErrors{ - field - message + productTypeCreate(input: { + name: "${name}" + slug: "${slug}" + isShippingRequired: true + productAttributes: "${attributeId}" + variantAttributes: "${attributeId}" + }){ + productErrors{ + field + message + } + productType{ + id + } } - productType{ - id - } - } -} `; + } `; return cy.sendRequestWithQuery(mutation); } export function deleteProduct(productId) { const mutation = `mutation{ - productDelete(id: "${productId}"){ - productErrors{ - field - message + productDelete(id: "${productId}"){ + productErrors{ + field + message + } } - } -} `; + } `; return cy.sendRequestWithQuery(mutation); } export function getProductTypes(first, search) { const query = `query{ - productTypes(first:${first}, filter:{ - search:"${search}" - }){ - edges{ - node{ - id - name - } + productTypes(first:${first}, filter:{ + search:"${search}" + }){ + edges{ + node{ + id + name } } - }`; + } + }`; return cy .sendRequestWithQuery(query) .then(resp => resp.body.data.productTypes.edges); @@ -185,12 +185,12 @@ export function getProductTypes(first, search) { export function deleteProductType(productTypeId) { const mutation = `mutation{ - productTypeDelete(id:"${productTypeId}"){ - productErrors{ - field - message - } + productTypeDelete(id:"${productTypeId}"){ + productErrors{ + field + message } - }`; + } + }`; return cy.sendRequestWithQuery(mutation); } diff --git a/cypress/apiRequests/Sales.js b/cypress/apiRequests/Sales.js new file mode 100644 index 000000000..e409fb18f --- /dev/null +++ b/cypress/apiRequests/Sales.js @@ -0,0 +1,35 @@ +import { getValueWithDefault } from "./utils/Utils"; + +export function getSales(first, searchQuery) { + const filter = getValueWithDefault( + searchQuery, + `, filter:{ + search:"${searchQuery}" + }` + ); + const query = `query{ + sales(first: + ${first} ${filter}){ + edges{ + node{ + id + name + } + } + } + }`; + return cy + .sendRequestWithQuery(query) + .then(resp => resp.body.data.sales.edges); +} +export function deleteSale(saleId) { + const mutation = `mutation{ + saleDelete(id:"${saleId}"){ + discountErrors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); +} diff --git a/cypress/apiRequests/ShippingMethod.js b/cypress/apiRequests/ShippingMethod.js index ee05f2774..97c449bfe 100644 --- a/cypress/apiRequests/ShippingMethod.js +++ b/cypress/apiRequests/ShippingMethod.js @@ -1,55 +1,49 @@ export function createShippingRate(name, shippingZone) { - const mutation = ` - mutation{ - shippingPriceCreate(input:{ - name: "${name}" - shippingZone: "${shippingZone}" - type: PRICE - }){ - shippingMethod{ - id - } - } - } - `; + const mutation = `mutation{ + shippingPriceCreate(input:{ + name: "${name}" + shippingZone: "${shippingZone}" + type: PRICE + }){ + shippingMethod{ + id + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function createShippingZone(name, country) { - const mutation = ` - mutation{ - shippingZoneCreate(input:{ - name: "${name}" - countries: "${country}" - }){ - shippingZone{ - id - } - } - } - `; + const mutation = `mutation{ + shippingZoneCreate(input:{ + name: "${name}" + countries: "${country}" + }){ + shippingZone{ + id + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function addChannelToShippingMethod(shippingRateId, channelId, price) { - const mutation = ` - mutation{ - shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{ - addChannels: { - channelId:"${channelId}" - price: ${price} - } - }){ - shippingMethod{ - id - } - shippingErrors{ - code - message - } - } - } - `; + const mutation = `mutation{ + shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{ + addChannels: { + channelId:"${channelId}" + price: ${price} + } + }){ + shippingMethod{ + id + } + shippingErrors{ + code + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } diff --git a/cypress/apiRequests/Warehouse.js b/cypress/apiRequests/Warehouse.js index 8dd60a198..2b7457ea8 100644 --- a/cypress/apiRequests/Warehouse.js +++ b/cypress/apiRequests/Warehouse.js @@ -1,55 +1,55 @@ export function 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 - name - } - } - }`; + 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 + name + } + } + }`; return cy.sendRequestWithQuery(mutation); } export function getWarehouses(first, search) { const query = `query{ - warehouses(first:${first}, filter:{ - search:"${search}" - }){ - edges{ - node{ - id - name - } - } - } - }`; + warehouses(first:${first}, filter:{ + search:"${search}" + }){ + edges{ + node{ + id + name + } + } + } + }`; return cy .sendRequestWithQuery(query) .then(resp => resp.body.data.warehouses.edges); } export function deleteWarehouse(warehouseId) { const mutation = `mutation{ - deleteWarehouse(id:"${warehouseId}"){ - warehouseErrors{ - field - message - } - } - }`; + deleteWarehouse(id:"${warehouseId}"){ + warehouseErrors{ + field + message + } + } + }`; return cy.sendRequestWithQuery(mutation); } diff --git a/cypress/apiRequests/storeFront/Collections.js b/cypress/apiRequests/storeFront/Collections.js index 500d59898..57dcab764 100644 --- a/cypress/apiRequests/storeFront/Collections.js +++ b/cypress/apiRequests/storeFront/Collections.js @@ -1,19 +1,19 @@ export function getCollection(collectionId, channelSlug) { const query = `query Collection{ - collection(id: "${collectionId}", channel: "${channelSlug}") { - id - slug - name - products(first:100){ - totalCount - edges{ - node{ - id - name - } - } + collection(id: "${collectionId}", channel: "${channelSlug}") { + id + slug + name + products(first:100){ + totalCount + edges{ + node{ + id + name } } - }`; + } + } + }`; return cy.sendRequestWithQuery(query, "token"); } diff --git a/cypress/apiRequests/storeFront/ProductDetails.js b/cypress/apiRequests/storeFront/ProductDetails.js index ddc69d628..047a867e2 100644 --- a/cypress/apiRequests/storeFront/ProductDetails.js +++ b/cypress/apiRequests/storeFront/ProductDetails.js @@ -1,37 +1,37 @@ export function getProductDetails(productId, channelId) { const query = `fragment BasicProductFields on Product { - id - name + id + name + } + + fragment Price on TaxedMoney { + gross { + amount + currency } - - fragment Price on TaxedMoney { - gross { - amount - currency + } + + fragment ProductVariantFields on ProductVariant { + id + sku + name + pricing { + price { + ...Price } } - - fragment ProductVariantFields on ProductVariant { - id - sku - name - pricing { - price { - ...Price - } + } + + query ProductDetails{ + product(id: "${productId}", channel: "${channelId}") { + ...BasicProductFields + variants { + ...ProductVariantFields } + isAvailable + isAvailableForPurchase + availableForPurchase } - - query ProductDetails{ - product(id: "${productId}", channel: "${channelId}") { - ...BasicProductFields - variants { - ...ProductVariantFields - } - isAvailable - isAvailableForPurchase - availableForPurchase - } - }`; + }`; return cy.sendRequestWithQuery(query, "token"); } diff --git a/cypress/apiRequests/storeFront/Search.js b/cypress/apiRequests/storeFront/Search.js index 5184cecda..c09e7f831 100644 --- a/cypress/apiRequests/storeFront/Search.js +++ b/cypress/apiRequests/storeFront/Search.js @@ -1,17 +1,17 @@ export function searchInShop(searchQuery) { const query = `query SearchProducts { - products(channel: "default-channel", filter:{ - search: "${searchQuery}" - }, first:10){ - totalCount - edges{ - node{ - id - name - } - } + products(channel: "default-channel", filter:{ + search: "${searchQuery}" + }, + first:10){ + totalCount + edges{ + node{ + id + name } - }`; - + } + } + }`; return cy.sendRequestWithQuery(query, "token"); } diff --git a/cypress/elements/catalog/assign-products.js b/cypress/elements/catalog/assign-products.js new file mode 100644 index 000000000..de21cb96b --- /dev/null +++ b/cypress/elements/catalog/assign-products.js @@ -0,0 +1,4 @@ +export const ASSIGN_PRODUCTS_SELECTORS = { + searchInput: "[name='query']", + tableRow: "[data-test-id='assign-product-table-row']" +}; diff --git a/cypress/elements/channels/menage-channel-availability.js b/cypress/elements/channels/menage-channel-availability.js new file mode 100644 index 000000000..d0dd7d04c --- /dev/null +++ b/cypress/elements/channels/menage-channel-availability.js @@ -0,0 +1,16 @@ +export const MENAGE_CHANNEL_AVAILABILITY = { + availableManageButton: + "[data-test-id='channels-availiability-manage-button']", + channelsAvailabilityForm: + "[data-test-id='manage-products-channels-availiability-list']", + channelAvailabilityColumn: + "[data-test='availability'][data-test-availability='true']", + channelAvailabilityList: "ul[role='menu']", + assignedChannels: "[data-test='channel-availability-item']", + publishedRadioButtons: "[name*='isPublished']", + availableForPurchaseRadioButtons: "[name*='isAvailableForPurchase']", + radioButtonsValueTrue: "[value='true']", + radioButtonsValueFalse: "[value='false']", + visibleInListingsButton: "[name*='visibleInListings']", + allChannelsInput: "[name='allChannels']" +}; diff --git a/cypress/elements/discounts/sales.js b/cypress/elements/discounts/sales.js new file mode 100644 index 000000000..2ba52b48d --- /dev/null +++ b/cypress/elements/discounts/sales.js @@ -0,0 +1,11 @@ +export const SALES_SELECTORS = { + createSaleButton: "[data-test-id='create-sale']", + nameInput: "[name='name']", + percentageOption: "[value='PERCENTAGE']", + fixedOption: "[value='FIXED']", + discountValue: "[name='value']", + startDateInput: "[name='startDate']", + saveButton: "[data-test='button-bar-confirm']", + productsTab: "[data-test-id='products-tab']", + assignProducts: "[data-test-id='assign-products']" +}; diff --git a/cypress/elements/shared/button-selectors.js b/cypress/elements/shared/button-selectors.js index 332c54131..66f60a439 100644 --- a/cypress/elements/shared/button-selectors.js +++ b/cypress/elements/shared/button-selectors.js @@ -1,4 +1,5 @@ export const BUTTON_SELECTORS = { back: '[data-test="back"]', - submit: '[data-test="submit"]' + submit: '[data-test="submit"]', + checkbox: "[type='checkbox']" }; diff --git a/cypress/integration/discounts/sales.js b/cypress/integration/discounts/sales.js new file mode 100644 index 000000000..ab0c3f2a9 --- /dev/null +++ b/cypress/integration/discounts/sales.js @@ -0,0 +1,179 @@ +// + +import faker from "faker"; + +import { updateChannelInProduct } from "../../apiRequests/Product"; +import { + assignProducts, + createSale, + discountOptions +} from "../../steps/salesSteps"; +import { urlList } from "../../url/urlList"; +import * as channelsUtils from "../../utils/channelsUtils"; +import * as productsUtils from "../../utils/productsUtils"; +import { deleteSalesStartsWith } from "../../utils/salesUtils"; +import { + createShipping, + deleteShippingStartsWith +} from "../../utils/shippingUtils"; +import { getProductPrice } from "../../utils/storeFront/storeFrontProductUtils"; + +describe("Sales discounts", () => { + const startsWith = "Cy-"; + + let productType; + let attribute; + let category; + let defaultChannel; + let warehouse; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + channelsUtils.deleteChannelsStartsWith(startsWith); + deleteSalesStartsWith(startsWith); + productsUtils.deleteProductsStartsWith(startsWith); + deleteShippingStartsWith(startsWith); + + const name = `${startsWith}${faker.random.number()}`; + productsUtils + .createTypeAttributeAndCategoryForProduct(name) + .then( + ({ + productType: productTypeResp, + attribute: attributeResp, + category: categoryResp + }) => { + productType = productTypeResp; + attribute = attributeResp; + category = categoryResp; + + channelsUtils.getDefaultChannel(); + } + ) + .then(channel => { + defaultChannel = channel; + cy.fixture("addresses"); + }) + .then(addresses => { + createShipping({ + channelId: defaultChannel.id, + name, + address: addresses.plAddress, + price: 100 + }); + }) + .then(({ warehouse: warehouseResp }) => { + warehouse = warehouseResp; + }); + }); + + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest(); + }); + + it("should create percentage discount", () => { + const saleName = `${startsWith}${faker.random.number()}`; + const discountValue = 50; + const productPrice = 100; + + productsUtils + .createProductInChannel({ + name: saleName, + channelId: defaultChannel.id, + warehouseId: warehouse.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + price: productPrice + }) + .then(({ product: productResp }) => { + cy.visit(urlList.sales); + const product = productResp; + createSale({ + saleName, + channelName: defaultChannel.name, + discountValue, + discountOption: discountOptions.PERCENTAGE + }); + assignProducts(product.name); + getProductPrice(product.id, defaultChannel.slug); + }) + .then(price => { + const expectedPrice = (productPrice * discountValue) / 100; + expect(expectedPrice).to.be.eq(price); + }); + }); + + it("should create fixed price discount", () => { + const saleName = `${startsWith}${faker.random.number()}`; + const discountValue = 50; + const productPrice = 100; + + productsUtils + .createProductInChannel({ + name: saleName, + channelId: defaultChannel.id, + warehouseId: warehouse.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + price: productPrice + }) + .then(({ product: productResp }) => { + cy.visit(urlList.sales); + const product = productResp; + createSale({ + saleName, + channelName: defaultChannel.name, + discountValue, + discountOption: discountOptions.FIXED + }); + assignProducts(product.name); + getProductPrice(product.id, defaultChannel.slug); + }) + .then(price => { + const expectedPrice = productPrice - discountValue; + expect(expectedPrice).to.be.eq(price); + }); + }); + + it("should not displayed discount not assign to channel", () => { + const saleName = `${startsWith}${faker.random.number()}`; + let channel; + let product; + const discountValue = 50; + const productPrice = 100; + + channelsUtils + .createChannel({ name: saleName }) + .then(channelResp => (channel = channelResp)); + productsUtils + .createProductInChannel({ + name: saleName, + channelId: defaultChannel.id, + warehouseId: warehouse.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + price: productPrice + }) + .then(({ product: productResp }) => { + product = productResp; + updateChannelInProduct({ + productId: product.id, + channelId: channel.id + }); + }) + .then(() => { + cy.visit(urlList.sales); + createSale({ + saleName, + channelName: channel.name, + discountValue + }); + assignProducts(product.name); + getProductPrice(product.id, defaultChannel.slug); + }) + .then(price => expect(price).to.equal(productPrice)); + }); +}); diff --git a/cypress/steps/salesSteps.js b/cypress/steps/salesSteps.js new file mode 100644 index 000000000..2b00201fb --- /dev/null +++ b/cypress/steps/salesSteps.js @@ -0,0 +1,57 @@ +import { ASSIGN_PRODUCTS_SELECTORS } from "../elements/catalog/assign-products"; +import { MENAGE_CHANNEL_AVAILABILITY } from "../elements/channels/menage-channel-availability"; +import { SALES_SELECTORS } from "../elements/discounts/sales"; +import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; +import { formatDate } from "../support/formatDate"; + +export const discountOptions = { + PERCENTAGE: SALES_SELECTORS.percentageOption, + FIXED: SALES_SELECTORS.fixedOption +}; + +export function createSale({ + saleName, + channelName, + discountValue = 10, + discountOption = discountOptions.PERCENTAGE +}) { + const todaysDate = formatDate(new Date()); + + cy.get(SALES_SELECTORS.createSaleButton) + .click() + .get(SALES_SELECTORS.nameInput) + .type(saleName) + .get(discountOption) + .click() + .get(MENAGE_CHANNEL_AVAILABILITY.availableManageButton) + .click() + .get(MENAGE_CHANNEL_AVAILABILITY.allChannelsInput) + .click() + .get(MENAGE_CHANNEL_AVAILABILITY.channelsAvailabilityForm) + .contains(channelName) + .click() + .get(BUTTON_SELECTORS.submit) + .click() + .get(SALES_SELECTORS.discountValue) + .type(discountValue) + .get(SALES_SELECTORS.startDateInput) + .type(todaysDate); + cy.addAliasToGraphRequest("SaleCreate"); + cy.get(SALES_SELECTORS.saveButton).click(); + cy.wait("@SaleCreate"); +} + +export function assignProducts(productName) { + cy.get(SALES_SELECTORS.productsTab) + .click() + .get(SALES_SELECTORS.assignProducts) + .click() + .get(ASSIGN_PRODUCTS_SELECTORS.searchInput) + .type(productName); + cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, productName) + .find(BUTTON_SELECTORS.checkbox) + .click(); + cy.addAliasToGraphRequest("SaleCataloguesAdd"); + cy.get(BUTTON_SELECTORS.submit).click(); + cy.wait("@SaleCataloguesAdd"); +} diff --git a/cypress/support/formatDate.js b/cypress/support/formatDate.js new file mode 100644 index 000000000..324d7261a --- /dev/null +++ b/cypress/support/formatDate.js @@ -0,0 +1,12 @@ +export function formatDate(date) { + const day = getPeriodValue(date, { day: "2-digit" }); + const month = getPeriodValue(date, { month: "2-digit" }); + const year = getPeriodValue(date, { year: "numeric" }); + + return new Array(year, month, day).join("-"); +} + +function getPeriodValue(date, option) { + const formatter = new Intl.DateTimeFormat("en-us", option); + return formatter.format(date); +} diff --git a/cypress/url/urlList.js b/cypress/url/urlList.js index 995a67ccc..fdfcc7a85 100644 --- a/cypress/url/urlList.js +++ b/cypress/url/urlList.js @@ -6,6 +6,7 @@ export const urlList = { orders: "orders/", products: "products/", warehouses: "warehouses/", + sales: "discounts/sales/", collections: "collections/" }; export const productDetailsUrl = productId => `${urlList.products}${productId}`; diff --git a/cypress/utils/salesUtils.js b/cypress/utils/salesUtils.js new file mode 100644 index 000000000..6178380fe --- /dev/null +++ b/cypress/utils/salesUtils.js @@ -0,0 +1,5 @@ +import { deleteSale, getSales } from "../apiRequests/Sales"; + +export function deleteSalesStartsWith(startsWith) { + cy.deleteElementsStartsWith(deleteSale, getSales, startsWith, "sales"); +} diff --git a/cypress/utils/storeFront/storeFrontProductUtils.js b/cypress/utils/storeFront/storeFrontProductUtils.js index 2d6fde7fa..30eaa73f0 100644 --- a/cypress/utils/storeFront/storeFrontProductUtils.js +++ b/cypress/utils/storeFront/storeFrontProductUtils.js @@ -18,7 +18,7 @@ export const isProductVisibleInSearchResult = (resp, productName) => { ); }; -export const getProductVariants = (productId, channelSlug) => +export const getProductVariants = (productId, channelSlug) => { getProductDetails(productId, channelSlug).then(resp => { const variantsList = resp.body.data.product.variants; return variantsList.map(element => ({ @@ -26,3 +26,9 @@ export const getProductVariants = (productId, channelSlug) => price: element.pricing.price.gross.amount })); }); +}; + +export const getProductPrice = (productId, channelSlug) => + getProductDetails(productId, channelSlug).then( + resp => resp.body.data.product.variants[0].pricing.price.gross.amount + ); diff --git a/src/components/AssignProductDialog/AssignProductDialog.tsx b/src/components/AssignProductDialog/AssignProductDialog.tsx index 10f1431de..d6ac75be9 100644 --- a/src/components/AssignProductDialog/AssignProductDialog.tsx +++ b/src/components/AssignProductDialog/AssignProductDialog.tsx @@ -165,7 +165,10 @@ const AssignProductDialog: React.FC = props => { ); return ( - + product.thumbnail.url)} @@ -202,6 +205,7 @@ const AssignProductDialog: React.FC = props => { { children?: React.ReactNode; isActive: boolean; changeTab: (index: T) => void; + testId?: string; } export function Tab(value: T) { const Component: React.FC> = props => { - const { children, isActive, changeTab } = props; + const { children, isActive, changeTab, testId } = props; const classes = useStyles(props); return ( = props => { description: "section header" })} toolbar={ - diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index 1be228a9e..12af7c718 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -73441,6 +73441,7 @@ exports[`Storyshots Views / Discounts / Sale details collections 1`] = ` Products (4) @@ -74796,6 +74797,7 @@ exports[`Storyshots Views / Discounts / Sale details default 1`] = ` Products (4) @@ -76156,6 +76158,7 @@ exports[`Storyshots Views / Discounts / Sale details form errors 1`] = ` Products (4) @@ -77538,6 +77541,7 @@ exports[`Storyshots Views / Discounts / Sale details loading 1`] = ` Products (…) @@ -78925,6 +78929,7 @@ exports[`Storyshots Views / Discounts / Sale details products 1`] = ` Products (4) @@ -78948,6 +78953,7 @@ exports[`Storyshots Views / Discounts / Sale details products 1`] = ` >