Skip to content
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

Merged

Conversation

TheHollidayInn
Copy link
Contributor

These are the initial get groups tests for #6509

let leader = await generateUser({ balance: 10 });
user = await generateUser({balance: 4});

let publicGuildUserIsMemberOf = await generateGroup(leader, {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep ^^

@TheHollidayInn TheHollidayInn force-pushed the api-v3-group-get-groups-test branch from 8cf32e6 to 4fbca93 Compare January 17, 2016 17:22
@@ -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) => {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@TheHollidayInn TheHollidayInn force-pushed the api-v3-group-get-groups-test branch from 4fbca93 to b60e0a4 Compare January 17, 2016 19:32
let groups = await user.get('/groups?type=privateGuilds,publicGuilds,party');

await expect(groups.length)
.to.eql(NUMBER_OF_GROUPS_USER_CAN_VIEW);
Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you awaiting at all? groups.length does not return a promise.

Copy link
Contributor Author

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..

@TheHollidayInn TheHollidayInn force-pushed the api-v3-group-get-groups-test branch from 133a7c0 to c5947ca Compare January 17, 2016 20:20
@paglias
Copy link
Contributor

paglias commented Jan 18, 2016

@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

@TheHollidayInn
Copy link
Contributor Author

....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?

@paglias
Copy link
Contributor

paglias commented Jan 18, 2016

@TheHollidayInn for the tavern I think the best thing is to do something like this:

  1. When only the tavern is fetched and not other public guilds -> fetch it as a single doc
  2. When public guilds are fetched and the tavern too, just fetch public guilds since the tavern will be included

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

@TheHollidayInn
Copy link
Contributor Author

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.

@crookedneighbor
Copy link
Contributor

Ahh, yeah, the tavern + public guilds thing is exactly what is happening. (I made a note about that in the v2 tests)

@crookedneighbor
Copy link
Contributor

Also. Here's a crazy idea. (Not for this PR) What if we made the tavern it's own kind of group? IE: type: 'tavern'?

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?

@paglias
Copy link
Contributor

paglias commented Jan 18, 2016

@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

@Alys
Copy link
Contributor

Alys commented Jan 18, 2016 via email

@paglias
Copy link
Contributor

paglias commented Jan 18, 2016

@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

@crookedneighbor
Copy link
Contributor

@paglias Good points.

@TheHollidayInn
Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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.

@TheHollidayInn TheHollidayInn force-pushed the api-v3-group-get-groups-test branch from 39a7855 to be55176 Compare January 19, 2016 14:13
@TheHollidayInn
Copy link
Contributor Author

Updated.

paglias added a commit that referenced this pull request Jan 24, 2016
@paglias paglias merged commit fe170a5 into HabitRPG:api-v3-groups Jan 24, 2016
@TheHollidayInn TheHollidayInn deleted the api-v3-group-get-groups-test branch January 24, 2016 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants