-
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 initial get groups tests #6531
Added initial get groups tests #6531
Conversation
let leader = await generateUser({ balance: 10 }); | ||
user = await generateUser({balance: 4}); | ||
|
||
let publicGuildUserIsMemberOf = await generateGroup(leader, { |
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.
Is there a reason why you are not using createAndPopulateGroup
for creating a group with members in it?
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.
Probably because it's not part of the interface to add an existing user in the createAndPopulateGroup
helper. Should probably add that functionality.
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.
Yep ^^
8cf32e6
to
4fbca93
Compare
@@ -123,6 +123,10 @@ api.getGroups = { | |||
return previousValue.concat(Array.isArray(currentValue) ? currentValue : [currentValue]); // otherwise concat the new results to the previousValue | |||
}, []); | |||
|
|||
results = _.uniq(results, (group) => { |
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 uniq? When it can result in the same challenge returned twice?
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.
Never mind about this. For some reason the await-to-eventually-have-lengthOf function was not counting the return object correctly. I am about to push a revision.
4fbca93
to
b60e0a4
Compare
let groups = await user.get('/groups?type=privateGuilds,publicGuilds,party'); | ||
|
||
await expect(groups.length) | ||
.to.eql(NUMBER_OF_GROUPS_USER_CAN_VIEW); |
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.
When I put the await inside of the expect and called to.eventually.be.lengthOf
this was counting incorrectly.
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.
Why are you await
ing at all? groups.length
does not return a promise.
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.
Eh, that is left over syntax. Now, I am in the habit of adding await before my expects..
133a7c0
to
c5947ca
Compare
@TheHollidayInn it's possible that when you fetch public guilds the tavern is returned too? Which means that if you fetch both tavern and publicGuilds the tavern could be duplicated? Also I'm not sure if we should populate the leader for the party and the tavern but not for other guilds, it's doesn't make sense |
....dang. Yep, that is what I was doing. I went to test that out and forgot to put back the tavern string. So, then, that is why I was using _.uniq. Should we modify something else to ensure that tavern isn't duplicated or should I just leave the string as it is? And, I'm unsure what the populate leader code does. I was going to test it on the get group by id tests. Do you want me to look into it? |
@TheHollidayInn for the tavern I think the best thing is to do something like this:
We could use https://docs.mongodb.org/manual/reference/operator/query/ne/ to exclude the tavern id but according to MongoDB's docs it's very inefficient. The populateLeader option should be removed, basically it populates the leader field with the leader profile name but we don't care when listing all the guilds |
Sounds good. I can make that change in the route. I was doing that with _.uniq, but I bet if I just check for the param and skip the tavern push when we see public guilds, that would be more efficient. I'll post the solution. Ah, I see what you are saying. Yea, I will remove the populateLeader. |
Ahh, yeah, the tavern + public guilds thing is exactly what is happening. (I made a note about that in the v2 tests) |
Also. Here's a crazy idea. (Not for this PR) What if we made the tavern it's own kind of group? IE: We're already going to need to change the id from 'habitrpg' to a uuid, right? Does it make more sense to call out that it is, in fact, a different kind of group? |
@crookedneighbor hmm for the uuid I made this change and we should be fine now. At this point changing the type of group would require to change a lot of code and in fact the tavern works almost as a normal public guild except that everyone is always a members |
Making the Tavern a new kind of group makes sense to me. Do we want to do
the same for Party Wanted and Newbies?
|
@Alys @crookedneighbor I think we can have an attribute to identify official groups but not a completely different type of groups :( It would really complicate the code and there's no reason to do it as long as the functionalities are the same. And also having it compatible with api-v2 would complicate things even more. I think it can be reviewed post api v3 but not now |
@paglias Good points. |
Updated with the two changes @paglias requested. |
@@ -109,7 +109,9 @@ api.getGroups = { | |||
}).select(groupFields).sort(sort).exec()); // TODO use lean? | |||
break; | |||
case 'tavern': | |||
queries.push(Group.getGroup({user, groupId: 'habitrpg', fields: groupFields, populateLeader: true})); | |||
if (types.indexOf('publicGuilds') === -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.
@TheHollidayInn could you remove the populateLeader at line 96? thanks
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 at line 113 too
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.
Eh, sorry about that. I didn't notice it was a parameter. I was thinking it was just in the projection.
39a7855
to
be55176
Compare
Updated. |
…test Added initial get groups tests
These are the initial get groups tests for #6509