tests for gift cards (#1677)

This commit is contained in:
Karolina Rakoczy 2021-12-17 12:08:13 +01:00 committed by GitHub
parent 5a14884f9d
commit 866bb91177
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 2 deletions

View file

@ -1,3 +1,8 @@
export const GIFT_CARD_UPDATE = {
changeActiveStatusButton: '[data-test-id="enable-button"]'
changeActiveStatusButton: '[data-test-id="enable-button"]',
consentCheckbox: '[name="delete-assigned-items-consent"]',
giftCardTagSelect: '[data-test-id="gift-card-tag-select-field"]',
expireCheckbox: '[name="cardExpires"]',
expireDateInput: '[name="expiryDate"]',
autocompleteOption: '[data-test-type="custom"]'
};

View file

@ -3,7 +3,14 @@
import faker from "faker";
import { getGiftCardWithTag } from "../../support/api/requests/GiftCard";
import { GIFT_CARD_UPDATE } from "../../elements/giftCard/giftCardUpdate";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { giftCardDetailsUrl } from "../../fixtures/urlList";
import {
createGiftCard,
getGiftCardWithId,
getGiftCardWithTag
} 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";
@ -102,5 +109,61 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
expect(giftCard.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.giftCardTagSelect)
.find("input")
.clear()
.type(updatedName)
.get(GIFT_CARD_UPDATE.autocompleteOption)
.click()
.addAliasToGraphRequest("GiftCardUpdate")
.get(BUTTON_SELECTORS.confirm)
.click()
.waitForRequestAndCheckIfNoErrors("@GiftCardUpdate");
getGiftCardWithId(giftCard.id);
})
.then(giftCard => {
expect(giftCard.tag).to.eq(updatedName);
expect(giftCard.expiryDate).to.eq(date);
});
});
});
});

View file

@ -37,6 +37,8 @@ export function getGiftCardWithId(id) {
const query = `query{
giftCard(id:"${id}"){
isActive
expiryDate
tag
currentBalance{
currency
amount