Allow group plans for private guilds only (#12479)

* hide upgrade button for public guilds

* prevent group plans for public guilds

* fix unit tests

* fix integration and unit tests that assumed group plans could be public guilds

* more unit tests fixes

* more resilient unit test

* more resilient unit test
This commit is contained in:
Matteo Pagliazzi
2020-08-21 11:46:09 +02:00
committed by GitHub
parent 633f3df372
commit 46b5efcaf6
9 changed files with 145 additions and 85 deletions

View File

@@ -31,11 +31,14 @@ describe('#upgradeGroupPlan', () => {
group = generateGroup({ group = generateGroup({
name: 'test group', name: 'test group',
type: 'guild', type: 'guild',
privacy: 'public', privacy: 'private',
leader: user._id, leader: user._id,
}); });
await group.save(); await group.save();
user.guilds.push(group._id);
await user.save();
spy = sinon.stub(amzLib, 'authorizeOnBillingAgreement'); spy = sinon.stub(amzLib, 'authorizeOnBillingAgreement');
spy.resolves([]); spy.resolves([]);

View File

@@ -21,11 +21,14 @@ describe('Canceling a subscription for group', () => {
group = generateGroup({ group = generateGroup({
name: 'test group', name: 'test group',
type: 'guild', type: 'guild',
privacy: 'public', privacy: 'private',
leader: user._id, leader: user._id,
}); });
await group.save(); await group.save();
user.guilds.push(group._id);
await user.save();
data = { data = {
user, user,
sub: { sub: {
@@ -141,6 +144,8 @@ describe('Canceling a subscription for group', () => {
it('prevents non group leader from managing subscription', async () => { it('prevents non group leader from managing subscription', async () => {
const groupMember = new User(); const groupMember = new User();
groupMember.guilds.push(group._id);
await groupMember.save();
data.user = groupMember; data.user = groupMember;
data.groupId = group._id; data.groupId = group._id;
@@ -162,7 +167,9 @@ describe('Canceling a subscription for group', () => {
let updatedGroup = await Group.findById(group._id).exec(); let updatedGroup = await Group.findById(group._id).exec();
const newLeader = new User(); const newLeader = new User();
newLeader.profile.name = 'newLeader';
updatedGroup.leader = newLeader._id; updatedGroup.leader = newLeader._id;
await newLeader.save();
await updatedGroup.save(); await updatedGroup.save();
await api.cancelSubscription(data); await api.cancelSubscription(data);
@@ -185,8 +192,6 @@ describe('Canceling a subscription for group', () => {
'user-agent': '', 'user-agent': '',
}, },
}; };
user.guilds.push(group._id);
await user.save();
expect(group.purchased.plan.planId).to.not.exist; expect(group.purchased.plan.planId).to.not.exist;
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -211,10 +216,15 @@ describe('Canceling a subscription for group', () => {
await api.createSubscription(data); await api.createSubscription(data);
await api.cancelSubscription(data); await api.cancelSubscription(data);
expect(sender.sendTxn).to.be.have.callCount(4); expect(sender.sendTxn).to.be.have.callCount(6);
expect(sender.sendTxn.thirdCall.args[0]._id).to.equal(recipient._id); const recipientCall = sender.sendTxn.getCalls().find(call => {
expect(sender.sendTxn.thirdCall.args[1]).to.equal('group-member-cancel'); const isRecipient = call.args[0]._id === recipient._id;
expect(sender.sendTxn.thirdCall.args[2]).to.eql([ const isGroupMemberCancel = call.args[1] === 'group-member-cancel';
return isRecipient && isGroupMemberCancel;
});
expect(recipientCall.args[0]._id).to.equal(recipient._id);
expect(recipientCall.args[1]).to.equal('group-member-cancel');
expect(recipientCall.args[2]).to.eql([
{ name: 'LEADER', content: user.profile.name }, { name: 'LEADER', content: user.profile.name },
{ name: 'GROUP_NAME', content: group.name }, { name: 'GROUP_NAME', content: group.name },
]); ]);
@@ -246,8 +256,6 @@ describe('Canceling a subscription for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -259,11 +267,13 @@ describe('Canceling a subscription for group', () => {
const group2 = generateGroup({ const group2 = generateGroup({
name: 'test group2', name: 'test group2',
type: 'guild', type: 'guild',
privacy: 'public', privacy: 'private',
leader: user._id, leader: user._id,
}); });
data.groupId = group2._id; data.groupId = group2._id;
await group2.save(); await group2.save();
user.guilds.push(group2._id);
await user.save();
recipient.guilds.push(group2._id); recipient.guilds.push(group2._id);
await recipient.save(); await recipient.save();
@@ -285,8 +295,6 @@ describe('Canceling a subscription for group', () => {
}); });
it('does cancel a leader subscription with two cancelled group plans', async () => { it('does cancel a leader subscription with two cancelled group plans', async () => {
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -298,7 +306,7 @@ describe('Canceling a subscription for group', () => {
const group2 = generateGroup({ const group2 = generateGroup({
name: 'test group2', name: 'test group2',
type: 'guild', type: 'guild',
privacy: 'public', privacy: 'private',
leader: user._id, leader: user._id,
}); });
user.guilds.push(group2._id); user.guilds.push(group2._id);

View File

@@ -12,6 +12,7 @@ import { model as Group } from '../../../../../../website/server/models/group';
import { import {
generateGroup, generateGroup,
} from '../../../../../helpers/api-unit.helper'; } from '../../../../../helpers/api-unit.helper';
import i18n from '../../../../../../website/common/script/i18n';
describe('Purchasing a group plan for group', () => { describe('Purchasing a group plan for group', () => {
const EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_GOOGLE = 'Google_subscription'; const EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_GOOGLE = 'Google_subscription';
@@ -33,11 +34,14 @@ describe('Purchasing a group plan for group', () => {
group = generateGroup({ group = generateGroup({
name: groupName, name: groupName,
type: 'guild', type: 'guild',
privacy: 'public', privacy: 'private',
leader: user._id, leader: user._id,
}); });
await group.save(); await group.save();
user.guilds.push(group._id);
await user.save();
data = { data = {
user, user,
sub: { sub: {
@@ -112,6 +116,30 @@ describe('Purchasing a group plan for group', () => {
expect(updatedGroup.purchased.plan.dateCreated).to.exist; expect(updatedGroup.purchased.plan.dateCreated).to.exist;
}); });
it('does not create a group plan for a public guild', async () => {
const publicGroup = generateGroup({
name: groupName,
type: 'guild',
privacy: 'public',
leader: user._id,
});
await publicGroup.save();
expect(publicGroup.purchased.plan.planId).to.not.exist;
data.groupId = publicGroup._id;
await expect(api.createSubscription(data))
.to.eventually.be.rejected.and.to.eql({
httpCode: 401,
name: 'NotAuthorized',
message: i18n.t('onlyPrivateGuildsCanUpgrade'),
});
const updatedGroup = await Group.findById(publicGroup._id).exec();
expect(updatedGroup.purchased.plan.planId).to.not.exist;
});
it('sends an email', async () => { it('sends an email', async () => {
expect(group.purchased.plan.planId).to.not.exist; expect(group.purchased.plan.planId).to.not.exist;
data.groupId = group._id; data.groupId = group._id;
@@ -148,8 +176,6 @@ describe('Purchasing a group plan for group', () => {
}); });
it('grants all members of a group a subscription', async () => { it('grants all members of a group a subscription', async () => {
user.guilds.push(group._id);
await user.save();
expect(group.purchased.plan.planId).to.not.exist; expect(group.purchased.plan.planId).to.not.exist;
data.groupId = group._id; data.groupId = group._id;
@@ -179,17 +205,28 @@ describe('Purchasing a group plan for group', () => {
await api.createSubscription(data); await api.createSubscription(data);
expect(sender.sendTxn).to.be.calledTwice; expect(sender.sendTxn).to.be.calledThrice;
expect(sender.sendTxn.firstCall.args[0]._id).to.equal(recipient._id); const recipientCall = sender.sendTxn.getCalls().find(call => {
expect(sender.sendTxn.firstCall.args[1]).to.equal('group-member-join'); const isRecipient = call.args[0]._id === recipient._id;
expect(sender.sendTxn.firstCall.args[2]).to.eql([ const isJoin = call.args[1] === 'group-member-join';
return isRecipient && isJoin;
});
expect(recipientCall.args[0]._id).to.equal(recipient._id);
expect(recipientCall.args[1]).to.equal('group-member-join');
expect(recipientCall.args[2]).to.eql([
{ name: 'LEADER', content: user.profile.name }, { name: 'LEADER', content: user.profile.name },
{ name: 'GROUP_NAME', content: group.name }, { name: 'GROUP_NAME', content: group.name },
{ name: 'PREVIOUS_SUBSCRIPTION_TYPE', content: EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_NONE }, { name: 'PREVIOUS_SUBSCRIPTION_TYPE', content: EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_NONE },
]); ]);
// confirm that the other email sent is appropriate: // confirm that the other email sent is appropriate:
expect(sender.sendTxn.secondCall.args[0]._id).to.equal(group.leader); const leaderCall = sender.sendTxn.getCalls().find(call => {
expect(sender.sendTxn.secondCall.args[1]).to.equal('group-subscription-begins'); const isLeader = call.args[0]._id === group.leader;
const isSubscriptionBegin = call.args[1] === 'group-subscription-begins';
return isLeader && isSubscriptionBegin;
});
expect(leaderCall.args[0]._id).to.equal(group.leader);
expect(leaderCall.args[1]).to.equal('group-subscription-begins');
}); });
it('sends one email to subscribed member of group, stating subscription is cancelled (Stripe)', async () => { it('sends one email to subscribed member of group, stating subscription is cancelled (Stripe)', async () => {
@@ -205,17 +242,28 @@ describe('Purchasing a group plan for group', () => {
await api.createSubscription(data); await api.createSubscription(data);
expect(sender.sendTxn).to.be.calledTwice; expect(sender.sendTxn).to.be.calledThrice;
expect(sender.sendTxn.firstCall.args[0]._id).to.equal(recipient._id); const recipientCall = sender.sendTxn.getCalls().find(call => {
expect(sender.sendTxn.firstCall.args[1]).to.equal('group-member-join'); const isRecipient = call.args[0]._id === recipient._id;
expect(sender.sendTxn.firstCall.args[2]).to.eql([ const isJoin = call.args[1] === 'group-member-join';
return isRecipient && isJoin;
});
expect(recipientCall.args[0]._id).to.equal(recipient._id);
expect(recipientCall.args[1]).to.equal('group-member-join');
expect(recipientCall.args[2]).to.eql([
{ name: 'LEADER', content: user.profile.name }, { name: 'LEADER', content: user.profile.name },
{ name: 'GROUP_NAME', content: group.name }, { name: 'GROUP_NAME', content: group.name },
{ name: 'PREVIOUS_SUBSCRIPTION_TYPE', content: EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_NORMAL }, { name: 'PREVIOUS_SUBSCRIPTION_TYPE', content: EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_NORMAL },
]); ]);
// confirm that the other email sent is not a cancel-subscription email: // confirm that the other email sent is not a cancel-subscription email:
expect(sender.sendTxn.secondCall.args[0]._id).to.equal(group.leader); const leaderCall = sender.sendTxn.getCalls().find(call => {
expect(sender.sendTxn.secondCall.args[1]).to.equal('group-subscription-begins'); const isLeader = call.args[0]._id === group.leader;
const isSubscriptionBegin = call.args[1] === 'group-subscription-begins';
return isLeader && isSubscriptionBegin;
});
expect(leaderCall.args[0]._id).to.equal(group.leader);
expect(leaderCall.args[1]).to.equal('group-subscription-begins');
}); });
it('sends one email to subscribed member of group, stating subscription is cancelled (Amazon)', async () => { it('sends one email to subscribed member of group, stating subscription is cancelled (Amazon)', async () => {
@@ -238,17 +286,28 @@ describe('Purchasing a group plan for group', () => {
await api.createSubscription(data); await api.createSubscription(data);
expect(sender.sendTxn).to.be.calledTwice; expect(sender.sendTxn).to.be.calledThrice;
expect(sender.sendTxn.firstCall.args[0]._id).to.equal(recipient._id); const recipientCall = sender.sendTxn.getCalls().find(call => {
expect(sender.sendTxn.firstCall.args[1]).to.equal('group-member-join'); const isRecipient = call.args[0]._id === recipient._id;
expect(sender.sendTxn.firstCall.args[2]).to.eql([ const isJoin = call.args[1] === 'group-member-join';
return isRecipient && isJoin;
});
expect(recipientCall.args[0]._id).to.equal(recipient._id);
expect(recipientCall.args[1]).to.equal('group-member-join');
expect(recipientCall.args[2]).to.eql([
{ name: 'LEADER', content: user.profile.name }, { name: 'LEADER', content: user.profile.name },
{ name: 'GROUP_NAME', content: group.name }, { name: 'GROUP_NAME', content: group.name },
{ name: 'PREVIOUS_SUBSCRIPTION_TYPE', content: EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_NORMAL }, { name: 'PREVIOUS_SUBSCRIPTION_TYPE', content: EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_NORMAL },
]); ]);
// confirm that the other email sent is not a cancel-subscription email: // confirm that the other email sent is not a cancel-subscription email:
expect(sender.sendTxn.secondCall.args[0]._id).to.equal(group.leader); const leaderCall = sender.sendTxn.getCalls().find(call => {
expect(sender.sendTxn.secondCall.args[1]).to.equal('group-subscription-begins'); const isLeader = call.args[0]._id === group.leader;
const isSubscriptionBegin = call.args[1] === 'group-subscription-begins';
return isLeader && isSubscriptionBegin;
});
expect(leaderCall.args[0]._id).to.equal(group.leader);
expect(leaderCall.args[1]).to.equal('group-subscription-begins');
amzLib.getBillingAgreementDetails.restore(); amzLib.getBillingAgreementDetails.restore();
}); });
@@ -275,17 +334,28 @@ describe('Purchasing a group plan for group', () => {
await api.createSubscription(data); await api.createSubscription(data);
expect(sender.sendTxn).to.be.calledTwice; expect(sender.sendTxn).to.be.calledThrice;
expect(sender.sendTxn.firstCall.args[0]._id).to.equal(recipient._id); const recipientCall = sender.sendTxn.getCalls().find(call => {
expect(sender.sendTxn.firstCall.args[1]).to.equal('group-member-join'); const isRecipient = call.args[0]._id === recipient._id;
expect(sender.sendTxn.firstCall.args[2]).to.eql([ const isJoin = call.args[1] === 'group-member-join';
return isRecipient && isJoin;
});
expect(recipientCall.args[0]._id).to.equal(recipient._id);
expect(recipientCall.args[1]).to.equal('group-member-join');
expect(recipientCall.args[2]).to.eql([
{ name: 'LEADER', content: user.profile.name }, { name: 'LEADER', content: user.profile.name },
{ name: 'GROUP_NAME', content: group.name }, { name: 'GROUP_NAME', content: group.name },
{ name: 'PREVIOUS_SUBSCRIPTION_TYPE', content: EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_NORMAL }, { name: 'PREVIOUS_SUBSCRIPTION_TYPE', content: EMAIL_TEMPLATE_SUBSCRIPTION_TYPE_NORMAL },
]); ]);
// confirm that the other email sent is not a cancel-subscription email: // confirm that the other email sent is not a cancel-subscription email:
expect(sender.sendTxn.secondCall.args[0]._id).to.equal(group.leader); const leaderCall = sender.sendTxn.getCalls().find(call => {
expect(sender.sendTxn.secondCall.args[1]).to.equal('group-subscription-begins'); const isLeader = call.args[0]._id === group.leader;
const isSubscriptionBegin = call.args[1] === 'group-subscription-begins';
return isLeader && isSubscriptionBegin;
});
expect(leaderCall.args[0]._id).to.equal(group.leader);
expect(leaderCall.args[1]).to.equal('group-subscription-begins');
paypalPayments.paypalBillingAgreementGet.restore(); paypalPayments.paypalBillingAgreementGet.restore();
paypalPayments.paypalBillingAgreementCancel.restore(); paypalPayments.paypalBillingAgreementCancel.restore();
@@ -302,8 +372,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -356,8 +424,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -419,8 +485,6 @@ describe('Purchasing a group plan for group', () => {
data.gift = undefined; data.gift = undefined;
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -455,8 +519,6 @@ describe('Purchasing a group plan for group', () => {
data.gift = undefined; data.gift = undefined;
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -483,8 +545,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -511,8 +571,6 @@ describe('Purchasing a group plan for group', () => {
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -541,8 +599,6 @@ describe('Purchasing a group plan for group', () => {
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -566,8 +622,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await recipient.cancelSubscription(); await recipient.cancelSubscription();
@@ -589,8 +643,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await recipient.cancelSubscription(); await recipient.cancelSubscription();
@@ -611,8 +663,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -632,8 +682,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -653,8 +701,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -688,8 +734,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -713,8 +757,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -726,13 +768,15 @@ describe('Purchasing a group plan for group', () => {
const group2 = generateGroup({ const group2 = generateGroup({
name: 'test group2', name: 'test group2',
type: 'guild', type: 'guild',
privacy: 'public', privacy: 'private',
leader: user._id, leader: user._id,
}); });
data.groupId = group2._id; data.groupId = group2._id;
await group2.save(); await group2.save();
recipient.guilds.push(group2._id); recipient.guilds.push(group2._id);
await recipient.save(); await recipient.save();
user.guilds.push(group2._id);
await user.save();
await api.createSubscription(data); await api.createSubscription(data);
@@ -757,8 +801,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -770,17 +812,22 @@ describe('Purchasing a group plan for group', () => {
const group2 = generateGroup({ const group2 = generateGroup({
name: 'test group2', name: 'test group2',
type: 'guild', type: 'guild',
privacy: 'public', privacy: 'private',
leader: user._id, leader: user._id,
}); });
data.groupId = group2._id; data.groupId = group2._id;
await group2.save(); await group2.save();
recipient.guilds.push(group2._id); recipient.guilds.push(group2._id);
await recipient.save(); await recipient.save();
user.guilds.push(group2._id);
await user.save();
await api.createSubscription(data); await api.createSubscription(data);
const updatedGroup = await Group.findById(group._id).exec(); const updatedGroup = await Group.findById(group._id).exec();
updatedGroup.memberCount = 2;
await updatedGroup.save();
await updatedGroup.leave(recipient); await updatedGroup.leave(recipient);
updatedUser = await User.findById(recipient._id).exec(); updatedUser = await User.findById(recipient._id).exec();
@@ -806,8 +853,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -835,8 +880,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -864,8 +907,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);
@@ -894,8 +935,6 @@ describe('Purchasing a group plan for group', () => {
recipient.guilds.push(group._id); recipient.guilds.push(group._id);
await recipient.save(); await recipient.save();
user.guilds.push(group._id);
await user.save();
data.groupId = group._id; data.groupId = group._id;
await api.createSubscription(data); await api.createSubscription(data);

View File

@@ -33,11 +33,14 @@ describe('Stripe - Upgrade Group Plan', () => {
group = generateGroup({ group = generateGroup({
name: 'test group', name: 'test group',
type: 'guild', type: 'guild',
privacy: 'public', privacy: 'private',
leader: user._id, leader: user._id,
}); });
await group.save(); await group.save();
user.guilds.push(group._id);
await user.save();
spy = sinon.stub(stripe.subscriptions, 'update'); spy = sinon.stub(stripe.subscriptions, 'update');
spy.resolves([]); spy.resolves([]);
data.groupId = group._id; data.groupId = group._id;

View File

@@ -274,6 +274,7 @@ describe('POST /groups/:groupId/leave', () => {
each(typesOfGroups, (groupDetails, groupType) => { each(typesOfGroups, (groupDetails, groupType) => {
context(`Leaving a group plan when the group is a ${groupType}`, () => { context(`Leaving a group plan when the group is a ${groupType}`, () => {
if (groupDetails.privacy === 'public') return; // public guilds cannot be group plans
let groupWithPlan; let groupWithPlan;
let leader; let leader;
let member; let member;
@@ -341,6 +342,7 @@ describe('POST /groups/:groupId/leave', () => {
each(typesOfGroups, (groupDetails, groupType) => { each(typesOfGroups, (groupDetails, groupType) => {
context(`Leaving a group with extraMonths left plan when the group is a ${groupType}`, () => { context(`Leaving a group with extraMonths left plan when the group is a ${groupType}`, () => {
if (groupDetails.privacy === 'public') return; // public guilds cannot be group plans
const extraMonths = 12; const extraMonths = 12;
let groupWithPlan; let groupWithPlan;
let member; let member;

View File

@@ -32,7 +32,7 @@ describe('payments - stripe - #checkout', () => {
stripePayments.checkout.restore(); stripePayments.checkout.restore();
}); });
it('cancels a user subscription', async () => { it('creates a user subscription', async () => {
user = await generateUser({ user = await generateUser({
'profile.name': 'sender', 'profile.name': 'sender',
'purchased.plan.customerId': 'customer-id', 'purchased.plan.customerId': 'customer-id',
@@ -48,7 +48,7 @@ describe('payments - stripe - #checkout', () => {
expect(stripeCheckoutSubscriptionStub.args[0][0].groupId).to.eql(undefined); expect(stripeCheckoutSubscriptionStub.args[0][0].groupId).to.eql(undefined);
}); });
it('cancels a group subscription', async () => { it('creates a group subscription', async () => {
user = await generateUser({ user = await generateUser({
'profile.name': 'sender', 'profile.name': 'sender',
'purchased.plan.customerId': 'customer-id', 'purchased.plan.customerId': 'customer-id',

View File

@@ -106,7 +106,7 @@
<div class="col-12 buttons-wrapper"> <div class="col-12 buttons-wrapper">
<div class="button-container"> <div class="button-container">
<button <button
v-if="isLeader && !group.purchased.active" v-if="isLeader && !group.purchased.active && group.privacy === 'private'"
class="btn btn-success btn-success" class="btn btn-success btn-success"
@click="upgradeGroup()" @click="upgradeGroup()"
> >

View File

@@ -293,6 +293,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",

View File

@@ -91,6 +91,10 @@ async function createSubscription (data) {
throw new NotAuthorized(shared.i18n.t('onlyGroupLeaderCanManageSubscription')); throw new NotAuthorized(shared.i18n.t('onlyGroupLeaderCanManageSubscription'));
} }
if (group.privacy !== 'private') {
throw new NotAuthorized(shared.i18n.t('onlyPrivateGuildsCanUpgrade'));
}
recipient = group; recipient = group;
itemPurchased = 'Group-Subscription'; itemPurchased = 'Group-Subscription';
purchaseType = 'group-subscribe'; purchaseType = 'group-subscribe';