-
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
Added get group challenges route and initial tests #6590
Conversation
The |
Yea, I agree. I was trying to use the chai .include, but the object aren't equal. I'll look through the documentation a bit. Maybe, we can extend chai to use lodash. |
The chai things plugin might be helpful. http://chaijs.com/plugins/chai-things |
@blade when I suggested the same plugin you said you prefer not to have it 😢 |
On a more constructive note, in such cases I do:
|
@TheHollidayInn the PR looks good, a few things:
|
I just noticed we don't have tests for getUserChallenge either so it may be a good occasion to add them! |
Actually don't add population, I'm not sure if it's really needed. We'll add it later if it becomes necessary |
@KristianTashkov I thought you might say that. 😄 I don't recall the exact details of why you wanted to use it, but I don't think the assertions looked quite as messy as these do. In any case, I think you were right, this would be a good plugin to add. |
e81a371
to
97dee87
Compare
So, Chai Things does not play well with Chai Keys: chaijs/chai-things#24 . |
it('should return group challenges for non member', async () => { | ||
let challenges = await nonMember.get(`/challenges/groups/${publicGuild._id}`); | ||
|
||
expect(_.findIndex(challenges, {_id: challenge._id})).to.be.above(-1); |
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.
If we can't use chai-things
, I'd prefer this to be something like
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
97dee87
to
d96f35e
Compare
@@ -121,7 +121,8 @@ api.joinChallenge = { | |||
let challenge = await Challenge.findOne({ _id: req.params.challengeId }); | |||
if (!challenge) throw new NotFound(res.t('challengeNotFound')); | |||
|
|||
if (!challenge.hasAccess(user)) throw new NotFound(res.t('challengeNotFound')); | |||
let group = await Group.getGroup({user, groupId: challenge.groupId, fields: '_id type privacy', optionalMembership: true}); |
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 enough
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.
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.
Except for my last comment it looks good! |
d96f35e
to
754befc
Compare
Updated! |
Added get group challenges route and initial tests
@TheHollidayInn thanks! in the end i preferred to use a modified hasAccess that will work with public guilds too so it's almost the same as canView except that it doesn't return true if you're already a member of the challenge because that's handled separately by challenge.isMember and in case will return a |
Sounds good, thanks! |
This address Get challenges for group and tests in #6509. I didn't see much logic here that needed to be abstracted, @paglias . Let me know if you disagree.