update tests for vouchers (#1546)

This commit is contained in:
Karolina Rakoczy 2021-11-03 12:29:59 +01:00 committed by GitHub
parent 80809a078a
commit a39f729a1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 103 additions and 79 deletions

View file

@ -7,17 +7,17 @@ import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { urlList, voucherDetailsUrl } from "../../fixtures/urlList"; import { urlList, voucherDetailsUrl } from "../../fixtures/urlList";
import { ONE_PERMISSION_USERS } from "../../fixtures/users"; import { ONE_PERMISSION_USERS } from "../../fixtures/users";
import { createChannel } from "../../support/api/requests/Channels"; import { createChannel } from "../../support/api/requests/Channels";
import { completeCheckout } from "../../support/api/requests/Checkout";
import * as channelsUtils from "../../support/api/utils/channelsUtils"; import * as channelsUtils from "../../support/api/utils/channelsUtils";
import { import {
createVoucherInChannel, createVoucherInChannel,
deleteVouchersStartsWith deleteVouchersStartsWith
} from "../../support/api/utils/discounts/vouchersUtils"; } from "../../support/api/utils/discounts/vouchersUtils";
import { createCheckoutWithVoucher } from "../../support/api/utils/ordersUtils";
import * as productsUtils from "../../support/api/utils/products/productsUtils";
import { import {
createShipping, addPayment,
deleteShippingStartsWith createCheckoutWithVoucher
} from "../../support/api/utils/shippingUtils"; } from "../../support/api/utils/ordersUtils";
import * as productsUtils from "../../support/api/utils/products/productsUtils";
import filterTests from "../../support/filterTests"; import filterTests from "../../support/filterTests";
import { import {
createVoucher, createVoucher,
@ -32,9 +32,6 @@ filterTests({ definedTags: ["all"] }, () => {
let defaultChannel; let defaultChannel;
let createdChannel; let createdChannel;
let productType;
let attribute;
let category;
let shippingMethod; let shippingMethod;
let variants; let variants;
let product; let product;
@ -43,59 +40,26 @@ filterTests({ definedTags: ["all"] }, () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
channelsUtils.deleteChannelsStartsWith(startsWith); channelsUtils.deleteChannelsStartsWith(startsWith);
productsUtils.deleteProductsStartsWith(startsWith);
deleteShippingStartsWith(startsWith);
deleteVouchersStartsWith(startsWith); deleteVouchersStartsWith(startsWith);
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
productsUtils productsUtils
.createTypeAttributeAndCategoryForProduct({ name }) .createProductWithShipping({ name, productPrice, shippingPrice })
.then( .then(
({ ({
productType: productTypeResp, variantsList: variantsResp,
attribute: attributeResp, defaultChannel: channel,
category: categoryResp shippingMethod: shippingMethodResp,
address: addressResp,
product: productResp
}) => { }) => {
productType = productTypeResp; variants = variantsResp;
attribute = attributeResp; defaultChannel = channel;
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 }) => {
shippingMethod = shippingMethodResp; shippingMethod = shippingMethodResp;
productsUtils.createProductInChannel({ address = addressResp;
name, product = productResp;
channelId: defaultChannel.id, createChannel({ name });
warehouseId: warehouse.id,
productTypeId: productType.id,
attributeId: attribute.id,
categoryId: category.id,
price: productPrice
});
} }
) )
.then(({ variantsList: variantsResp, product: productResp }) => {
product = productResp;
variants = variantsResp;
createChannel({ name });
})
.then(channel => { .then(channel => {
createdChannel = channel; createdChannel = channel;
}); });
@ -103,36 +67,92 @@ filterTests({ definedTags: ["all"] }, () => {
it("should create percentage voucher", () => { it("should create percentage voucher", () => {
const voucherValue = 50; const voucherValue = 50;
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const expectedAmount =
(productPrice * voucherValue) / 100 + shippingPrice;
let checkout;
loginAndCreateCheckoutForVoucherWithDiscount( loginAndCreateCheckoutForVoucherWithDiscount(
discountOptions.PERCENTAGE, discountOptions.PERCENTAGE,
voucherValue voucherValue,
).then(amount => { voucherCode
const expectedAmount = )
(productPrice * voucherValue) / 100 + shippingPrice; .then(amount => {
expect(amount).to.be.eq(expectedAmount); 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", () => { it("should create fixed price voucher", () => {
const voucherValue = 50; const voucherValue = 50;
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const expectedAmount = productPrice + shippingPrice - voucherValue;
let checkout;
loginAndCreateCheckoutForVoucherWithDiscount( loginAndCreateCheckoutForVoucherWithDiscount(
discountOptions.FIXED, discountOptions.FIXED,
voucherValue voucherValue,
).then(amount => { voucherCode
const expectedAmount = productPrice + shippingPrice - voucherValue; )
expect(amount).to.be.eq(expectedAmount); .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", () => { it("should create free shipping voucher", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const expectedAmount = productPrice;
let checkout;
loginAndCreateCheckoutForVoucherWithDiscount( loginAndCreateCheckoutForVoucherWithDiscount(
discountOptions.SHIPPING, discountOptions.SHIPPING,
null null,
).then(amount => { voucherCode
const expectedAmount = productPrice; )
expect(amount).to.be.eq(expectedAmount); .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", () => { it("should create voucher not available for selected channel", () => {
@ -173,8 +193,6 @@ filterTests({ definedTags: ["all"] }, () => {
.then(voucherResp => { .then(voucherResp => {
voucher = voucherResp; voucher = voucherResp;
expect(voucher.id).to.be.ok; expect(voucher.id).to.be.ok;
})
.then(resp => {
cy.visit(voucherDetailsUrl(voucher.id)) cy.visit(voucherDetailsUrl(voucher.id))
.addAliasToGraphRequest("VoucherDelete") .addAliasToGraphRequest("VoucherDelete")
.get(BUTTON_SELECTORS.deleteButton) .get(BUTTON_SELECTORS.deleteButton)
@ -203,10 +221,9 @@ filterTests({ definedTags: ["all"] }, () => {
function loginAndCreateCheckoutForVoucherWithDiscount( function loginAndCreateCheckoutForVoucherWithDiscount(
discount, discount,
voucherValue voucherValue,
voucherCode
) { ) {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
cy.clearSessionData() cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount) .loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
.visit(urlList.vouchers); .visit(urlList.vouchers);

View file

@ -120,7 +120,8 @@ export function deleteProductsStartsWith(startsWith) {
export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
name, name,
description = name, description = name,
warehouseId warehouseId,
productPrice = 10
}) { }) {
let defaultChannel; let defaultChannel;
let collection; let collection;
@ -147,13 +148,18 @@ export function deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
name, name,
collectionId: collection.id, collectionId: collection.id,
description, description,
warehouseId warehouseId,
price: productPrice
}); });
}) })
.then(({ product, variantsList }) => ({ product, variantsList })); .then(({ product, variantsList }) => ({ product, variantsList }));
} }
export function createProductWithShipping({ name }) { export function createProductWithShipping({
name,
productPrice = 10,
shippingPrice = 10
}) {
let address; let address;
let warehouse; let warehouse;
let shippingMethod; let shippingMethod;
@ -172,7 +178,7 @@ export function createProductWithShipping({ name }) {
channelId: defaultChannel.id, channelId: defaultChannel.id,
name, name,
address, address,
price: 10 price: shippingPrice
}); });
}) })
.then( .then(
@ -186,7 +192,8 @@ export function createProductWithShipping({ name }) {
shippingZone = shippingZoneResp; shippingZone = shippingZoneResp;
deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({ deleteProductsAndCreateNewOneWithNewDataAndDefaultChannel({
name, name,
warehouseId: warehouse.id warehouseId: warehouse.id,
productPrice
}); });
} }
) )

View file

@ -85,7 +85,7 @@ export function selectChannelInDetailsPages(channelName) {
} }
cy.get(SELECT_CHANNELS_TO_ASSIGN.selectChannelsForm) cy.get(SELECT_CHANNELS_TO_ASSIGN.selectChannelsForm)
.find(BUTTON_SELECTORS.submit) .find(BUTTON_SELECTORS.submit)
.click(); .click({ force: true });
} }
export function selectChannelVariantInDetailsPage(channelName, attributeName) { export function selectChannelVariantInDetailsPage(channelName, attributeName) {