saleor-dashboard/cypress/integration/giftCards.js
2021-09-08 13:32:05 +02:00

103 lines
3 KiB
JavaScript

// <reference types="cypress" />
import faker from "faker";
import { getGiftCardWithTag } from "../apiRequests/giftCards";
import {
expiryPeriods,
openAndFillUpCreateGiftCardDialog,
saveGiftCard,
setExpiryDate,
setExpiryPeriod,
setNeverExpire
} from "../steps/giftCardSteps";
import filterTests from "../support/filterTests";
import { formatDate } from "../support/format/formatDate";
filterTests(["all"], () => {
describe("Tests for gift cards", () => {
const startsWith = "GiftCards";
const amount = 50;
const currency = "USD";
before(() => {
cy.clearSessionData().loginUserViaRequest();
});
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
});
setNeverExpire();
saveGiftCard()
.then(createdGiftCardCode => {
giftCardCode = createdGiftCardCode;
getGiftCardWithTag(name);
})
.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;
openAndFillUpCreateGiftCardDialog({
note: name,
tag: name,
amount,
currency
});
setExpiryPeriod(2, expiryPeriods.MONTH);
saveGiftCard()
.then(createdGiftCardCode => {
giftCardCode = createdGiftCardCode;
getGiftCardWithTag(name);
})
.then(giftCard => {
expect(giftCard.code).to.eq(giftCardCode);
expect(giftCard.initialBalance.amount).to.eq(amount);
expect(giftCard.initialBalance.currency).to.eq(currency);
expect(giftCard.expiryPeriod.amount).to.eq(2);
expect(giftCard.expiryPeriod.type).to.eq("MONTH");
});
});
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;
getGiftCardWithTag(name);
})
.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);
});
});
});
});