saleor-dashboard/cypress/integration/catalog/giftCards.js
Karolina Rakoczy 2c64a966cc
Saleor 4437 refactor tests (#1389)
* reference type cypress working

* refactor

* remove screenshots

* add reference

* add slash marker

* run tests based on shop version

* fix run tests based on shop version

* fix run tests based on shop version

* change base url to localhost

* fix plugins

* fix plugins

* fix plugins

* fix plugins

* fix plugins

* fix plugins

* fix yml

* fix yml

* chage file names

* fix files names

* fix broken imports add checking for errors in grpah responses

* fix broken imports add checking for errors in grpah responses

* update jest

* fix snapshot
2021-09-27 12:04:21 +02:00

105 lines
3.1 KiB
JavaScript

/// <reference types="cypress" />
/// <reference types="../../support"/>
import faker from "faker";
import { getGiftCardWithTag } from "../../support/api/requests/GiftCard";
import filterTests from "../../support/filterTests";
import { formatDate } from "../../support/formatData/formatDate";
import {
expiryPeriods,
openAndFillUpCreateGiftCardDialog,
saveGiftCard,
setExpiryDate,
setExpiryPeriod,
setNeverExpire
} 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();
});
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);
});
});
});
});