diff --git a/cypress/integration/discounts/vouchers.js b/cypress/integration/discounts/vouchers.js index 84f254f4c..a20ee5e59 100644 --- a/cypress/integration/discounts/vouchers.js +++ b/cypress/integration/discounts/vouchers.js @@ -7,17 +7,17 @@ import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; import { urlList, voucherDetailsUrl } from "../../fixtures/urlList"; import { ONE_PERMISSION_USERS } from "../../fixtures/users"; import { createChannel } from "../../support/api/requests/Channels"; +import { completeCheckout } from "../../support/api/requests/Checkout"; import * as channelsUtils from "../../support/api/utils/channelsUtils"; import { createVoucherInChannel, deleteVouchersStartsWith } from "../../support/api/utils/discounts/vouchersUtils"; -import { createCheckoutWithVoucher } from "../../support/api/utils/ordersUtils"; -import * as productsUtils from "../../support/api/utils/products/productsUtils"; import { - createShipping, - deleteShippingStartsWith -} from "../../support/api/utils/shippingUtils"; + addPayment, + createCheckoutWithVoucher +} from "../../support/api/utils/ordersUtils"; +import * as productsUtils from "../../support/api/utils/products/productsUtils"; import filterTests from "../../support/filterTests"; import { createVoucher, @@ -32,9 +32,6 @@ filterTests({ definedTags: ["all"] }, () => { let defaultChannel; let createdChannel; - let productType; - let attribute; - let category; let shippingMethod; let variants; let product; @@ -43,59 +40,26 @@ filterTests({ definedTags: ["all"] }, () => { before(() => { cy.clearSessionData().loginUserViaRequest(); channelsUtils.deleteChannelsStartsWith(startsWith); - productsUtils.deleteProductsStartsWith(startsWith); - deleteShippingStartsWith(startsWith); deleteVouchersStartsWith(startsWith); - const name = `${startsWith}${faker.datatype.number()}`; - productsUtils - .createTypeAttributeAndCategoryForProduct({ name }) + .createProductWithShipping({ name, productPrice, shippingPrice }) .then( ({ - productType: productTypeResp, - attribute: attributeResp, - category: categoryResp + variantsList: variantsResp, + defaultChannel: channel, + shippingMethod: shippingMethodResp, + address: addressResp, + product: productResp }) => { - productType = productTypeResp; - attribute = attributeResp; - category = categoryResp; - - channelsUtils.getDefaultChannel(); - } - ) - .then(channel => { - defaultChannel = channel; - cy.fixture("addresses"); - }) - .then(addresses => { - address = addresses.plAddress; - createShipping({ - channelId: defaultChannel.id, - name, - address, - price: shippingPrice - }); - }) - .then( - ({ shippingMethod: shippingMethodResp, warehouse: warehouse }) => { + variants = variantsResp; + defaultChannel = channel; shippingMethod = shippingMethodResp; - productsUtils.createProductInChannel({ - name, - channelId: defaultChannel.id, - warehouseId: warehouse.id, - productTypeId: productType.id, - attributeId: attribute.id, - categoryId: category.id, - price: productPrice - }); + address = addressResp; + product = productResp; + createChannel({ name }); } ) - .then(({ variantsList: variantsResp, product: productResp }) => { - product = productResp; - variants = variantsResp; - createChannel({ name }); - }) .then(channel => { createdChannel = channel; }); @@ -103,36 +67,92 @@ filterTests({ definedTags: ["all"] }, () => { it("should create percentage voucher", () => { const voucherValue = 50; + const voucherCode = `${startsWith}${faker.datatype.number()}`; + const expectedAmount = + (productPrice * voucherValue) / 100 + shippingPrice; + let checkout; loginAndCreateCheckoutForVoucherWithDiscount( discountOptions.PERCENTAGE, - voucherValue - ).then(amount => { - const expectedAmount = - (productPrice * voucherValue) / 100 + shippingPrice; - expect(amount).to.be.eq(expectedAmount); - }); + voucherValue, + voucherCode + ) + .then(amount => { + expect(amount).to.be.eq(expectedAmount); + createCheckoutForCreatedVoucher(voucherCode); + }) + .then(resp => { + expect(resp.addPromoCodeResp.checkout.totalPrice.gross.amount).to.eq( + expectedAmount + ); + checkout = resp.checkout; + addPayment(checkout.id); + }) + .then(() => { + completeCheckout(checkout.id); + }) + .then(({ order }) => { + expect(order.id).to.be.ok; + }); }); it("should create fixed price voucher", () => { const voucherValue = 50; + const voucherCode = `${startsWith}${faker.datatype.number()}`; + const expectedAmount = productPrice + shippingPrice - voucherValue; + let checkout; + loginAndCreateCheckoutForVoucherWithDiscount( discountOptions.FIXED, - voucherValue - ).then(amount => { - const expectedAmount = productPrice + shippingPrice - voucherValue; - expect(amount).to.be.eq(expectedAmount); - }); + voucherValue, + voucherCode + ) + .then(amount => { + expect(amount).to.be.eq(expectedAmount); + createCheckoutForCreatedVoucher(voucherCode); + }) + .then(resp => { + expect(resp.addPromoCodeResp.checkout.totalPrice.gross.amount).to.eq( + expectedAmount + ); + checkout = resp.checkout; + addPayment(checkout.id); + }) + .then(() => { + completeCheckout(checkout.id); + }) + .then(({ order }) => { + expect(order.id).to.be.ok; + }); }); it("should create free shipping voucher", () => { + const voucherCode = `${startsWith}${faker.datatype.number()}`; + const expectedAmount = productPrice; + let checkout; + loginAndCreateCheckoutForVoucherWithDiscount( discountOptions.SHIPPING, - null - ).then(amount => { - const expectedAmount = productPrice; - expect(amount).to.be.eq(expectedAmount); - }); + null, + voucherCode + ) + .then(amount => { + expect(amount).to.be.eq(expectedAmount); + createCheckoutForCreatedVoucher(voucherCode); + }) + .then(resp => { + expect(resp.addPromoCodeResp.checkout.totalPrice.gross.amount).to.eq( + expectedAmount + ); + checkout = resp.checkout; + addPayment(checkout.id); + }) + .then(() => { + completeCheckout(checkout.id); + }) + .then(({ order }) => { + expect(order.id).to.be.ok; + }); }); it("should create voucher not available for selected channel", () => { @@ -173,8 +193,6 @@ filterTests({ definedTags: ["all"] }, () => { .then(voucherResp => { voucher = voucherResp; expect(voucher.id).to.be.ok; - }) - .then(resp => { cy.visit(voucherDetailsUrl(voucher.id)) .addAliasToGraphRequest("VoucherDelete") .get(BUTTON_SELECTORS.deleteButton) @@ -203,10 +221,9 @@ filterTests({ definedTags: ["all"] }, () => { function loginAndCreateCheckoutForVoucherWithDiscount( discount, - voucherValue + voucherValue, + voucherCode ) { - const voucherCode = `${startsWith}${faker.datatype.number()}`; - cy.clearSessionData() .loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount) .visit(urlList.vouchers); diff --git a/cypress/support/api/utils/products/productsUtils.js b/cypress/support/api/utils/products/productsUtils.js index c9e1e205c..bf314fe4e 100644 --- a/cypress/support/api/utils/products/productsUtils.js +++ b/cypress/support/api/utils/products/productsUtils.js @@ -120,7 +120,8 @@ export function deleteProductsStartsWith(startsWith) { export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({ name, description = name, - warehouseId + warehouseId, + productPrice = 10 }) { let defaultChannel; let collection; @@ -147,13 +148,18 @@ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({ name, collectionId: collection.id, description, - warehouseId + warehouseId, + price: productPrice }); }) .then(({ product, variantsList }) => ({ product, variantsList })); } -export function createProductWithShipping({ name }) { +export function createProductWithShipping({ + name, + productPrice = 10, + shippingPrice = 10 +}) { let address; let warehouse; let shippingMethod; @@ -172,7 +178,7 @@ export function createProductWithShipping({ name }) { channelId: defaultChannel.id, name, address, - price: 10 + price: shippingPrice }); }) .then( @@ -186,7 +192,8 @@ export function createProductWithShipping({ name }) { shippingZone = shippingZoneResp; deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({ name, - warehouseId: warehouse.id + warehouseId: warehouse.id, + productPrice }); } ) diff --git a/cypress/support/pages/channelsPage.js b/cypress/support/pages/channelsPage.js index d7fb17964..aae534e06 100644 --- a/cypress/support/pages/channelsPage.js +++ b/cypress/support/pages/channelsPage.js @@ -85,7 +85,7 @@ export function selectChannelInDetailsPages(channelName) { } cy.get(SELECT_CHANNELS_TO_ASSIGN.selectChannelsForm) .find(BUTTON_SELECTORS.submit) - .click(); + .click({ force: true }); } export function selectChannelVariantInDetailsPage(channelName, attributeName) {