Add tests for gift cards (#1779)

* added tests for gift cards

* update tests names for gift cards

* change naming, move functions from test file, fix testId

* fix move function

* Edit test case name

Co-authored-by: Ewa Czerniak <ewa.czerniak@saleor.io>

Co-authored-by: Ewa Czerniak <ewa.czerniak@saleor.io>
This commit is contained in:
Karolina Rakoczy 2022-02-01 11:58:02 +01:00 committed by GitHub
parent 5892bca40b
commit 35e48a635f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 688 additions and 346 deletions

View file

@ -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}"]`;

View file

@ -1,3 +0,0 @@
export const GIFT_CARD_LIST = {
issueCardButton: '[data-test-id="issueCardButton"]'
};

View file

@ -1,173 +0,0 @@
/// <reference types="cypress" />
/// <reference types="../../support"/>
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);
});
});
});
});

View file

@ -0,0 +1,282 @@
/// <reference types="cypress" />
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);
});
});
});
});

View file

@ -0,0 +1,106 @@
/// <reference types="cypress" />
/// <reference types="../../../support"/>
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);
});
});
});
});

View file

@ -0,0 +1,107 @@
/// <reference types="cypress" />
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;
});
});
});
});

View file

@ -0,0 +1,90 @@
/// <reference types="cypress" />
/// <reference types="../../../support"/>
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);
});
});
});
});

View file

@ -1,162 +0,0 @@
// <reference types="cypress" />
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);
});
});
});
});

View file

@ -141,6 +141,7 @@ export function completeCheckout(checkoutId, paymentData) {
const mutation = `mutation{
checkoutComplete(checkoutId:"${checkoutId}" ${paymentDataLine}){
order{
userEmail
id
lines{
id

View file

@ -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}

View file

@ -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
});
});
}

View file

@ -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();
}

View file

@ -51,7 +51,7 @@ const GiftCardsListHeader: React.FC = () => {
<Button
variant="primary"
onClick={openCreateDialog}
data-test-id="issueCardButton"
data-test-id="issue-card-button"
>
{intl.formatMessage(messages.issueButtonLabel)}
</Button>

View file

@ -108,9 +108,11 @@ const GiftCardsListTable: React.FC = () => {
className={classes.row}
key={id}
hover={!!giftCard}
data-test-id={"gift-card-row-" + id}
>
<TableCell padding="checkbox">
<Checkbox
data-test-id="select-gift-card-checkbox"
disabled={!giftCard}
disableClickPropagation
checked={isSelected(id)}

View file

@ -113,6 +113,7 @@ const BulkEnableDisableSection: React.FC = () => {
onClick={handleActivateGiftCards}
variant="secondary"
transitionState={activateGiftCardsOpts?.status}
data-test-id="activate-gift-cards"
>
{intl.formatMessage(messages.enableLabel)}
</ConfirmButton>
@ -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)}
</ConfirmButton>