|
| 1 | +import redeemGiftPage from 'codecrafters-frontend/tests/pages/redeem-gift-page'; |
| 2 | +import testScenario from 'codecrafters-frontend/mirage/scenarios/test'; |
| 3 | +import { module, test } from 'qunit'; |
| 4 | +import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers'; |
| 5 | +import { signInAsSubscriber } from 'codecrafters-frontend/tests/support/authentication-helpers'; |
| 6 | +import { assertTooltipContent } from 'ember-tooltips/test-support'; |
| 7 | + |
| 8 | +module('Acceptance | redeem-gift-page | redeem', function (hooks) { |
| 9 | + setupApplicationTest(hooks); |
| 10 | + |
| 11 | + test('user cannot redeem a gift if they are not logged in', async function (assert) { |
| 12 | + testScenario(this.server); |
| 13 | + |
| 14 | + this.server.schema.membershipGifts.create({ |
| 15 | + secretToken: 'xyz', |
| 16 | + giftMessage: 'Happy Birthday! Enjoy your CodeCrafters membership.', |
| 17 | + validityInDays: 365, |
| 18 | + purchasedAt: new Date(), |
| 19 | + claimedAt: null, |
| 20 | + }); |
| 21 | + |
| 22 | + await redeemGiftPage.visit({ secret_token: 'xyz' }); |
| 23 | + assert.notOk(redeemGiftPage.giftDetailsContainer.redeemButton.isDisabled, 'Redeem button should be enabled for anonymous users'); |
| 24 | + |
| 25 | + await redeemGiftPage.giftDetailsContainer.redeemButton.hover(); |
| 26 | + assertTooltipContent(assert, { contentString: 'Click to login via GitHub' }); |
| 27 | + }); |
| 28 | + |
| 29 | + test('user cannot redeem a gift if they already have a membership', async function (assert) { |
| 30 | + testScenario(this.server); |
| 31 | + |
| 32 | + signInAsSubscriber(this.owner, this.server); |
| 33 | + |
| 34 | + this.server.schema.membershipGifts.create({ |
| 35 | + secretToken: 'xyz', |
| 36 | + giftMessage: 'Happy Birthday! Enjoy your CodeCrafters membership.', |
| 37 | + validityInDays: 365, |
| 38 | + purchasedAt: new Date(), |
| 39 | + claimedAt: null, |
| 40 | + }); |
| 41 | + |
| 42 | + await redeemGiftPage.visit({ secret_token: 'xyz' }); |
| 43 | + assert.ok(redeemGiftPage.giftDetailsContainer.redeemButton.isDisabled, 'Redeem button should be disabled for users with existing membership'); |
| 44 | + |
| 45 | + await redeemGiftPage.giftDetailsContainer.redeemButton.hover(); |
| 46 | + |
| 47 | + assertTooltipContent(assert, { |
| 48 | + contentString: 'You already have full access to CodeCrafters. You can claim this gift once your membership expires.', |
| 49 | + }); |
| 50 | + }); |
| 51 | +}); |
0 commit comments