Ensured tavern is not returned twice and removed leader population

This commit is contained in:
Keith Holliday
2016-01-19 08:13:24 -06:00
parent c5947ca9c4
commit be55176954
2 changed files with 8 additions and 9 deletions

View File

@@ -76,8 +76,7 @@ describe('GET /groups', () => {
it('returns only the user\'s party when party passed in as query', async () => { it('returns only the user\'s party when party passed in as query', async () => {
await expect(user.get('/groups?type=party')) await expect(user.get('/groups?type=party'))
.to.eventually.have.a.lengthOf(1) .to.eventually.have.a.lengthOf(1)
.and.to.have.deep.property('[0]') .and.to.have.deep.property('[0]');
.and.to.have.property('leader._id', user._id);
}); });
it('returns all public guilds when publicGuilds passed in as query', async () => { it('returns all public guilds when publicGuilds passed in as query', async () => {
@@ -91,9 +90,7 @@ describe('GET /groups', () => {
}); });
it('returns a list of groups user has access to', async () => { it('returns a list of groups user has access to', async () => {
let groups = await user.get('/groups?type=privateGuilds,publicGuilds,party'); await expect(user.get('/groups?type=privateGuilds,publicGuilds,party,tavern'))
.to.eventually.have.lengthOf(NUMBER_OF_GROUPS_USER_CAN_VIEW);
expect(groups.length)
.to.eql(NUMBER_OF_GROUPS_USER_CAN_VIEW);
}); });
}); });

View File

@@ -86,14 +86,14 @@ api.getGroups = {
// TODO validate types are acceptable? probably not necessary // TODO validate types are acceptable? probably not necessary
let types = req.query.type.split(','); let types = req.query.type.split(',');
let groupFields = 'name description memberCount balance leader'; let groupFields = 'name description memberCount balance';
let sort = '-memberCount'; let sort = '-memberCount';
let queries = []; let queries = [];
types.forEach(type => { types.forEach(type => {
switch (type) { switch (type) {
case 'party': case 'party':
queries.push(Group.getGroup({user, groupId: 'party', fields: groupFields, populateLeader: true})); queries.push(Group.getGroup({user, groupId: 'party', fields: groupFields}));
break; break;
case 'privateGuilds': case 'privateGuilds':
queries.push(Group.find({ queries.push(Group.find({
@@ -109,7 +109,9 @@ api.getGroups = {
}).select(groupFields).sort(sort).exec()); // TODO use lean? }).select(groupFields).sort(sort).exec()); // TODO use lean?
break; break;
case 'tavern': case 'tavern':
queries.push(Group.getGroup({user, groupId: 'habitrpg', fields: groupFields, populateLeader: true})); if (types.indexOf('publicGuilds') === -1) {
queries.push(Group.getGroup({user, groupId: 'habitrpg', fields: groupFields}));
}
break; break;
} }
}); });