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 (
-
+