subscription test improvements

This commit is contained in:
Phillip Thelen
2024-08-13 13:11:22 +02:00
committed by Kalista Payne
parent ca78e74330
commit eea36e3ed5
2 changed files with 17 additions and 16 deletions
+12 -3
View File
@@ -65,7 +65,6 @@ describe('payments/index', () => {
mysteryItems: [],
consecutive: {
trinkets: 0,
offset: 0,
gemCapExtra: 0,
},
};
@@ -179,13 +178,13 @@ describe('payments/index', () => {
expect(recipient.purchased.plan.consecutive.gemCapExtra).to.eql(10);
});
it('sets gemCapExtra to max if they receive a 3 month sub', async () => {
it('sets gemCapExtra to 0 if they receive a 3 month sub', async () => {
data.gift.subscription.key = 'basic_3mo';
data.gift.subscription.months = 3;
await api.createSubscription(data);
expect(recipient.purchased.plan.gemCapExtra).to.eql(0);
expect(recipient.purchased.plan.consecutive.gemCapExtra).to.eql(0);
});
it('sets gemCapExtra to max if they receive a 12 month sub', async () => {
@@ -1183,6 +1182,16 @@ describe('payments/index', () => {
expect(user.purchased.plan.consecutive.gemCapExtra).to.eql(12);
});
it('initializes gemCapExtra', async () => {
await api.cancelSubscription(data);
expect(user.purchased.plan.consecutive.gemCapExtra).to.eql(0);
});
it('initializes hourglasses', async () => {
await api.cancelSubscription(data);
expect(user.purchased.plan.consecutive.trinkets).to.eql(0);
});
it('does not reset owned hourglasses', async () => {
user.purchased.plan.consecutive.trinkets = 12;
+5 -13
View File
@@ -200,18 +200,11 @@ async function prepareSubscriptionValues (data) {
owner: data.user._id,
});
// allow non-override if a plan was previously used
if (!plan.gemsBought) {
plan.gemsBought = 0;
}
if (!plan.dateCreated) {
plan.dateCreated = today;
}
if (!plan.mysteryItems) {
plan.mysteryItems = [];
}
_.defaults(plan, {
gemsBought: 0,
dateCreated: today,
mysteryItems: [],
});
if (data.subscriptionId) {
plan.subscriptionId = data.subscriptionId;
@@ -261,7 +254,6 @@ async function createSubscription (data) {
if (months > 0) {
if (block.months === 12) {
recipient.purchased.plan.consecutive.gemCapExtra = 26;
recipient.markModified('purchased.plan.consecutive');
}
if (block.months === 12 && autoRenews && !recipient.purchased.plan.hourglassPromoReceived) {