diff --git a/cypress/elements/giftCard/giftCardUpdate.js b/cypress/elements/giftCard/giftCardUpdate.js index 470899807..f93cdb93f 100644 --- a/cypress/elements/giftCard/giftCardUpdate.js +++ b/cypress/elements/giftCard/giftCardUpdate.js @@ -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"]' }; diff --git a/cypress/integration/catalog/giftCards.js b/cypress/integration/catalog/giftCards.js index 61598a987..fdc9e49ed 100644 --- a/cypress/integration/catalog/giftCards.js +++ b/cypress/integration/catalog/giftCards.js @@ -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); + }); + }); }); }); diff --git a/cypress/support/api/requests/GiftCard.js b/cypress/support/api/requests/GiftCard.js index 3124c415d..d89b69019 100644 --- a/cypress/support/api/requests/GiftCard.js +++ b/cypress/support/api/requests/GiftCard.js @@ -37,6 +37,8 @@ export function getGiftCardWithId(id) { const query = `query{ giftCard(id:"${id}"){ isActive + expiryDate + tag currentBalance{ currency amount