mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
Fall Festival Gem Promo (#138)
* content: add gems blocks * gemsBlocks: include ios and android identifiers * wip: promo code * split common constants into multiple files * add second promo part * geCurrentEvent, refactor promo * fix lint * fix exports, use world state api * start adding world state tests * remove console.log * use gems block for purchases * remove comments * fix most unit tests * restore comment * fix lint * prevent apple/google gift tests from breaking other tests when stub is not reset * fix unit tests, clarify tests names * iap: use gift object when gifting gems * allow gift object with less data * fix iap tests, remove findById stubs * iap: require less data from the mobile apps * apply discounts * add missing worldState file * fix lint * add test event * start removing 20 gems option for web * start adding support for all gems packages on web * fix unit tests for apple, stripe and google * amazon: support all gems blocks * paypal: support all gems blocks * fix payments unit tests, add tests for getGemsBlock * web: add gems plans with discounts, update stripe * fix amazon and paypal clients, payments success modals * amazon pay: disabled state * update icons, start abstracting payments buttons * begin redesign * redesign gems modal * fix buttons * fix hover color for gems modal close icon * add key to world state current event * extend test event length * implement gems modals designs * early test fall2020 * fix header banner position * add missing files * use iso 8601 for dates, minor ui fixes * fix time zones * events: fix ISO8601 format * fix css indentation * start abstracting banners * refactor payments buttons * test spooky, fix group plans box * implement gems promo banners, refactor banners, fixes * fix lint * fix dates * remove unused i18n strings * fix stripe integration test * fix world state integration tests * the current active event * add missing unit tests * add storybook story for payments buttons component * fix typo * fix(stripe): correct label when gifting subscriptions
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import moment from 'moment';
|
||||
|
||||
import * as sender from '../../../../../website/server/libs/email';
|
||||
import common from '../../../../../website/common';
|
||||
import api from '../../../../../website/server/libs/payments/payments';
|
||||
import * as analytics from '../../../../../website/server/libs/analyticsService';
|
||||
import * as notifications from '../../../../../website/server/libs/pushNotifications';
|
||||
@@ -9,6 +10,7 @@ import { translate as t } from '../../../../helpers/api-integration/v3';
|
||||
import {
|
||||
generateGroup,
|
||||
} from '../../../../helpers/api-unit.helper';
|
||||
import * as worldState from '../../../../../website/server/libs/worldState';
|
||||
|
||||
describe('payments/index', () => {
|
||||
let user; let group; let data; let
|
||||
@@ -555,6 +557,7 @@ describe('payments/index', () => {
|
||||
beforeEach(() => {
|
||||
data = {
|
||||
user,
|
||||
gemsBlock: common.content.gems['21gems'],
|
||||
paymentMethod: 'payment',
|
||||
headers: {
|
||||
'x-client': 'habitica-web',
|
||||
@@ -564,22 +567,6 @@ describe('payments/index', () => {
|
||||
});
|
||||
|
||||
context('Self Purchase', () => {
|
||||
it('amount property defaults to 5', async () => {
|
||||
expect(user.balance).to.eql(0);
|
||||
|
||||
await api.buyGems(data);
|
||||
|
||||
expect(user.balance).to.eql(5);
|
||||
});
|
||||
|
||||
it('can set amount that is purchased', async () => {
|
||||
data.amount = 13;
|
||||
|
||||
await api.buyGems(data);
|
||||
|
||||
expect(user.balance).to.eql(13);
|
||||
});
|
||||
|
||||
it('sends a donation email', async () => {
|
||||
await api.buyGems(data);
|
||||
|
||||
@@ -588,6 +575,51 @@ describe('payments/index', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('No Active Promotion', () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(worldState, 'getCurrentEvent').returns(null);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
worldState.getCurrentEvent.restore();
|
||||
});
|
||||
|
||||
it('does not apply a discount', async () => {
|
||||
const balanceBefore = user.balance;
|
||||
|
||||
await api.buyGems(data);
|
||||
|
||||
const balanceAfter = user.balance;
|
||||
const balanceDiff = balanceAfter - balanceBefore;
|
||||
|
||||
expect(balanceDiff * 4).to.eql(21);
|
||||
});
|
||||
});
|
||||
|
||||
context('Active Promotion', () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(worldState, 'getCurrentEvent').returns({
|
||||
...common.content.events.fall2020,
|
||||
event: 'fall2020',
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
worldState.getCurrentEvent.restore();
|
||||
});
|
||||
|
||||
it('applies a discount', async () => {
|
||||
const balanceBefore = user.balance;
|
||||
|
||||
await api.buyGems(data);
|
||||
|
||||
const balanceAfter = user.balance;
|
||||
const balanceDiff = balanceAfter - balanceBefore;
|
||||
|
||||
expect(balanceDiff * 4).to.eql(30);
|
||||
});
|
||||
});
|
||||
|
||||
context('Gift', () => {
|
||||
let recipient;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user