From d39485802291d65d563e92764bfb75ba1018a88c Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 25 Jul 2023 18:00:31 -0500 Subject: [PATCH] fix(tests): new approach attempt --- .../GET-challenges_group_groupid.test.js | 26 +++++++++---------- .../api-integration/v3/object-generators.js | 3 +++ website/server/controllers/api-v3/groups.js | 6 ++++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/test/api/v3/integration/challenges/GET-challenges_group_groupid.test.js b/test/api/v3/integration/challenges/GET-challenges_group_groupid.test.js index 3bcfaaa627..abbfb50ae2 100644 --- a/test/api/v3/integration/challenges/GET-challenges_group_groupid.test.js +++ b/test/api/v3/integration/challenges/GET-challenges_group_groupid.test.js @@ -267,12 +267,12 @@ describe('GET challenges/groups/:groupId', () => { context('official challenge is present', () => { let officialChallenge; let unofficialChallenges; - + before(async () => { await user.update({ 'permissions.challengeAdmin': true, }); - + officialChallenge = await generateChallenge(user, tavern, { categories: [{ name: 'habitica_official', @@ -281,7 +281,7 @@ describe('GET challenges/groups/:groupId', () => { prize: 1, }); await user.post(`/challenges/${officialChallenge._id}/join`); - + // We add 10 extra challenges to test whether the official challenge // (the oldest) makes it to the front page. unofficialChallenges = []; @@ -291,27 +291,27 @@ describe('GET challenges/groups/:groupId', () => { unofficialChallenges.push(challenge); } }); - + it('should return official challenges first', async () => { - const challenges = await user.get(`/challenges/groups/habitrpg`); - + const challenges = await user.get('/challenges/groups/habitrpg'); + const foundChallengeIndex = _.findIndex(challenges, { _id: officialChallenge._id }); expect(foundChallengeIndex).to.eql(0); }); - + it('should return newest challenges first, after official ones', async () => { - let challenges = await user.get(`/challenges/groups/habitrpg`); - + let challenges = await user.get('/challenges/groups/habitrpg'); + unofficialChallenges.forEach((chal, index) => { const foundChallengeIndex = _.findIndex(challenges, { _id: chal._id }); expect(foundChallengeIndex).to.eql(10 - index); }); - + const newChallenge = await generateChallenge(user, tavern, { prize: 1 }); await user.post(`/challenges/${newChallenge._id}/join`); - - challenges = await user.get(`/challenges/groups/${publicGuild._id}`); - + + challenges = await user.get('/challenges/groups/habitrpg'); + const foundChallengeIndex = _.findIndex(challenges, { _id: newChallenge._id }); expect(foundChallengeIndex).to.eql(1); }); diff --git a/test/helpers/api-integration/v3/object-generators.js b/test/helpers/api-integration/v3/object-generators.js index b48dd862a9..e3a7c723c9 100644 --- a/test/helpers/api-integration/v3/object-generators.js +++ b/test/helpers/api-integration/v3/object-generators.js @@ -127,6 +127,9 @@ export async function createAndPopulateGroup (settings = {}) { const upgradeToGroupPlan = settings.upgradeToGroupPlan || false; const { groupDetails } = settings; const leaderDetails = settings.leaderDetails || { balance: 10 }; + if (upgradeToGroupPlan) { + leaderDetails.permissions = { fullAccess: true }; + } const groupLeader = await generateUser(leaderDetails); const group = await generateGroup(groupLeader, groupDetails); diff --git a/website/server/controllers/api-v3/groups.js b/website/server/controllers/api-v3/groups.js index 7d9a50736c..5d30fdc61e 100644 --- a/website/server/controllers/api-v3/groups.js +++ b/website/server/controllers/api-v3/groups.js @@ -126,7 +126,11 @@ api.createGroup = { if (validationErrors) throw validationErrors; if (group.type === 'guild') { - throw new BadRequest(res.t('featureRetired')); + if (!user.hasPermission('fullAccess')) { + throw new BadRequest(res.t('featureRetired')); + } + group.balance = 1; + user.guilds.push(group._id); } else { if (group.privacy !== 'private') throw new NotAuthorized(res.t('partyMustbePrivate')); if (user.party._id) throw new NotAuthorized(res.t('messageGroupAlreadyInParty'));