-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added get group challenges route and initial tests #6590
Merged
paglias
merged 2 commits into
HabitRPG:api-v3-groups
from
TheHollidayInn:api-v3-get-group-challenges
Feb 2, 2016
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
test/api/v3/integration/challenges/GET-challenges_group_groupid.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
generateUser, | ||
generateChallenge, | ||
createAndPopulateGroup, | ||
translate as t, | ||
} from '../../../../helpers/api-v3-integration.helper'; | ||
|
||
describe('GET challenges/group/:groupId', () => { | ||
context('Public Guild', () => { | ||
let publicGuild, user, nonMember, challenge, challenge2; | ||
|
||
before(async () => { | ||
let { group, groupLeader } = await createAndPopulateGroup({ | ||
groupDetails: { | ||
name: 'TestGuild', | ||
type: 'guild', | ||
privacy: 'public', | ||
}, | ||
}); | ||
|
||
publicGuild = group; | ||
user = groupLeader; | ||
|
||
nonMember = await generateUser(); | ||
|
||
challenge = await generateChallenge(user, group); | ||
challenge2 = await generateChallenge(user, group); | ||
}); | ||
|
||
it('should return group challenges for non member', async () => { | ||
let challenges = await nonMember.get(`/challenges/groups/${publicGuild._id}`); | ||
|
||
let foundChallenge1 = _.find(challenges, { _id: challenge._id }); | ||
expect(foundChallenge1).to.exist; | ||
let foundChallenge2 = _.find(challenges, { _id: challenge2._id }); | ||
expect(foundChallenge2).to.exist; | ||
}); | ||
|
||
it('should return group challenges for member', async () => { | ||
let challenges = await user.get(`/challenges/groups/${publicGuild._id}`); | ||
|
||
let foundChallenge1 = _.find(challenges, { _id: challenge._id }); | ||
expect(foundChallenge1).to.exist; | ||
let foundChallenge2 = _.find(challenges, { _id: challenge2._id }); | ||
expect(foundChallenge2).to.exist; | ||
}); | ||
}); | ||
|
||
context('Private Guild', () => { | ||
let privateGuild, user, nonMember, challenge, challenge2; | ||
|
||
before(async () => { | ||
let { group, groupLeader } = await createAndPopulateGroup({ | ||
groupDetails: { | ||
name: 'TestPrivateGuild', | ||
type: 'guild', | ||
privacy: 'private', | ||
}, | ||
}); | ||
|
||
privateGuild = group; | ||
user = groupLeader; | ||
|
||
nonMember = await generateUser(); | ||
|
||
challenge = await generateChallenge(user, group); | ||
challenge2 = await generateChallenge(user, group); | ||
}); | ||
|
||
it('should prevent non-member from seeing challenges', async () => { | ||
await expect(nonMember.get(`/challenges/groups/${privateGuild._id}`)) | ||
.to.eventually.be.rejected.and.eql({ | ||
code: 404, | ||
error: 'NotFound', | ||
message: t('groupNotFound'), | ||
}); | ||
}); | ||
|
||
it('should return group challenges for member', async () => { | ||
let challenges = await user.get(`/challenges/groups/${privateGuild._id}`); | ||
|
||
let foundChallenge1 = _.find(challenges, { _id: challenge._id }); | ||
expect(foundChallenge1).to.exist; | ||
let foundChallenge2 = _.find(challenges, { _id: challenge2._id }); | ||
expect(foundChallenge2).to.exist; | ||
}); | ||
}); | ||
}); |
72 changes: 72 additions & 0 deletions
72
test/api/v3/integration/challenges/GET-challenges_user.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { | ||
generateUser, | ||
generateChallenge, | ||
createAndPopulateGroup, | ||
} from '../../../../helpers/api-v3-integration.helper'; | ||
|
||
describe('GET challenges/user', () => { | ||
let user, member, nonMember, challenge, challenge2; | ||
|
||
before(async () => { | ||
let { group, groupLeader, members } = await createAndPopulateGroup({ | ||
groupDetails: { | ||
name: 'TestGuild', | ||
type: 'guild', | ||
privacy: 'public', | ||
}, | ||
members: 1, | ||
}); | ||
|
||
user = groupLeader; | ||
|
||
member = members[0]; | ||
nonMember = await generateUser(); | ||
|
||
challenge = await generateChallenge(user, group); | ||
challenge2 = await generateChallenge(user, group); | ||
}); | ||
|
||
it('should return challenges user has joined', async () => { | ||
await nonMember.post(`/challenges/${challenge._id}/join`); | ||
|
||
let challenges = await nonMember.get(`/challenges/user`); | ||
|
||
let foundChallenge = _.find(challenges, { _id: challenge._id }); | ||
expect(foundChallenge).to.exist; | ||
}); | ||
|
||
it('should return challenges user has created', async () => { | ||
let challenges = await user.get(`/challenges/user`); | ||
|
||
let foundChallenge1 = _.find(challenges, { _id: challenge._id }); | ||
expect(foundChallenge1).to.exist; | ||
let foundChallenge2 = _.find(challenges, { _id: challenge2._id }); | ||
expect(foundChallenge2).to.exist; | ||
}); | ||
|
||
it('should return challenges in user\'s group', async () => { | ||
let challenges = await member.get(`/challenges/user`); | ||
|
||
let foundChallenge1 = _.find(challenges, { _id: challenge._id }); | ||
expect(foundChallenge1).to.exist; | ||
let foundChallenge2 = _.find(challenges, { _id: challenge2._id }); | ||
expect(foundChallenge2).to.exist; | ||
}); | ||
|
||
it('should not return challenges user doesn\'t have access to', async () => { | ||
let { group, groupLeader } = await createAndPopulateGroup({ | ||
groupDetails: { | ||
name: 'TestPrivateGuild', | ||
type: 'guild', | ||
privacy: 'private', | ||
}, | ||
}); | ||
|
||
let privateChallenge = await generateChallenge(groupLeader, group); | ||
|
||
let challenges = await nonMember.get(`/challenges/user`); | ||
|
||
let foundChallenge = _.find(challenges, { _id: privateChallenge._id }); | ||
expect(foundChallenge).to.not.exist; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheHollidayInn why you added this check?
challenge.hasAccess
should haveve been enoughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I undestand, you should be able to join challenges in public guilds without being a member of the guild and I guess this fixes it. But probably this logic should be put in
hasAccess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yes, this logic should be in hasAccess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KristianTashkov Yep, this is exactly the case.
I'll move the logic. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it seems the challenge.canView callas hasAccess, so basically, we only need to check viewAccess.