2020-03-29 12:54:13 +00:00
|
|
|
import moment from 'moment';
|
2020-05-05 15:16:35 +00:00
|
|
|
import calculateSubscriptionTerminationDate from '../../../../../../website/server/libs/payments/calculateSubscriptionTerminationDate';
|
2020-03-29 12:54:13 +00:00
|
|
|
import api from '../../../../../../website/server/libs/payments/payments';
|
|
|
|
|
|
2020-05-05 15:16:35 +00:00
|
|
|
const groupPlanId = api.constants.GROUP_PLAN_CUSTOMER_ID;
|
|
|
|
|
|
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
2020-09-21 14:22:13 +00:00
|
|
|
describe('stripe - #calculateSubscriptionTerminationDate', () => {
|
2020-03-29 12:54:13 +00:00
|
|
|
let plan;
|
|
|
|
|
let nextBill;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
plan = {
|
|
|
|
|
customerId: 'customer-id',
|
|
|
|
|
extraMonths: 0,
|
|
|
|
|
};
|
|
|
|
|
nextBill = moment();
|
|
|
|
|
});
|
2020-05-05 15:16:35 +00:00
|
|
|
|
2020-03-29 12:54:13 +00:00
|
|
|
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');
|
|
|
|
|
|
2020-05-05 15:16:35 +00:00
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
2020-03-29 12:54:13 +00:00
|
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
|
|
|
});
|
2020-05-05 15:16:35 +00:00
|
|
|
|
2020-03-29 12:54:13 +00:00
|
|
|
it('if nextBill is null, add 30 days to termination date', () => {
|
|
|
|
|
nextBill = null;
|
|
|
|
|
const expectedTerminationDate = moment()
|
|
|
|
|
.add(30, 'days');
|
2020-05-05 15:16:35 +00:00
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
2020-03-29 12:54:13 +00:00
|
|
|
|
|
|
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
|
|
|
});
|
2020-05-05 15:16:35 +00:00
|
|
|
|
2020-03-29 12:54:13 +00:00
|
|
|
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');
|
|
|
|
|
|
2020-05-05 15:16:35 +00:00
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
2020-03-29 12:54:13 +00:00
|
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
|
|
|
});
|
2020-05-05 15:16:35 +00:00
|
|
|
|
2020-03-29 12:54:13 +00:00
|
|
|
it('should add 30.5 days for each extraMonth', () => {
|
|
|
|
|
plan.extraMonths = 4;
|
|
|
|
|
const expectedTerminationDate = moment()
|
|
|
|
|
.add(30.5 * 4, 'days');
|
|
|
|
|
|
2020-05-05 15:16:35 +00:00
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
2020-03-29 12:54:13 +00:00
|
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
|
|
|
});
|
2020-05-05 15:16:35 +00:00
|
|
|
|
2020-03-29 12:54:13 +00:00
|
|
|
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');
|
|
|
|
|
|
2020-05-05 15:16:35 +00:00
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
2020-03-29 12:54:13 +00:00
|
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
|
|
|
});
|
2020-05-05 15:16:35 +00:00
|
|
|
|
2020-03-29 12:54:13 +00:00
|
|
|
it('behaves like extraMonths is 0 if it\'s set to a negative number', () => {
|
|
|
|
|
plan.extraMonths = -5;
|
|
|
|
|
const expectedTerminationDate = moment();
|
2020-05-05 15:16:35 +00:00
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
2020-03-29 12:54:13 +00:00
|
|
|
expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0);
|
|
|
|
|
});
|
2020-05-05 15:16:35 +00:00
|
|
|
|
|
|
|
|
it('returns current terminated date if it exists and is later than newly calculated date', () => {
|
|
|
|
|
const expectedTerminationDate = moment().add({ months: 5 }).toDate();
|
2020-05-14 10:56:12 +00:00
|
|
|
plan.dateTerminated = expectedTerminationDate;
|
2020-05-05 15:16:35 +00:00
|
|
|
|
|
|
|
|
const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId);
|
|
|
|
|
|
|
|
|
|
expect(terminationDate).to.equal(expectedTerminationDate);
|
|
|
|
|
});
|
2020-05-14 10:56:12 +00:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
2020-03-29 12:54:13 +00:00
|
|
|
});
|