mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 05:07:22 +01:00
Fix double subscriptions, second attempt (#14345)
* fix(subscriptions): reject subs that come in too fast * fix(lint): remove unused import * fix(groups): individual subs may come rapidly * fix(subscriptions): bad paren, handle rapid testing * fix(test): reset dateUpdated between subs * fix(test): one more block for dateUpdated Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
@@ -350,6 +350,10 @@ describe('payments/index', () => {
|
||||
});
|
||||
|
||||
context('Purchasing a subscription for self', () => {
|
||||
beforeEach(() => {
|
||||
data.user.purchased.plan.dateUpdated = moment().subtract(1, 'hours').toDate();
|
||||
});
|
||||
|
||||
it('creates a subscription', async () => {
|
||||
expect(user.purchased.plan.planId).to.not.exist;
|
||||
|
||||
@@ -376,6 +380,7 @@ describe('payments/index', () => {
|
||||
user.purchased.plan = plan;
|
||||
user.purchased.plan.dateTerminated = moment(new Date()).add(2, 'months');
|
||||
expect(user.purchased.plan.extraMonths).to.eql(0);
|
||||
data.user.purchased.plan.dateUpdated = moment().subtract(1, 'hours').toDate();
|
||||
|
||||
await api.createSubscription(data);
|
||||
|
||||
@@ -386,6 +391,7 @@ describe('payments/index', () => {
|
||||
user.purchased.plan = plan;
|
||||
user.purchased.plan.dateTerminated = moment(new Date()).subtract(2, 'months');
|
||||
expect(user.purchased.plan.extraMonths).to.eql(0);
|
||||
data.user.purchased.plan.dateUpdated = moment().subtract(1, 'hours').toDate();
|
||||
|
||||
await api.createSubscription(data);
|
||||
|
||||
@@ -395,6 +401,7 @@ describe('payments/index', () => {
|
||||
it('does not reset Gold-to-Gems cap on additional subscription', async () => {
|
||||
user.purchased.plan = plan;
|
||||
user.purchased.plan.gemsBought = 10;
|
||||
data.user.purchased.plan.dateUpdated = moment().subtract(1, 'hours').toDate();
|
||||
|
||||
await api.createSubscription(data);
|
||||
|
||||
@@ -448,6 +455,10 @@ describe('payments/index', () => {
|
||||
});
|
||||
|
||||
context('Block subscription perks', () => {
|
||||
beforeEach(() => {
|
||||
data.user.purchased.plan.dateUpdated = moment().subtract(1, 'hours').toDate();
|
||||
});
|
||||
|
||||
it('adds block months to plan.consecutive.offset', async () => {
|
||||
await api.createSubscription(data);
|
||||
|
||||
@@ -486,6 +497,7 @@ describe('payments/index', () => {
|
||||
data.sub.key = 'basic_12mo';
|
||||
|
||||
await api.createSubscription(data);
|
||||
data.user.purchased.plan.dateUpdated = moment().subtract(1, 'hours').toDate();
|
||||
await api.createSubscription(data);
|
||||
|
||||
expect(user.purchased.plan.consecutive.gemCapExtra).to.eql(25);
|
||||
@@ -524,6 +536,7 @@ describe('payments/index', () => {
|
||||
now: mayMysteryItemTimeframe,
|
||||
toFake: ['Date'],
|
||||
});
|
||||
data.user.purchased.plan.dateUpdated = moment().subtract(1, 'hours').toDate();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user