From f8d5593fc3805871d3dcf555e6207ee5b0f6d468 Mon Sep 17 00:00:00 2001 From: Karolina Date: Wed, 17 Mar 2021 11:00:30 +0100 Subject: [PATCH] Saleor 1741 tests for orders (#1011) * first test for draft orders * tests for channels in draft orders * tests for channels in draft orders * tests for channels in draft orders * test for moving draft order to orders * test for orders * test for orders * tests for draft orders * tests for draft orders * tests for draft orders * tests for draft orders * test for moving draft order * tests for orders --- cypress/apiRequests/Order.js | 1 + cypress/elements/orders/orders-selectors.js | 3 +- cypress/integration/orders/orders.js | 116 ++++++++++++++++++ cypress/utils/ordersUtils.js | 27 +++- .../OrderChannelSectionCard.tsx | 2 +- .../__snapshots__/Stories.test.ts.snap | 16 +++ 6 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 cypress/integration/orders/orders.js diff --git a/cypress/apiRequests/Order.js b/cypress/apiRequests/Order.js index ebfa7c75b..fc9aa9009 100644 --- a/cypress/apiRequests/Order.js +++ b/cypress/apiRequests/Order.js @@ -35,6 +35,7 @@ export function createDraftOrder(customerId, shippingMethodId, channelId) { } order{ id + number } } }`; diff --git a/cypress/elements/orders/orders-selectors.js b/cypress/elements/orders/orders-selectors.js index bafa5768c..ac1b301c6 100644 --- a/cypress/elements/orders/orders-selectors.js +++ b/cypress/elements/orders/orders-selectors.js @@ -1,5 +1,6 @@ export const ORDERS_SELECTORS = { orders: "[data-test='submenu-item-label'][data-test-id='orders']", createOrder: "[data-test-id='create-order-button']", - orderRow: "[data-test-id='order-table-row']" + orderRow: "[data-test-id='order-table-row']", + salesChannel: "[data-test-id='order-sales-channel']" }; diff --git a/cypress/integration/orders/orders.js b/cypress/integration/orders/orders.js new file mode 100644 index 000000000..77a0391ed --- /dev/null +++ b/cypress/integration/orders/orders.js @@ -0,0 +1,116 @@ +// +import faker from "faker"; + +import { + createCustomer, + deleteCustomersStartsWith +} from "../../apiRequests/Customer"; +import { ORDERS_SELECTORS } from "../../elements/orders/orders-selectors"; +import { selectChannelInPicker } from "../../steps/channelsSteps"; +import { finalizeDraftOrder } from "../../steps/draftOrderSteps"; +import { urlList } from "../../url/urlList"; +import { getDefaultChannel } from "../../utils/channelsUtils"; +import { createOrder } from "../../utils/ordersUtils"; +import * as productsUtils from "../../utils/productsUtils"; +import { + createShipping, + deleteShippingStartsWith +} from "../../utils/shippingUtils"; + +describe("Orders", () => { + const startsWith = "Cy-"; + const randomName = startsWith + faker.random.number(); + + let customer; + let defaultChannel; + let warehouse; + let shippingMethod; + let variantsList; + + before(() => { + cy.clearSessionData().loginUserViaRequest(); + deleteCustomersStartsWith(startsWith); + deleteShippingStartsWith(startsWith); + productsUtils.deleteProductsStartsWith(startsWith); + + let address; + + getDefaultChannel() + .then(channel => { + defaultChannel = channel; + }) + .then(() => { + cy.fixture("addresses"); + }) + .then(addresses => { + address = addresses.plAddress; + createCustomer(`${randomName}@example.com`, randomName, address, true); + }) + .then(customerResp => { + customer = customerResp.body.data.customerCreate.user; + createShipping({ + channelId: defaultChannel.id, + name: randomName, + address + }); + }) + .then( + ({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => { + shippingMethod = shippingMethodResp; + warehouse = warehouseResp; + productsUtils.createTypeAttributeAndCategoryForProduct(randomName); + } + ) + .then( + ({ + productType: productTypeResp, + attribute: attributeResp, + category: categoryResp + }) => { + productsUtils.createProductInChannel({ + name: randomName, + channelId: defaultChannel.id, + warehouseId: warehouse.id, + productTypeId: productTypeResp.id, + attributeId: attributeResp.id, + categoryId: categoryResp.id + }); + } + ) + .then(({ variants: variantsResp }) => { + variantsList = variantsResp; + }); + }); + + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest(); + }); + + it("should create order with selected channel", () => { + cy.visit(urlList.orders) + .get(ORDERS_SELECTORS.createOrder) + .click(); + selectChannelInPicker(defaultChannel.name); + finalizeDraftOrder(randomName).then(draftOrderNumber => { + cy.visit(urlList.orders); + cy.contains(ORDERS_SELECTORS.orderRow, draftOrderNumber).click(); + cy.contains(ORDERS_SELECTORS.salesChannel, defaultChannel.name).should( + "be.visible" + ); + }); + }); + it("should not be possible to change channel in order", () => { + createOrder({ + customerId: customer.id, + channelId: defaultChannel.id, + shippingMethodId: shippingMethod.id, + variantsList + }).then(order => { + cy.visit(urlList.orders); + cy.contains(ORDERS_SELECTORS.orderRow, order.number).click(); + cy.get(ORDERS_SELECTORS.salesChannel) + .find("[button]") + .should("not.exist"); + }); + }); +}); diff --git a/cypress/utils/ordersUtils.js b/cypress/utils/ordersUtils.js index a9124e553..17c50e3f7 100644 --- a/cypress/utils/ordersUtils.js +++ b/cypress/utils/ordersUtils.js @@ -27,13 +27,34 @@ export function createReadyToFulfillOrder( return createDraftOrder(customerId, shippingMethodId, channelId) .then(orderResp => { order = orderResp; - variantsList.forEach(variantElement => { - orderRequest.addProductToOrder(order.id, variantElement.id); - }); + assignVariantsToOrder(order, variantsList); }) .then(() => orderRequest.markOrderAsPaid(order.id)) .then(() => orderRequest.completeOrder(order.id)); } + +export function createOrder({ + customerId, + shippingMethodId, + channelId, + variantsList +}) { + let order; + return createDraftOrder(customerId, shippingMethodId, channelId) + .then(orderResp => { + order = orderResp; + assignVariantsToOrder(order, variantsList); + }) + .then(() => orderRequest.completeOrder(order.id)) + .then(() => order); +} + +function assignVariantsToOrder(order, variantsList) { + variantsList.forEach(variantElement => { + orderRequest.addProductToOrder(order.id, variantElement.id); + }); +} + export function createDraftOrder(customerId, shippingMethodId, channelId) { return orderRequest .createDraftOrder(customerId, shippingMethodId, channelId) diff --git a/src/orders/components/OrderChannelSectionCard/OrderChannelSectionCard.tsx b/src/orders/components/OrderChannelSectionCard/OrderChannelSectionCard.tsx index 5e6887713..de3e3aafd 100644 --- a/src/orders/components/OrderChannelSectionCard/OrderChannelSectionCard.tsx +++ b/src/orders/components/OrderChannelSectionCard/OrderChannelSectionCard.tsx @@ -14,7 +14,7 @@ export const OrderChannelSectionCard: React.FC = ( const intl = useIntl(); return ( - +