mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Keep existing Mystery Items and Hourglasses when adding to group - fixes 8643 (#8745)
* Modified addSubToGroupUser to save existing mysteryItems and trinkets from an expired subscription Added unit test * fix eslint error
This commit is contained in:
@@ -653,5 +653,32 @@ describe('payments/index', () => {
|
||||
|
||||
expect(updatedUser.items.pets['Jackalope-RoyalPurple']).to.eql(5);
|
||||
});
|
||||
|
||||
it('saves previously unused Mystery Items and Hourglasses for an expired subscription', async () => {
|
||||
let planExpirationDate = new Date();
|
||||
planExpirationDate.setDate(planExpirationDate.getDate() - 2);
|
||||
let mysteryItem = 'item';
|
||||
let mysteryItems = [mysteryItem];
|
||||
let consecutive = {
|
||||
trinkets: 3,
|
||||
};
|
||||
|
||||
// set expired plan with unused items
|
||||
plan.mysteryItems = mysteryItems;
|
||||
plan.consecutive = consecutive;
|
||||
plan.dateCreated = planExpirationDate;
|
||||
plan.dateTerminated = planExpirationDate;
|
||||
plan.customerId = null;
|
||||
|
||||
user.purchased.plan = plan;
|
||||
|
||||
await user.save();
|
||||
await api.addSubToGroupUser(user, group);
|
||||
|
||||
let updatedUser = await User.findById(user._id).exec();
|
||||
|
||||
expect(updatedUser.purchased.plan.mysteryItems[0]).to.eql(mysteryItem);
|
||||
expect(updatedUser.purchased.plan.consecutive.trinkets).to.equal(consecutive.trinkets);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -112,8 +112,8 @@ api.addSubToGroupUser = async function addSubToGroupUser (member, group) {
|
||||
},
|
||||
};
|
||||
|
||||
if (member.isSubscribed()) {
|
||||
let memberPlan = member.purchased.plan;
|
||||
if (member.isSubscribed()) {
|
||||
let customerHasCancelledGroupPlan = memberPlan.customerId === this.constants.GROUP_PLAN_CUSTOMER_ID && !member.hasNotCancelled();
|
||||
let ignorePaymentPlan = paymentMethodsToIgnore.indexOf(memberPlan.paymentMethod) !== -1;
|
||||
let ignoreCustomerId = customerIdsToIgnore.indexOf(memberPlan.customerId) !== -1;
|
||||
@@ -154,6 +154,10 @@ api.addSubToGroupUser = async function addSubToGroupUser (member, group) {
|
||||
}).value();
|
||||
}
|
||||
|
||||
// save unused hourglass and mystery items
|
||||
plan.consecutive.trinkets = memberPlan.consecutive.trinkets;
|
||||
plan.mysteryItems = memberPlan.mysteryItems;
|
||||
|
||||
member.purchased.plan = plan;
|
||||
member.items.mounts['Jackalope-RoyalPurple'] = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user