diff --git a/cypress/elements/giftCard/giftCardDialog.js b/cypress/elements/catalog/giftCard/giftCardDialog.js
similarity index 100%
rename from cypress/elements/giftCard/giftCardDialog.js
rename to cypress/elements/catalog/giftCard/giftCardDialog.js
diff --git a/cypress/elements/catalog/giftCard/giftCardList.js b/cypress/elements/catalog/giftCard/giftCardList.js
new file mode 100644
index 000000000..dc8b4b2ee
--- /dev/null
+++ b/cypress/elements/catalog/giftCard/giftCardList.js
@@ -0,0 +1,9 @@
+export const GIFT_CARD_LIST = {
+ issueCardButton: '[data-test-id="issue-card-button"]',
+ selectGiftCardCheckbox: '[data-test-id="select-gift-card-checkbox"]',
+ deactivateGiftCardButton: '[data-test-id="deactivate-gift-cards"]',
+ activateGiftCardButton: '[data-test-id="activate-gift-cards"]'
+};
+
+export const giftCardRow = giftCardId =>
+ `[data-test-id="gift-card-row-${giftCardId}"]`;
diff --git a/cypress/elements/giftCard/giftCardUpdate.js b/cypress/elements/catalog/giftCard/giftCardUpdate.js
similarity index 100%
rename from cypress/elements/giftCard/giftCardUpdate.js
rename to cypress/elements/catalog/giftCard/giftCardUpdate.js
diff --git a/cypress/elements/giftCard/giftCardList.js b/cypress/elements/giftCard/giftCardList.js
deleted file mode 100644
index 16a2ece5e..000000000
--- a/cypress/elements/giftCard/giftCardList.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export const GIFT_CARD_LIST = {
- issueCardButton: '[data-test-id="issueCardButton"]'
-};
diff --git a/cypress/integration/catalog/giftCards.js b/cypress/integration/catalog/giftCards.js
deleted file mode 100644
index 7a14f6dad..000000000
--- a/cypress/integration/catalog/giftCards.js
+++ /dev/null
@@ -1,173 +0,0 @@
-///
-///
-
-import faker from "faker";
-
-import { GIFT_CARD_UPDATE } from "../../elements/giftCard/giftCardUpdate";
-import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
-import { giftCardDetailsUrl } from "../../fixtures/urlList";
-import {
- createGiftCard,
- getGiftCardsWithCode,
- getGiftCardWithId
-} from "../../support/api/requests/GiftCard";
-import { deleteGiftCardsWithTagStartsWith } from "../../support/api/utils/catalog/giftCardUtils";
-import { addToDate } from "../../support/api/utils/misc";
-import filterTests from "../../support/filterTests";
-import { formatDate } from "../../support/formatData/formatDate";
-import {
- expiryPeriods,
- openAndFillUpCreateGiftCardDialog,
- saveGiftCard,
- setExpiryDate,
- setExpiryPeriod
-} from "../../support/pages/catalog/giftCardPage";
-
-filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
- describe("Tests for gift cards", () => {
- const startsWith = "GiftCards";
- const amount = 50;
- const currency = "USD";
-
- before(() => {
- cy.clearSessionData().loginUserViaRequest();
- deleteGiftCardsWithTagStartsWith(startsWith);
- });
-
- beforeEach(() => {
- cy.clearSessionData().loginUserViaRequest();
- });
-
- it("should create never expire gift card", () => {
- const name = `${startsWith}${faker.datatype.number()}`;
- let giftCard;
-
- openAndFillUpCreateGiftCardDialog({
- note: name,
- tag: name,
- amount,
- currency
- });
- saveGiftCard()
- .then(giftCardResp => {
- giftCard = giftCardResp;
- getGiftCardsWithCode(giftCard.code);
- })
- .then(giftCardsResp => {
- expect(giftCardsResp[0].node.code).to.eq(giftCard.code);
- expect(giftCardsResp[0].node.initialBalance.amount).to.eq(amount);
- expect(giftCardsResp[0].node.initialBalance.currency).to.eq(currency);
- });
- });
-
- it("should create gift card with two moths expiry", () => {
- const name = `${startsWith}${faker.datatype.number()}`;
- let giftCard;
- const expectedExpiryDate = addToDate(new Date(), 2, "M");
-
- openAndFillUpCreateGiftCardDialog({
- note: name,
- tag: name,
- amount,
- currency
- });
- setExpiryPeriod(2, expiryPeriods.MONTH);
- saveGiftCard()
- .then(giftCardResp => {
- giftCard = giftCardResp;
- getGiftCardsWithCode(giftCard.code);
- })
- .then(giftCardsResp => {
- expect(giftCardsResp[0].node.code).to.eq(giftCard.code);
- expect(giftCardsResp[0].node.initialBalance.amount).to.eq(amount);
- expect(giftCardsResp[0].node.initialBalance.currency).to.eq(currency);
- expect(giftCardsResp[0].node.expiryDate).to.eq(expectedExpiryDate);
- });
- });
-
- it("should create gift card with date expiry", () => {
- const name = `${startsWith}${faker.datatype.number()}`;
- let giftCard;
- const date = formatDate(new Date(new Date().getFullYear() + 2, 1, 1));
-
- openAndFillUpCreateGiftCardDialog({
- note: name,
- tag: name,
- amount,
- currency
- });
- setExpiryDate(date);
- saveGiftCard()
- .then(giftCardResp => {
- giftCard = giftCardResp;
- getGiftCardsWithCode(giftCard.code);
- })
- .then(giftCardsResp => {
- expect(giftCardsResp[0].node.code).to.eq(giftCard.code);
- expect(giftCardsResp[0].node.initialBalance.amount).to.eq(amount);
- expect(giftCardsResp[0].node.initialBalance.currency).to.eq(currency);
- expect(giftCardsResp[0].node.expiryDate).to.eq(date);
- });
- });
-
- it("should delete gift card", () => {
- const name = `${startsWith}${faker.datatype.number()}`;
-
- createGiftCard({
- tag: name,
- amount: 10,
- currency: "USD"
- }).then(giftCard => {
- cy.visit(giftCardDetailsUrl(giftCard.id))
- .get(BUTTON_SELECTORS.deleteButton)
- .click()
- .addAliasToGraphRequest("DeleteGiftCard")
- .get(GIFT_CARD_UPDATE.consentCheckbox)
- .click()
- .get(BUTTON_SELECTORS.submit)
- .click()
- .waitForRequestAndCheckIfNoErrors("@DeleteGiftCard");
- getGiftCardWithId(giftCard.id).should("be.null");
- });
- });
-
- it("should update gift card", () => {
- const name = `${startsWith}${faker.datatype.number()}`;
- const updatedName = `${startsWith}${faker.datatype.number()}`;
- const date = formatDate(new Date(new Date().getFullYear() + 2, 1, 1));
-
- createGiftCard({
- tag: name,
- amount: 10,
- currency: "USD"
- })
- .then(giftCard => {
- cy.visit(giftCardDetailsUrl(giftCard.id))
- .waitForProgressBarToNotBeVisible()
- .get(GIFT_CARD_UPDATE.expireCheckbox)
- .click()
- .get(GIFT_CARD_UPDATE.expireDateInput)
- .type(date)
- .get(GIFT_CARD_UPDATE.removeTagButton)
- .click()
- .get(GIFT_CARD_UPDATE.giftCardTagSelect)
- .find("input")
- .clear()
- .type(updatedName)
- .get(GIFT_CARD_UPDATE.autocompleteCustomOption)
- .click()
- .addAliasToGraphRequest("GiftCardUpdate")
- .get(BUTTON_SELECTORS.confirm)
- .click()
- .waitForRequestAndCheckIfNoErrors("@GiftCardUpdate");
- getGiftCardWithId(giftCard.id);
- })
- .then(giftCard => {
- expect(giftCard.tags[0].name.toLowerCase()).to.eq(
- updatedName.toLowerCase()
- );
- expect(giftCard.expiryDate).to.eq(date);
- });
- });
- });
-});
diff --git a/cypress/integration/catalog/giftCards/activateGiftCards.js b/cypress/integration/catalog/giftCards/activateGiftCards.js
new file mode 100644
index 000000000..395409278
--- /dev/null
+++ b/cypress/integration/catalog/giftCards/activateGiftCards.js
@@ -0,0 +1,282 @@
+///
+import faker from "faker";
+
+import { GIFT_CARD_LIST } from "../../../elements/catalog/giftCard/giftCardList";
+import { urlList } from "../../../fixtures/urlList";
+import { completeCheckout } from "../../../support/api/requests/Checkout";
+import {
+ createGiftCard,
+ giftCardDeactivate
+} from "../../../support/api/requests/GiftCard";
+import {
+ createCheckoutWithDisabledGiftCard,
+ deleteGiftCardsWithTagStartsWith,
+ isGiftCardDataAsExpected,
+ purchaseProductWithActiveGiftCard
+} from "../../../support/api/utils/catalog/giftCardUtils";
+import * as channelsUtils from "../../../support/api/utils/channelsUtils";
+import {
+ addPayment,
+ purchaseProductWithPromoCode
+} from "../../../support/api/utils/ordersUtils";
+import * as productsUtils from "../../../support/api/utils/products/productsUtils";
+import {
+ createShipping,
+ deleteShippingStartsWith
+} from "../../../support/api/utils/shippingUtils";
+import filterTests from "../../../support/filterTests";
+import {
+ changeGiftCardActiveStatus,
+ selectGiftCard
+} from "../../../support/pages/catalog/giftCardPage";
+
+filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
+ describe("As a admin I want to use enabled gift card in checkout", () => {
+ const startsWith = "GiftCardsCheckout";
+ const productPrice = 50;
+ const shippingPrice = 50;
+ const email = "example@example.com";
+
+ let defaultChannel;
+ let productType;
+ let attribute;
+ let category;
+ let shippingMethod;
+ let variants;
+ let address;
+ let dataForCheckout;
+ const giftCardData = {
+ amount: 150,
+ currency: "USD"
+ };
+
+ before(() => {
+ cy.clearSessionData().loginUserViaRequest();
+ channelsUtils.deleteChannelsStartsWith(startsWith);
+ productsUtils.deleteProductsStartsWith(startsWith);
+ deleteShippingStartsWith(startsWith);
+ deleteGiftCardsWithTagStartsWith(startsWith);
+
+ const name = `${startsWith}${faker.datatype.number()}`;
+
+ productsUtils
+ .createTypeAttributeAndCategoryForProduct({ name })
+ .then(
+ ({
+ productType: productTypeResp,
+ attribute: attributeResp,
+ category: categoryResp
+ }) => {
+ 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 }) => {
+ shippingMethod = shippingMethodResp;
+ productsUtils.createProductInChannel({
+ name,
+ channelId: defaultChannel.id,
+ warehouseId: warehouse.id,
+ productTypeId: productType.id,
+ attributeId: attribute.id,
+ categoryId: category.id,
+ price: productPrice
+ });
+ }
+ )
+ .then(({ variantsList: variantsResp }) => {
+ variants = variantsResp;
+
+ dataForCheckout = {
+ address,
+ email,
+ auth: "token",
+ channelSlug: defaultChannel.slug,
+ shippingMethodName: shippingMethod.name,
+ variantsList: variants
+ };
+ });
+ });
+
+ beforeEach(() => {
+ cy.clearSessionData().loginUserViaRequest();
+ });
+
+ it("should be able to enable gift card and use it in checkout. TC: SALEOR_1006", () => {
+ const expectedGiftCardBalance =
+ giftCardData.amount - productPrice - shippingPrice;
+ giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
+ let giftCard;
+
+ createGiftCard(giftCardData)
+ .then(giftCardResp => {
+ giftCard = giftCardResp;
+ giftCardDeactivate(giftCard.id);
+ })
+ .then(() => {
+ changeGiftCardActiveStatus(giftCard.id);
+ dataForCheckout.voucherCode = giftCard.code;
+ purchaseProductWithPromoCode(dataForCheckout);
+ })
+ .then(({ order }) => {
+ expect(order.total.gross.amount).to.eq(0);
+ expect(order.userEmail).to.eq(email);
+ isGiftCardDataAsExpected({
+ giftCardId: giftCard.id,
+ expectedAmount: expectedGiftCardBalance,
+ userEmail: email,
+ initialBalance: giftCardData.amount
+ });
+ })
+ .then(dataAsExpected => {
+ expect(dataAsExpected).to.be.true;
+ });
+ });
+
+ it("should not be able to disable gift card and use it in checkout. TC: SALEOR_1007", () => {
+ giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
+ let giftCard;
+
+ createGiftCard(giftCardData)
+ .then(giftCardResp => {
+ giftCard = giftCardResp;
+ changeGiftCardActiveStatus(giftCard.id);
+ dataForCheckout.voucherCode = giftCard.code;
+ createCheckoutWithDisabledGiftCard(dataForCheckout);
+ })
+ .then(checkout => {
+ addPayment(checkout.id);
+ completeCheckout(checkout.id);
+ })
+ .then(() => {
+ isGiftCardDataAsExpected({
+ giftCardId: giftCard.id,
+ expectedAmount: giftCardData.amount
+ });
+ })
+ .then(dataAsExpected => {
+ expect(dataAsExpected).to.be.true;
+ });
+ });
+
+ it("should not be able to disable several gift cards on gift card list page and use it in checkout. TC: SALEOR_1013", () => {
+ const firstGiftCardName = `${startsWith}${faker.datatype.number()}`;
+ const secondGiftCardName = `${startsWith}${faker.datatype.number()}`;
+ const amount = 10;
+ let firstGiftCard;
+ let secondGiftCard;
+
+ createGiftCard({
+ tag: firstGiftCardName,
+ amount,
+ currency: "USD"
+ })
+ .then(giftCard => {
+ firstGiftCard = giftCard;
+ createGiftCard({
+ tag: secondGiftCardName,
+ amount,
+ currency: "USD"
+ });
+ })
+ .then(giftCard => {
+ secondGiftCard = giftCard;
+ cy.visit(urlList.giftCards).waitForProgressBarToNotExist();
+ selectGiftCard(firstGiftCard.id);
+ selectGiftCard(secondGiftCard.id)
+ .addAliasToGraphRequest("GiftCardBulkDeactivate")
+ .get(GIFT_CARD_LIST.deactivateGiftCardButton)
+ .click()
+ .waitForRequestAndCheckIfNoErrors("@GiftCardBulkDeactivate")
+ .confirmationMessageShouldDisappear();
+ dataForCheckout.voucherCode = firstGiftCard.code;
+ createCheckoutWithDisabledGiftCard(dataForCheckout);
+ dataForCheckout.voucherCode = secondGiftCard.code;
+ createCheckoutWithDisabledGiftCard(dataForCheckout);
+ })
+ .then(checkout => {
+ addPayment(checkout.id);
+ completeCheckout(checkout.id);
+ })
+ .then(() => {
+ isGiftCardDataAsExpected({
+ giftCardId: firstGiftCard.id,
+ expectedAmount: amount
+ }).then(dataAsExpected => expect(dataAsExpected).to.be.true);
+ isGiftCardDataAsExpected({
+ giftCardId: secondGiftCard.id,
+ expectedAmount: amount
+ }).then(dataAsExpected => expect(dataAsExpected).to.be.true);
+ });
+ });
+
+ it("should be able to enable several gift cards on gift card list page and use it in checkout. TC: SALEOR_1012", () => {
+ const firstGiftCardName = `${startsWith}${faker.datatype.number()}`;
+ const secondGiftCardName = `${startsWith}${faker.datatype.number()}`;
+ const amount = 10;
+ const expectedOrderPrice = shippingPrice + productPrice - amount;
+ let firstGiftCard;
+ let secondGiftCard;
+
+ createGiftCard({
+ tag: firstGiftCardName,
+ amount,
+ currency: "USD",
+ isActive: false
+ })
+ .then(giftCard => {
+ firstGiftCard = giftCard;
+ createGiftCard({
+ tag: secondGiftCardName,
+ amount,
+ currency: "USD",
+ isActive: false
+ });
+ })
+ .then(giftCard => {
+ secondGiftCard = giftCard;
+ cy.visit(urlList.giftCards).waitForProgressBarToNotExist();
+ selectGiftCard(firstGiftCard.id);
+ selectGiftCard(secondGiftCard.id)
+ .addAliasToGraphRequest("GiftCardBulkActivate")
+ .get(GIFT_CARD_LIST.activateGiftCardButton)
+ .click()
+ .waitForRequestAndCheckIfNoErrors("@GiftCardBulkActivate")
+ .confirmationMessageShouldDisappear();
+ dataForCheckout.voucherCode = firstGiftCard.code;
+ purchaseProductWithActiveGiftCard({
+ giftCard: firstGiftCard,
+ expectedAmount: 0,
+ initialAmount: amount,
+ dataForCheckout,
+ expectedOrderPrice
+ }).then(isDataAsExpected => expect(isDataAsExpected).to.be.true);
+ dataForCheckout.voucherCode = secondGiftCard.code;
+ purchaseProductWithActiveGiftCard({
+ giftCard: secondGiftCard,
+ expectedAmount: 0,
+ initialAmount: amount,
+ dataForCheckout,
+ expectedOrderPrice
+ }).then(isDataAsExpected => expect(isDataAsExpected).to.be.true);
+ });
+ });
+ });
+});
diff --git a/cypress/integration/catalog/giftCards/createGiftCard.js b/cypress/integration/catalog/giftCards/createGiftCard.js
new file mode 100644
index 000000000..14bf3daa1
--- /dev/null
+++ b/cypress/integration/catalog/giftCards/createGiftCard.js
@@ -0,0 +1,106 @@
+///
+///
+
+import faker from "faker";
+
+import { getGiftCardsWithCode } from "../../../support/api/requests/GiftCard";
+import { deleteGiftCardsWithTagStartsWith } from "../../../support/api/utils/catalog/giftCardUtils";
+import { addToDate } from "../../../support/api/utils/misc";
+import filterTests from "../../../support/filterTests";
+import { formatDate } from "../../../support/formatData/formatDate";
+import {
+ expiryPeriods,
+ openAndFillUpCreateGiftCardDialog,
+ saveGiftCard,
+ setExpiryDate,
+ setExpiryPeriod
+} from "../../../support/pages/catalog/giftCardPage";
+
+filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
+ describe("As an admin I want to create gift card", () => {
+ const startsWith = "GiftCards";
+ const amount = 50;
+ const currency = "USD";
+
+ before(() => {
+ cy.clearSessionData().loginUserViaRequest();
+ deleteGiftCardsWithTagStartsWith(startsWith);
+ });
+
+ beforeEach(() => {
+ cy.clearSessionData().loginUserViaRequest();
+ });
+
+ it("should be able to create never expire gift card. TC: SALEOR_1001", () => {
+ const name = `${startsWith}${faker.datatype.number()}`;
+ let giftCard;
+
+ openAndFillUpCreateGiftCardDialog({
+ note: name,
+ tag: name,
+ amount,
+ currency
+ });
+ saveGiftCard()
+ .then(giftCardResp => {
+ giftCard = giftCardResp;
+ getGiftCardsWithCode(giftCard.code);
+ })
+ .then(giftCardsResp => {
+ expect(giftCardsResp[0].node.code).to.eq(giftCard.code);
+ expect(giftCardsResp[0].node.initialBalance.amount).to.eq(amount);
+ expect(giftCardsResp[0].node.initialBalance.currency).to.eq(currency);
+ });
+ });
+
+ it("should be able to create gift card with two moths expiry. TC: SALEOR_1002", () => {
+ const name = `${startsWith}${faker.datatype.number()}`;
+ let giftCard;
+ const expectedExpiryDate = addToDate(new Date(), 2, "M");
+
+ openAndFillUpCreateGiftCardDialog({
+ note: name,
+ tag: name,
+ amount,
+ currency
+ });
+ setExpiryPeriod(2, expiryPeriods.MONTH);
+ saveGiftCard()
+ .then(giftCardResp => {
+ giftCard = giftCardResp;
+ getGiftCardsWithCode(giftCard.code);
+ })
+ .then(giftCardsResp => {
+ expect(giftCardsResp[0].node.code).to.eq(giftCard.code);
+ expect(giftCardsResp[0].node.initialBalance.amount).to.eq(amount);
+ expect(giftCardsResp[0].node.initialBalance.currency).to.eq(currency);
+ expect(giftCardsResp[0].node.expiryDate).to.eq(expectedExpiryDate);
+ });
+ });
+
+ it("should be able to create gift card with date expiry. TC: SALEOR_1003", () => {
+ const name = `${startsWith}${faker.datatype.number()}`;
+ const date = formatDate(new Date(new Date().getFullYear() + 2, 1, 1));
+ let giftCard;
+
+ openAndFillUpCreateGiftCardDialog({
+ note: name,
+ tag: name,
+ amount,
+ currency
+ });
+ setExpiryDate(date);
+ saveGiftCard()
+ .then(giftCardResp => {
+ giftCard = giftCardResp;
+ getGiftCardsWithCode(giftCard.code);
+ })
+ .then(giftCardsResp => {
+ expect(giftCardsResp[0].node.code).to.eq(giftCard.code);
+ expect(giftCardsResp[0].node.initialBalance.amount).to.eq(amount);
+ expect(giftCardsResp[0].node.initialBalance.currency).to.eq(currency);
+ expect(giftCardsResp[0].node.expiryDate).to.eq(date);
+ });
+ });
+ });
+});
diff --git a/cypress/integration/catalog/giftCards/purchaseGiftCard.js b/cypress/integration/catalog/giftCards/purchaseGiftCard.js
new file mode 100644
index 000000000..6e1b62f63
--- /dev/null
+++ b/cypress/integration/catalog/giftCards/purchaseGiftCard.js
@@ -0,0 +1,107 @@
+///
+import faker from "faker";
+
+import { deleteGiftCardsWithTagStartsWith } from "../../../support/api/utils/catalog/giftCardUtils";
+import * as channelsUtils from "../../../support/api/utils/channelsUtils";
+import { createWaitingForCaptureOrder } from "../../../support/api/utils/ordersUtils";
+import * as productsUtils from "../../../support/api/utils/products/productsUtils";
+import {
+ createShipping,
+ deleteShippingStartsWith
+} from "../../../support/api/utils/shippingUtils";
+import filterTests from "../../../support/filterTests";
+
+filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
+ describe("As a customer I should be able to purchase gift card as a product", () => {
+ const startsWith = "GiftCardsCheckout";
+ const productPrice = 50;
+ const shippingPrice = 50;
+ const email = "example@example.com";
+
+ let defaultChannel;
+ let productType;
+ let attribute;
+ let category;
+ let shippingMethod;
+ let variants;
+ let address;
+ const giftCardData = {
+ amount: 150,
+ currency: "USD"
+ };
+
+ before(() => {
+ cy.clearSessionData().loginUserViaRequest();
+ channelsUtils.deleteChannelsStartsWith(startsWith);
+ productsUtils.deleteProductsStartsWith(startsWith);
+ deleteShippingStartsWith(startsWith);
+ deleteGiftCardsWithTagStartsWith(startsWith);
+
+ const name = `${startsWith}${faker.datatype.number()}`;
+
+ productsUtils
+ .createTypeAttributeAndCategoryForProduct({ name, kind: "GIFT_CARD" })
+ .then(
+ ({
+ productType: productTypeResp,
+ attribute: attributeResp,
+ category: categoryResp
+ }) => {
+ 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 }) => {
+ shippingMethod = shippingMethodResp;
+ productsUtils.createProductInChannel({
+ name,
+ channelId: defaultChannel.id,
+ warehouseId: warehouse.id,
+ productTypeId: productType.id,
+ attributeId: attribute.id,
+ categoryId: category.id,
+ price: productPrice
+ });
+ }
+ )
+ .then(({ variantsList: variantsResp }) => {
+ variants = variantsResp;
+ });
+ });
+
+ beforeEach(() => {
+ cy.clearSessionData().loginUserViaRequest();
+ });
+
+ it("should be able to purchase gift card as a product. TC: SALEOR_1008", () => {
+ giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
+
+ createWaitingForCaptureOrder({
+ address,
+ channelSlug: defaultChannel.slug,
+ email,
+ shippingMethodName: shippingMethod.name,
+ variantsList: variants
+ }).then(({ order }) => {
+ expect(order.id).to.be.ok;
+ });
+ });
+ });
+});
diff --git a/cypress/integration/catalog/giftCards/updatingGiftCards.js b/cypress/integration/catalog/giftCards/updatingGiftCards.js
new file mode 100644
index 000000000..0be7ed807
--- /dev/null
+++ b/cypress/integration/catalog/giftCards/updatingGiftCards.js
@@ -0,0 +1,90 @@
+///
+///
+
+import faker from "faker";
+
+import { GIFT_CARD_UPDATE } from "../../../elements/catalog/giftCard/giftCardUpdate";
+import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
+import { giftCardDetailsUrl } from "../../../fixtures/urlList";
+import {
+ createGiftCard,
+ getGiftCardWithId
+} from "../../../support/api/requests/GiftCard";
+import { deleteGiftCardsWithTagStartsWith } from "../../../support/api/utils/catalog/giftCardUtils";
+import filterTests from "../../../support/filterTests";
+import { formatDate } from "../../../support/formatData/formatDate";
+
+filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
+ describe("As an admin I want to update gift card", () => {
+ const startsWith = "GiftCards";
+
+ before(() => {
+ cy.clearSessionData().loginUserViaRequest();
+ deleteGiftCardsWithTagStartsWith(startsWith);
+ });
+
+ beforeEach(() => {
+ cy.clearSessionData().loginUserViaRequest();
+ });
+
+ it("should be able to delete gift card. TC: SALEOR_1004", () => {
+ const name = `${startsWith}${faker.datatype.number()}`;
+
+ createGiftCard({
+ tag: name,
+ amount: 10,
+ currency: "USD"
+ }).then(giftCard => {
+ cy.visit(giftCardDetailsUrl(giftCard.id))
+ .get(BUTTON_SELECTORS.deleteButton)
+ .click()
+ .addAliasToGraphRequest("DeleteGiftCard")
+ .get(GIFT_CARD_UPDATE.consentCheckbox)
+ .click()
+ .get(BUTTON_SELECTORS.submit)
+ .click()
+ .waitForRequestAndCheckIfNoErrors("@DeleteGiftCard");
+ getGiftCardWithId(giftCard.id).should("be.null");
+ });
+ });
+
+ it("should be able to update gift card. TC: SALEOR_1005", () => {
+ const name = `${startsWith}${faker.datatype.number()}`;
+ const updatedName = `${startsWith}${faker.datatype.number()}`;
+ const date = formatDate(new Date(new Date().getFullYear() + 2, 1, 1));
+
+ createGiftCard({
+ tag: name,
+ amount: 10,
+ currency: "USD"
+ })
+ .then(giftCard => {
+ cy.visit(giftCardDetailsUrl(giftCard.id))
+ .waitForProgressBarToNotBeVisible()
+ .get(GIFT_CARD_UPDATE.expireCheckbox)
+ .click()
+ .get(GIFT_CARD_UPDATE.expireDateInput)
+ .type(date)
+ .get(GIFT_CARD_UPDATE.removeTagButton)
+ .click()
+ .get(GIFT_CARD_UPDATE.giftCardTagSelect)
+ .find("input")
+ .clear()
+ .type(updatedName)
+ .get(GIFT_CARD_UPDATE.autocompleteCustomOption)
+ .click()
+ .addAliasToGraphRequest("GiftCardUpdate")
+ .get(BUTTON_SELECTORS.confirm)
+ .click()
+ .waitForRequestAndCheckIfNoErrors("@GiftCardUpdate");
+ getGiftCardWithId(giftCard.id);
+ })
+ .then(giftCard => {
+ expect(giftCard.tags[0].name.toLowerCase()).to.eq(
+ updatedName.toLowerCase()
+ );
+ expect(giftCard.expiryDate).to.eq(date);
+ });
+ });
+ });
+});
diff --git a/cypress/integration/checkout/giftCardsInCheckout.js b/cypress/integration/checkout/giftCardsInCheckout.js
deleted file mode 100644
index d52f4cf75..000000000
--- a/cypress/integration/checkout/giftCardsInCheckout.js
+++ /dev/null
@@ -1,162 +0,0 @@
-//
-import faker from "faker";
-
-import { completeCheckout } from "../../support/api/requests/Checkout";
-import {
- createGiftCard,
- getGiftCardWithId,
- giftCardDeactivate
-} from "../../support/api/requests/GiftCard";
-import { deleteGiftCardsWithTagStartsWith } from "../../support/api/utils/catalog/giftCardUtils";
-import * as channelsUtils from "../../support/api/utils/channelsUtils";
-import {
- addPayment,
- createCheckoutWithVoucher,
- purchaseProductWithPromoCode
-} from "../../support/api/utils/ordersUtils";
-import * as productsUtils from "../../support/api/utils/products/productsUtils";
-import {
- createShipping,
- deleteShippingStartsWith
-} from "../../support/api/utils/shippingUtils";
-import filterTests from "../../support/filterTests";
-import { changeGiftCardActiveStatus } from "../../support/pages/catalog/giftCardPage";
-
-filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
- describe("Gift cards in checkout", () => {
- const startsWith = "GiftCardsCheckout";
- const productPrice = 50;
- const shippingPrice = 50;
-
- let defaultChannel;
- let productType;
- let attribute;
- let category;
- let shippingMethod;
- let variants;
- let address;
- let dataForCheckout;
- const giftCardData = {
- amount: 150,
- currency: "USD"
- };
-
- before(() => {
- cy.clearSessionData().loginUserViaRequest();
- channelsUtils.deleteChannelsStartsWith(startsWith);
- productsUtils.deleteProductsStartsWith(startsWith);
- deleteShippingStartsWith(startsWith);
- deleteGiftCardsWithTagStartsWith(startsWith);
-
- const name = `${startsWith}${faker.datatype.number()}`;
-
- productsUtils
- .createTypeAttributeAndCategoryForProduct({ name, kind: "GIFT_CARD" })
- .then(
- ({
- productType: productTypeResp,
- attribute: attributeResp,
- category: categoryResp
- }) => {
- 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 }) => {
- shippingMethod = shippingMethodResp;
- productsUtils.createProductInChannel({
- name,
- channelId: defaultChannel.id,
- warehouseId: warehouse.id,
- productTypeId: productType.id,
- attributeId: attribute.id,
- categoryId: category.id,
- price: productPrice
- });
- }
- )
- .then(({ variantsList: variantsResp }) => {
- variants = variantsResp;
-
- dataForCheckout = {
- address,
- auth: "token",
- channelSlug: defaultChannel.slug,
- shippingMethodName: shippingMethod.name,
- variantsList: variants
- };
- });
- });
-
- beforeEach(() => {
- cy.clearSessionData().loginUserViaRequest();
- });
-
- it("should enable gift card", () => {
- giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
- let giftCard;
-
- createGiftCard(giftCardData)
- .then(giftCardResp => {
- giftCard = giftCardResp;
- giftCardDeactivate(giftCard.id);
- })
- .then(() => {
- changeGiftCardActiveStatus(giftCard.id);
- dataForCheckout.voucherCode = giftCard.code;
- purchaseProductWithPromoCode(dataForCheckout);
- })
- .then(({ order }) => {
- expect(order.total.gross.amount).to.eq(0);
- getGiftCardWithId(giftCard.id);
- })
- .then(giftCardResp => {
- expect(giftCardResp.initialBalance.amount).to.eq(giftCardData.amount);
- expect(giftCardResp.currentBalance.amount).to.eq(
- giftCardData.amount - productPrice - shippingPrice
- );
- });
- });
-
- it("should disable giftCard", () => {
- giftCardData.tag = `${startsWith}${faker.datatype.number()}`;
- let giftCard;
-
- createGiftCard(giftCardData)
- .then(giftCardResp => {
- giftCard = giftCardResp;
- changeGiftCardActiveStatus(giftCard.id);
- dataForCheckout.voucherCode = giftCard.code;
- createCheckoutWithVoucher(dataForCheckout);
- })
- .then(({ addPromoCodeResp, checkout }) => {
- expect(addPromoCodeResp.checkoutErrors[0].field).to.eq("promoCode");
- addPayment(checkout.id);
- completeCheckout(checkout.id);
- })
- .then(() => {
- getGiftCardWithId(giftCard.id);
- })
- .then(giftCardResp => {
- expect(giftCardResp.currentBalance.amount).to.eq(giftCardData.amount);
- });
- });
- });
-});
diff --git a/cypress/support/api/requests/Checkout.js b/cypress/support/api/requests/Checkout.js
index ae2acb511..af0f4397e 100644
--- a/cypress/support/api/requests/Checkout.js
+++ b/cypress/support/api/requests/Checkout.js
@@ -141,6 +141,7 @@ export function completeCheckout(checkoutId, paymentData) {
const mutation = `mutation{
checkoutComplete(checkoutId:"${checkoutId}" ${paymentDataLine}){
order{
+ userEmail
id
lines{
id
diff --git a/cypress/support/api/requests/GiftCard.js b/cypress/support/api/requests/GiftCard.js
index b75526348..d1bb6610c 100644
--- a/cypress/support/api/requests/GiftCard.js
+++ b/cypress/support/api/requests/GiftCard.js
@@ -107,11 +107,11 @@ export function getGiftCardWithId(id) {
return cy.sendRequestWithQuery(query).its("body.data.giftCard");
}
-export function createGiftCard({ tag, currency, amount }) {
+export function createGiftCard({ tag, currency, amount, isActive = true }) {
const mutation = `mutation{
giftCardCreate(input:{
addTags:"${tag}"
- isActive: true
+ isActive: ${isActive}
balance: {
currency: "${currency}"
amount: ${amount}
diff --git a/cypress/support/api/utils/catalog/giftCardUtils.js b/cypress/support/api/utils/catalog/giftCardUtils.js
index 51f00d20f..d4aa93b02 100644
--- a/cypress/support/api/utils/catalog/giftCardUtils.js
+++ b/cypress/support/api/utils/catalog/giftCardUtils.js
@@ -1,4 +1,12 @@
-import { deleteGiftCard, getGiftCards } from "../../requests/GiftCard";
+import {
+ deleteGiftCard,
+ getGiftCards,
+ getGiftCardWithId
+} from "../../requests/GiftCard";
+import {
+ createCheckoutWithVoucher,
+ purchaseProductWithPromoCode
+} from "../ordersUtils";
export function deleteGiftCardsWithTagStartsWith(tag) {
getGiftCards(100).then(resp => {
@@ -6,7 +14,7 @@ export function deleteGiftCardsWithTagStartsWith(tag) {
if (giftCardArray) {
giftCardArray.edges.forEach(element => {
const includes = element.node.tags.find(element =>
- element.name.includes(tag.toLowerCase())
+ element.name.toLowerCase().includes(tag.toLowerCase())
);
if (includes) {
deleteGiftCard(element.node.id);
@@ -15,3 +23,66 @@ export function deleteGiftCardsWithTagStartsWith(tag) {
}
});
}
+
+export function isGiftCardDataAsExpected({
+ giftCardId,
+ expectedAmount,
+ userEmail,
+ initialBalance
+}) {
+ let dataAsExpected = true;
+ return getGiftCardWithId(giftCardId).then(giftCard => {
+ if (expectedAmount) {
+ dataAsExpected = expectedAmount === giftCard.currentBalance.amount;
+ }
+ if (userEmail) {
+ dataAsExpected = userEmail === giftCard.usedByEmail;
+ }
+ if (initialBalance) {
+ dataAsExpected = initialBalance === giftCard.initialBalance.amount;
+ }
+ return dataAsExpected;
+ });
+}
+
+export function createCheckoutWithDisabledGiftCard({
+ channelSlug,
+ email = "email@example.com",
+ variantsList,
+ address,
+ shippingMethodName,
+ voucherCode,
+ auth
+}) {
+ return createCheckoutWithVoucher({
+ channelSlug,
+ email,
+ variantsList,
+ address,
+ shippingMethodName,
+ voucherCode,
+ auth
+ }).then(({ addPromoCodeResp, checkout }) => {
+ expect(addPromoCodeResp.checkoutErrors[0].field).to.eq("promoCode");
+ return checkout;
+ });
+}
+
+export function purchaseProductWithActiveGiftCard({
+ giftCard,
+ expectedAmount,
+ initialAmount,
+ dataForCheckout,
+ expectedOrderPrice
+}) {
+ return purchaseProductWithPromoCode(dataForCheckout).then(({ order }) => {
+ expect(order.total.gross.amount).to.eq(expectedOrderPrice);
+ expect(order.userEmail).to.eq(dataForCheckout.email);
+ return isGiftCardDataAsExpected({
+ giftCardId: giftCard.id,
+ expectedAmount,
+ userEmail: dataForCheckout.email,
+ initialBalance: initialAmount
+ });
+ });
+}
diff --git a/cypress/support/pages/catalog/giftCardPage.js b/cypress/support/pages/catalog/giftCardPage.js
index 803b42f11..c6e09c1eb 100644
--- a/cypress/support/pages/catalog/giftCardPage.js
+++ b/cypress/support/pages/catalog/giftCardPage.js
@@ -1,6 +1,9 @@
-import { GIFT_CARD_DIALOG } from "../../../elements/giftCard/giftCardDialog";
-import { GIFT_CARD_LIST } from "../../../elements/giftCard/giftCardList";
-import { GIFT_CARD_UPDATE } from "../../../elements/giftCard/giftCardUpdate";
+import { GIFT_CARD_DIALOG } from "../../../elements/catalog/giftCard/giftCardDialog";
+import {
+ GIFT_CARD_LIST,
+ giftCardRow
+} from "../../../elements/catalog/giftCard/giftCardList";
+import { GIFT_CARD_UPDATE } from "../../../elements/catalog/giftCard/giftCardUpdate";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { giftCardDetailsUrl, urlList } from "../../../fixtures/urlList";
@@ -67,3 +70,10 @@ export function changeGiftCardActiveStatus(giftCardId) {
.click()
.confirmationMessageShouldDisappear();
}
+
+export function selectGiftCard(giftCardId) {
+ return cy
+ .get(giftCardRow(giftCardId))
+ .find(GIFT_CARD_LIST.selectGiftCardCheckbox)
+ .click();
+}
diff --git a/src/giftCards/GiftCardsList/GiftCardsListHeader/GiftCardsListHeader.tsx b/src/giftCards/GiftCardsList/GiftCardsListHeader/GiftCardsListHeader.tsx
index 03c9975d8..994987fcf 100644
--- a/src/giftCards/GiftCardsList/GiftCardsListHeader/GiftCardsListHeader.tsx
+++ b/src/giftCards/GiftCardsList/GiftCardsListHeader/GiftCardsListHeader.tsx
@@ -51,7 +51,7 @@ const GiftCardsListHeader: React.FC = () => {
diff --git a/src/giftCards/GiftCardsList/GiftCardsListTable/GiftCardsListTable.tsx b/src/giftCards/GiftCardsList/GiftCardsListTable/GiftCardsListTable.tsx
index 6d42fb154..982bb824c 100644
--- a/src/giftCards/GiftCardsList/GiftCardsListTable/GiftCardsListTable.tsx
+++ b/src/giftCards/GiftCardsList/GiftCardsListTable/GiftCardsListTable.tsx
@@ -108,9 +108,11 @@ const GiftCardsListTable: React.FC = () => {
className={classes.row}
key={id}
hover={!!giftCard}
+ data-test-id={"gift-card-row-" + id}
>
{
onClick={handleActivateGiftCards}
variant="secondary"
transitionState={activateGiftCardsOpts?.status}
+ data-test-id="activate-gift-cards"
>
{intl.formatMessage(messages.enableLabel)}
@@ -122,6 +123,7 @@ const BulkEnableDisableSection: React.FC = () => {
onClick={handleDeactivateGiftCards}
variant="secondary"
transitionState={deactivateGiftCardsOpts?.status}
+ data-test-id="deactivate-gift-cards"
>
{intl.formatMessage(messages.disableLabel)}