diff --git a/cypress/e2e/apps.js b/cypress/e2e/apps.js index fdaf90037..b3c28b3e3 100644 --- a/cypress/e2e/apps.js +++ b/cypress/e2e/apps.js @@ -10,10 +10,25 @@ import { BUTTON_SELECTORS } from "../elements/shared/button-selectors"; import { appDetailsUrl, urlList } from "../fixtures/urlList"; import { ONE_PERMISSION_USERS } from "../fixtures/users"; import { createApp, getApp, updateApp } from "../support/api/requests/Apps"; +import { + addShippingMethod, + createCheckout, + orderCreateFromCheckout, +} from "../support/api/requests/Checkout"; import { createVoucher } from "../support/api/requests/Discounts/Vouchers"; import { createGiftCard } from "../support/api/requests/GiftCard"; import { deleteAppsStartsWith } from "../support/api/utils/appUtils"; import { getDefaultChannel } from "../support/api/utils/channelsUtils"; +import { getShippingMethodIdFromCheckout } from "../support/api/utils/ordersUtils"; +import { + createProductInChannel, + createTypeAttributeAndCategoryForProduct, + deleteProductsStartsWith, +} from "../support/api/utils/products/productsUtils"; +import { + createShipping, + deleteShippingStartsWith, +} from "../support/api/utils/shippingUtils"; import { discountOptions } from "../support/pages/discounts/vouchersPage"; describe("As a staff user I want to manage apps", () => { @@ -22,16 +37,54 @@ describe("As a staff user I want to manage apps", () => { let createdApp; let defaultChannel; + let address; + let warehouse; + let shippingMethod; + let variantsList; + let checkout; + const email = `example@example.com`; before(() => { cy.clearSessionData().loginUserViaRequest(); deleteAppsStartsWith(startsWith); + deleteProductsStartsWith(startsWith); + deleteShippingStartsWith(startsWith); + createApp(name, "MANAGE_APPS").then(app => { createdApp = app; }); - getDefaultChannel().then(channel => { - defaultChannel = channel; - }); + cy.fixture("addresses") + .then(addresses => { + address = addresses.usAddress; + getDefaultChannel(); + }) + .then(channelResp => { + defaultChannel = channelResp; + createShipping({ + channelId: defaultChannel.id, + name, + address, + price: 10, + }); + }) + .then( + ({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => { + warehouse = warehouseResp; + shippingMethod = shippingMethodResp; + }, + ); + createTypeAttributeAndCategoryForProduct({ name }) + .then(({ productType, attribute, category }) => { + createProductInChannel({ + name, + channelId: defaultChannel.id, + warehouseId: warehouse.id, + productTypeId: productType.id, + attributeId: attribute.id, + categoryId: category.id, + }); + }) + .then(({ variantsList: variants }) => (variantsList = variants)); }); beforeEach(() => { @@ -157,4 +210,36 @@ describe("As a staff user I want to manage apps", () => { }); }, ); + + it( + "should be able to use app to create order from checkout. TC: SALEOR_3005", + { tags: ["@app", "@allEnv", "@stable"] }, + () => { + const token = createdApp.authToken; + + cy.clearSessionData().loginUserViaRequest(); + updateApp(createdApp.app.id, "HANDLE_CHECKOUTS"); + + cy.clearSessionData(); + + createCheckout({ + channelSlug: defaultChannel.slug, + email, + variantsList, + address, + billingAddress: address, + auth: "token", + }).then(({ checkout: checkoutResp }) => { + const shippingMethodId = getShippingMethodIdFromCheckout( + checkoutResp, + shippingMethod.name, + ); + checkout = checkoutResp; + addShippingMethod(checkout.id, shippingMethodId); + orderCreateFromCheckout(checkout.id, token).then(resp => { + expect(resp.id).to.be.not.empty; + }); + }); + }, + ); }); diff --git a/cypress/support/api/requests/Checkout.js b/cypress/support/api/requests/Checkout.js index 440ba39a5..9609cb60f 100644 --- a/cypress/support/api/requests/Checkout.js +++ b/cypress/support/api/requests/Checkout.js @@ -280,3 +280,25 @@ export function getCheckout(token) { }`; return cy.sendRequestWithQuery(query).its("body.data.checkout"); } + +export function orderCreateFromCheckout( + checkoutId, + token, + removeCheckoutFlag = true, +) { + const mutation = `mutation { + orderCreateFromCheckout(id: "${checkoutId}", removeCheckout: ${removeCheckoutFlag}) + { + order{ + id + } + errors{ + field + message + } + } + }`; + return cy + .sendRequestWithQuery(mutation, token) + .its("body.data.orderCreateFromCheckout.order"); +}