mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-10-28 11:42:29 +01:00
* 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
90 lines
3.4 KiB
JavaScript
90 lines
3.4 KiB
JavaScript
import moment from 'moment';
|
|
import calculateSubscriptionTerminationDate from '../../../../../../website/server/libs/payments/calculateSubscriptionTerminationDate';
|
|
import api from '../../../../../../website/server/libs/payments/payments';
|
|
|
|
const groupPlanId = api.constants.GROUP_PLAN_CUSTOMER_ID;
|
|
|
|
describe('stripe - #calculateSubscriptionTerminationDate', () => {
|
|
let plan;
|
|
let nextBill;
|
|
|
|
beforeEach(() => {
|
|
plan = {
|
|
customerId: 'customer-id',
|
|
extraMonths: 0,
|
|
};
|
|
nextBill = moment();
|
|
});
|
|
|
|
it('should extend date to the exact amount of days left before the next bill will occur', () => {
|
|
nextBill = moment()
|
|
.add(5, 'days');
|
|
const expectedTerminationDate = moment()
|
|
.add(5, 'days');
|
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
});
|
|
|
|
it('if nextBill is null, add 30 days to termination date', () => {
|
|
nextBill = null;
|
|
const expectedTerminationDate = moment()
|
|
.add(30, 'days');
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
|
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
});
|
|
|
|
it('if nextBill is null and it\'s a group plan, add 2 days instead of 30', () => {
|
|
nextBill = null;
|
|
plan.customerId = api.constants.GROUP_PLAN_CUSTOMER_ID;
|
|
const expectedTerminationDate = moment()
|
|
.add(2, 'days');
|
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
});
|
|
|
|
it('should add 30.5 days for each extraMonth', () => {
|
|
plan.extraMonths = 4;
|
|
const expectedTerminationDate = moment()
|
|
.add(30.5 * 4, 'days');
|
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
});
|
|
|
|
it('should round up if total days gained by extraMonth is a decimal number', () => {
|
|
plan.extraMonths = 5;
|
|
const expectedTerminationDate = moment()
|
|
.add(Math.ceil(30.5 * 5), 'days');
|
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
});
|
|
|
|
it('behaves like extraMonths is 0 if it\'s set to a negative number', () => {
|
|
plan.extraMonths = -5;
|
|
const expectedTerminationDate = moment();
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
});
|
|
|
|
it('returns current terminated date if it exists and is later than newly calculated date', () => {
|
|
const expectedTerminationDate = moment().add({ months: 5 }).toDate();
|
|
plan.dateTerminated = expectedTerminationDate;
|
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
|
|
|
expect(terminationDate).to.equal(expectedTerminationDate);
|
|
});
|
|
|
|
it('returns the calculated termination date if the plan does not have one', () => {
|
|
nextBill = moment().add(5, 'days');
|
|
const expectedTerminationDate = moment().add(5, 'days');
|
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
});
|
|
});
|