mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
fix(tests): new approach attempt
This commit is contained in:
@@ -267,12 +267,12 @@ describe('GET challenges/groups/:groupId', () => {
|
|||||||
|
|
||||||
context('official challenge is present', () => {
|
context('official challenge is present', () => {
|
||||||
let officialChallenge; let unofficialChallenges;
|
let officialChallenge; let unofficialChallenges;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await user.update({
|
await user.update({
|
||||||
'permissions.challengeAdmin': true,
|
'permissions.challengeAdmin': true,
|
||||||
});
|
});
|
||||||
|
|
||||||
officialChallenge = await generateChallenge(user, tavern, {
|
officialChallenge = await generateChallenge(user, tavern, {
|
||||||
categories: [{
|
categories: [{
|
||||||
name: 'habitica_official',
|
name: 'habitica_official',
|
||||||
@@ -281,7 +281,7 @@ describe('GET challenges/groups/:groupId', () => {
|
|||||||
prize: 1,
|
prize: 1,
|
||||||
});
|
});
|
||||||
await user.post(`/challenges/${officialChallenge._id}/join`);
|
await user.post(`/challenges/${officialChallenge._id}/join`);
|
||||||
|
|
||||||
// We add 10 extra challenges to test whether the official challenge
|
// We add 10 extra challenges to test whether the official challenge
|
||||||
// (the oldest) makes it to the front page.
|
// (the oldest) makes it to the front page.
|
||||||
unofficialChallenges = [];
|
unofficialChallenges = [];
|
||||||
@@ -291,27 +291,27 @@ describe('GET challenges/groups/:groupId', () => {
|
|||||||
unofficialChallenges.push(challenge);
|
unofficialChallenges.push(challenge);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return official challenges first', async () => {
|
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 });
|
const foundChallengeIndex = _.findIndex(challenges, { _id: officialChallenge._id });
|
||||||
expect(foundChallengeIndex).to.eql(0);
|
expect(foundChallengeIndex).to.eql(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return newest challenges first, after official ones', async () => {
|
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) => {
|
unofficialChallenges.forEach((chal, index) => {
|
||||||
const foundChallengeIndex = _.findIndex(challenges, { _id: chal._id });
|
const foundChallengeIndex = _.findIndex(challenges, { _id: chal._id });
|
||||||
expect(foundChallengeIndex).to.eql(10 - index);
|
expect(foundChallengeIndex).to.eql(10 - index);
|
||||||
});
|
});
|
||||||
|
|
||||||
const newChallenge = await generateChallenge(user, tavern, { prize: 1 });
|
const newChallenge = await generateChallenge(user, tavern, { prize: 1 });
|
||||||
await user.post(`/challenges/${newChallenge._id}/join`);
|
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 });
|
const foundChallengeIndex = _.findIndex(challenges, { _id: newChallenge._id });
|
||||||
expect(foundChallengeIndex).to.eql(1);
|
expect(foundChallengeIndex).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -127,6 +127,9 @@ export async function createAndPopulateGroup (settings = {}) {
|
|||||||
const upgradeToGroupPlan = settings.upgradeToGroupPlan || false;
|
const upgradeToGroupPlan = settings.upgradeToGroupPlan || false;
|
||||||
const { groupDetails } = settings;
|
const { groupDetails } = settings;
|
||||||
const leaderDetails = settings.leaderDetails || { balance: 10 };
|
const leaderDetails = settings.leaderDetails || { balance: 10 };
|
||||||
|
if (upgradeToGroupPlan) {
|
||||||
|
leaderDetails.permissions = { fullAccess: true };
|
||||||
|
}
|
||||||
|
|
||||||
const groupLeader = await generateUser(leaderDetails);
|
const groupLeader = await generateUser(leaderDetails);
|
||||||
const group = await generateGroup(groupLeader, groupDetails);
|
const group = await generateGroup(groupLeader, groupDetails);
|
||||||
|
|||||||
@@ -126,7 +126,11 @@ api.createGroup = {
|
|||||||
if (validationErrors) throw validationErrors;
|
if (validationErrors) throw validationErrors;
|
||||||
|
|
||||||
if (group.type === 'guild') {
|
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 {
|
} else {
|
||||||
if (group.privacy !== 'private') throw new NotAuthorized(res.t('partyMustbePrivate'));
|
if (group.privacy !== 'private') throw new NotAuthorized(res.t('partyMustbePrivate'));
|
||||||
if (user.party._id) throw new NotAuthorized(res.t('messageGroupAlreadyInParty'));
|
if (user.party._id) throw new NotAuthorized(res.t('messageGroupAlreadyInParty'));
|
||||||
|
|||||||
Reference in New Issue
Block a user