mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
fix(tests): subscriptions, group updates
This commit is contained in:
@@ -23,10 +23,11 @@ describe('PUT /group', () => {
|
|||||||
groupDetails: {
|
groupDetails: {
|
||||||
name: groupName,
|
name: groupName,
|
||||||
type: groupType,
|
type: groupType,
|
||||||
privacy: 'public',
|
privacy: 'private',
|
||||||
categories: groupCategories,
|
categories: groupCategories,
|
||||||
},
|
},
|
||||||
members: 1,
|
members: 1,
|
||||||
|
upgradeToGroupPlan: true,
|
||||||
});
|
});
|
||||||
adminUser = await generateUser({ 'permissions.moderator': true });
|
adminUser = await generateUser({ 'permissions.moderator': true });
|
||||||
groupToUpdate = group;
|
groupToUpdate = group;
|
||||||
@@ -106,14 +107,29 @@ describe('PUT /group', () => {
|
|||||||
expect(updatedGroup.name).to.equal(groupUpdatedName);
|
expect(updatedGroup.name).to.equal(groupUpdatedName);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows a leader to change leaders', async () => {
|
it('does not allow a leader to change leader of active group plan', async () => {
|
||||||
const updatedGroup = await leader.put(`/groups/${groupToUpdate._id}`, {
|
await expect(leader.put(`/groups/${groupToUpdate._id}`, {
|
||||||
name: groupUpdatedName,
|
name: groupUpdatedName,
|
||||||
leader: nonLeader._id,
|
leader: nonLeader._id,
|
||||||
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
error: 'NotAuthorized',
|
||||||
|
message: t('cannotChangeLeaderWithActiveGroupPlan'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows a leader of a party to change leaders', async () => {
|
||||||
|
let party; let partyLeader; let members;
|
||||||
|
({ group: party, groupLeader: partyLeader, members } = await createAndPopulateGroup({
|
||||||
|
members: 1,
|
||||||
|
}));
|
||||||
|
const updatedGroup = await partyLeader.put(`/groups/${party._id}`, {
|
||||||
|
name: groupUpdatedName,
|
||||||
|
leader: members[0]._id,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(updatedGroup.leader._id).to.eql(nonLeader._id);
|
expect(updatedGroup.leader._id).to.eql(members[0]._id);
|
||||||
expect(updatedGroup.leader.profile.name).to.eql(nonLeader.profile.name);
|
expect(updatedGroup.leader.profile.name).to.eql(members[0].profile.name);
|
||||||
expect(updatedGroup.name).to.equal(groupUpdatedName);
|
expect(updatedGroup.name).to.equal(groupUpdatedName);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,15 +138,16 @@ describe('PUT /group', () => {
|
|||||||
groupDetails: {
|
groupDetails: {
|
||||||
name: 'public guild',
|
name: 'public guild',
|
||||||
type: 'guild',
|
type: 'guild',
|
||||||
privacy: 'public',
|
privacy: 'private',
|
||||||
},
|
},
|
||||||
|
upgradeToGroupPlan: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateGroupDetails = {
|
const updateGroupDetails = {
|
||||||
id: group._id,
|
id: group._id,
|
||||||
name: 'public guild',
|
name: 'public guild',
|
||||||
type: 'guild',
|
type: 'guild',
|
||||||
privacy: 'public',
|
privacy: 'private',
|
||||||
bannedWordsAllowed: true,
|
bannedWordsAllowed: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -150,9 +167,11 @@ describe('PUT /group', () => {
|
|||||||
groupDetails: {
|
groupDetails: {
|
||||||
name: 'public guild',
|
name: 'public guild',
|
||||||
type: 'guild',
|
type: 'guild',
|
||||||
privacy: 'public',
|
privacy: 'private',
|
||||||
},
|
},
|
||||||
|
upgradeToGroupPlan: true,
|
||||||
});
|
});
|
||||||
|
await groupLeader.update({ permissions: {} } );
|
||||||
|
|
||||||
const updateGroupDetails = {
|
const updateGroupDetails = {
|
||||||
id: group._id,
|
id: group._id,
|
||||||
|
|||||||
@@ -50,22 +50,21 @@ describe('payments : amazon #subscribeCancel', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('cancels a group subscription', async () => {
|
it('cancels a group subscription', async () => {
|
||||||
user = await generateUser({
|
({ group, groupLeader: user } = await createAndPopulateGroup({
|
||||||
'profile.name': 'sender',
|
groupDetails: {
|
||||||
'purchased.plan.customerId': 'customer-id',
|
name: 'test group',
|
||||||
'purchased.plan.planId': 'basic_3mo',
|
type: 'guild',
|
||||||
'purchased.plan.lastBillingDate': new Date(),
|
privacy: 'private',
|
||||||
balance: 2,
|
},
|
||||||
});
|
leaderDetails: {
|
||||||
|
'profile.name': 'sender',
|
||||||
group = await generateGroup(user, {
|
'purchased.plan.customerId': 'customer-id',
|
||||||
name: 'test group',
|
'purchased.plan.planId': 'basic_3mo',
|
||||||
type: 'guild',
|
'purchased.plan.lastBillingDate': new Date(),
|
||||||
privacy: 'public',
|
balance: 2,
|
||||||
'purchased.plan.customerId': 'customer-id',
|
},
|
||||||
'purchased.plan.planId': 'basic_3mo',
|
upgradeToGroupPlan: true,
|
||||||
'purchased.plan.lastBillingDate': new Date(),
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
await user.get(`${endpoint}&groupId=${group._id}`);
|
await user.get(`${endpoint}&groupId=${group._id}`);
|
||||||
|
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ describe('payments - amazon - #subscribe', () => {
|
|||||||
|
|
||||||
group = await generateGroup(user, {
|
group = await generateGroup(user, {
|
||||||
name: 'test group',
|
name: 'test group',
|
||||||
type: 'guild',
|
type: 'party',
|
||||||
privacy: 'public',
|
privacy: 'private',
|
||||||
'purchased.plan.customerId': 'customer-id',
|
'purchased.plan.customerId': 'customer-id',
|
||||||
'purchased.plan.planId': 'basic_3mo',
|
'purchased.plan.planId': 'basic_3mo',
|
||||||
'purchased.plan.lastBillingDate': new Date(),
|
'purchased.plan.lastBillingDate': new Date(),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
generateGroup,
|
|
||||||
translate as t,
|
translate as t,
|
||||||
|
createAndPopulateGroup,
|
||||||
} from '../../../../../helpers/api-integration/v3';
|
} from '../../../../../helpers/api-integration/v3';
|
||||||
import stripePayments from '../../../../../../website/server/libs/payments/stripe';
|
import stripePayments from '../../../../../../website/server/libs/payments/stripe';
|
||||||
|
|
||||||
@@ -48,22 +48,21 @@ describe('payments - stripe - #subscribeCancel', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('cancels a group subscription', async () => {
|
it('cancels a group subscription', async () => {
|
||||||
user = await generateUser({
|
({ group, groupLeader: user } = await createAndPopulateGroup({
|
||||||
'profile.name': 'sender',
|
groupDetails: {
|
||||||
'purchased.plan.customerId': 'customer-id',
|
name: 'test group',
|
||||||
'purchased.plan.planId': 'basic_3mo',
|
type: 'guild',
|
||||||
'purchased.plan.lastBillingDate': new Date(),
|
privacy: 'private',
|
||||||
balance: 2,
|
},
|
||||||
});
|
leaderDetails: {
|
||||||
|
'profile.name': 'sender',
|
||||||
group = await generateGroup(user, {
|
'purchased.plan.customerId': 'customer-id',
|
||||||
name: 'test group',
|
'purchased.plan.planId': 'basic_3mo',
|
||||||
type: 'guild',
|
'purchased.plan.lastBillingDate': new Date(),
|
||||||
privacy: 'public',
|
balance: 2,
|
||||||
'purchased.plan.customerId': 'customer-id',
|
},
|
||||||
'purchased.plan.planId': 'basic_3mo',
|
upgradeToGroupPlan: true,
|
||||||
'purchased.plan.lastBillingDate': new Date(),
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
await user.get(`${endpoint}&groupId=${group._id}`);
|
await user.get(`${endpoint}&groupId=${group._id}`);
|
||||||
|
|
||||||
|
|||||||
@@ -199,6 +199,7 @@
|
|||||||
"claim": "Claim Task",
|
"claim": "Claim Task",
|
||||||
"removeClaim": "Remove Claim",
|
"removeClaim": "Remove Claim",
|
||||||
"onlyGroupLeaderCanManageSubscription": "Only the group leader can manage the group's subscription",
|
"onlyGroupLeaderCanManageSubscription": "Only the group leader can manage the group's subscription",
|
||||||
|
"onlyPrivateGuildsCanUpgrade": "Only private guilds can be upgraded to a group plan.",
|
||||||
"youHaveBeenAssignedTask": "<%- managerName %> has assigned you the task <span class=\"notification-bold\"><%- taskText %></span>.",
|
"youHaveBeenAssignedTask": "<%- managerName %> has assigned you the task <span class=\"notification-bold\"><%- taskText %></span>.",
|
||||||
"yourTaskHasBeenApproved": "Your task <span class=\"notification-green notification-bold\"><%- taskText %></span> has been approved.",
|
"yourTaskHasBeenApproved": "Your task <span class=\"notification-green notification-bold\"><%- taskText %></span> has been approved.",
|
||||||
"thisTaskApproved": "This task was approved",
|
"thisTaskApproved": "This task was approved",
|
||||||
|
|||||||
@@ -487,7 +487,9 @@ api.updateGroup = {
|
|||||||
if (group.leader !== user._id && group.type === 'party') throw new NotAuthorized(res.t('messageGroupOnlyLeaderCanUpdate'));
|
if (group.leader !== user._id && group.type === 'party') throw new NotAuthorized(res.t('messageGroupOnlyLeaderCanUpdate'));
|
||||||
else if (group.leader !== user._id && !user.hasPermission('moderator')) throw new NotAuthorized(res.t('messageGroupOnlyLeaderCanUpdate'));
|
else if (group.leader !== user._id && !user.hasPermission('moderator')) throw new NotAuthorized(res.t('messageGroupOnlyLeaderCanUpdate'));
|
||||||
|
|
||||||
if (req.body.leader !== user._id && group.hasNotCancelled()) throw new NotAuthorized(res.t('cannotChangeLeaderWithActiveGroupPlan'));
|
if (req.body.leader && req.body.leader !== user._id && group.hasNotCancelled()) {
|
||||||
|
throw new NotAuthorized(res.t('cannotChangeLeaderWithActiveGroupPlan'));
|
||||||
|
}
|
||||||
|
|
||||||
const handleArrays = (currentValue, updatedValue) => {
|
const handleArrays = (currentValue, updatedValue) => {
|
||||||
if (!_.isArray(currentValue)) {
|
if (!_.isArray(currentValue)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user