2021-09-27 10:04:21 +00:00
|
|
|
/// <reference types="cypress" />
|
|
|
|
/// <reference types="../../support"/>
|
|
|
|
|
2021-09-08 11:32:05 +00:00
|
|
|
import faker from "faker";
|
|
|
|
|
2021-09-27 10:04:21 +00:00
|
|
|
import { getGiftCardWithTag } from "../../support/api/requests/GiftCard";
|
2021-09-29 13:24:47 +00:00
|
|
|
import { deleteGiftCardsWithTagStartsWith } from "../../support/api/utils/catalog/giftCardUtils";
|
|
|
|
import { addToDate } from "../../support/api/utils/misc";
|
2021-09-27 10:04:21 +00:00
|
|
|
import filterTests from "../../support/filterTests";
|
|
|
|
import { formatDate } from "../../support/formatData/formatDate";
|
2021-09-08 11:32:05 +00:00
|
|
|
import {
|
|
|
|
expiryPeriods,
|
|
|
|
openAndFillUpCreateGiftCardDialog,
|
|
|
|
saveGiftCard,
|
|
|
|
setExpiryDate,
|
2021-09-29 13:24:47 +00:00
|
|
|
setExpiryPeriod
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../support/pages/catalog/giftCardPage";
|
2021-09-08 11:32:05 +00:00
|
|
|
|
2021-09-27 10:04:21 +00:00
|
|
|
filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
|
2021-09-08 11:32:05 +00:00
|
|
|
describe("Tests for gift cards", () => {
|
|
|
|
const startsWith = "GiftCards";
|
|
|
|
const amount = 50;
|
|
|
|
const currency = "USD";
|
|
|
|
|
|
|
|
before(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
2021-09-29 13:24:47 +00:00
|
|
|
deleteGiftCardsWithTagStartsWith(startsWith);
|
2021-09-08 11:32:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.clearSessionData().loginUserViaRequest();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create never expire gift card", () => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let giftCardCode;
|
|
|
|
|
|
|
|
openAndFillUpCreateGiftCardDialog({
|
|
|
|
note: name,
|
|
|
|
tag: name,
|
|
|
|
amount,
|
|
|
|
currency
|
|
|
|
});
|
|
|
|
saveGiftCard()
|
|
|
|
.then(createdGiftCardCode => {
|
|
|
|
giftCardCode = createdGiftCardCode;
|
2021-09-29 13:24:47 +00:00
|
|
|
getGiftCardWithTag(name, true);
|
2021-09-08 11:32:05 +00:00
|
|
|
})
|
|
|
|
.then(giftCard => {
|
|
|
|
expect(giftCard.code).to.eq(giftCardCode);
|
|
|
|
expect(giftCard.initialBalance.amount).to.eq(amount);
|
|
|
|
expect(giftCard.initialBalance.currency).to.eq(currency);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create gift card with two moths expiry", () => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let giftCardCode;
|
2021-09-29 13:24:47 +00:00
|
|
|
const expectedExpiryDate = addToDate(new Date(), 2, "M");
|
2021-09-08 11:32:05 +00:00
|
|
|
|
|
|
|
openAndFillUpCreateGiftCardDialog({
|
|
|
|
note: name,
|
|
|
|
tag: name,
|
|
|
|
amount,
|
|
|
|
currency
|
|
|
|
});
|
|
|
|
setExpiryPeriod(2, expiryPeriods.MONTH);
|
|
|
|
saveGiftCard()
|
|
|
|
.then(createdGiftCardCode => {
|
|
|
|
giftCardCode = createdGiftCardCode;
|
2021-09-29 13:24:47 +00:00
|
|
|
getGiftCardWithTag(name, true);
|
2021-09-08 11:32:05 +00:00
|
|
|
})
|
|
|
|
.then(giftCard => {
|
|
|
|
expect(giftCard.code).to.eq(giftCardCode);
|
|
|
|
expect(giftCard.initialBalance.amount).to.eq(amount);
|
|
|
|
expect(giftCard.initialBalance.currency).to.eq(currency);
|
2021-09-29 13:24:47 +00:00
|
|
|
expect(giftCard.expiryDate).to.eq(expectedExpiryDate);
|
2021-09-08 11:32:05 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create gift card with date expiry", () => {
|
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
let giftCardCode;
|
|
|
|
const date = formatDate(new Date(new Date().getFullYear() + 2, 1, 1));
|
|
|
|
|
|
|
|
openAndFillUpCreateGiftCardDialog({
|
|
|
|
note: name,
|
|
|
|
tag: name,
|
|
|
|
amount,
|
|
|
|
currency
|
|
|
|
});
|
|
|
|
setExpiryDate(date);
|
|
|
|
saveGiftCard()
|
|
|
|
.then(createdGiftCardCode => {
|
|
|
|
giftCardCode = createdGiftCardCode;
|
2021-09-29 13:24:47 +00:00
|
|
|
getGiftCardWithTag(name, true);
|
2021-09-08 11:32:05 +00:00
|
|
|
})
|
|
|
|
.then(giftCard => {
|
|
|
|
expect(giftCard.code).to.eq(giftCardCode);
|
|
|
|
expect(giftCard.initialBalance.amount).to.eq(amount);
|
|
|
|
expect(giftCard.initialBalance.currency).to.eq(currency);
|
|
|
|
expect(giftCard.expiryDate).to.eq(date);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|