add population to challenge.group, challenge.leader and group.leader

This commit is contained in:
Matteo Pagliazzi
2016-02-02 21:47:12 +01:00
parent 509dffd0c7
commit 7a5aa731db
13 changed files with 207 additions and 62 deletions

View File

@@ -27,22 +27,38 @@ describe('GET challenges/group/:groupId', () => {
challenge2 = await generateChallenge(user, group);
});
it('should return group challenges for non member', async () => {
it('should return group challenges for non member with populated leader', async () => {
let challenges = await nonMember.get(`/challenges/groups/${publicGuild._id}`);
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: publicGuild.leader._id,
profile: {name: user.profile.name},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: publicGuild.leader._id,
profile: {name: user.profile.name},
});
});
it('should return group challenges for member', async () => {
it('should return group challenges for member with populated leader', async () => {
let challenges = await user.get(`/challenges/groups/${publicGuild._id}`);
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: publicGuild.leader._id,
profile: {name: user.profile.name},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: publicGuild.leader._id,
profile: {name: user.profile.name},
});
});
});
@@ -76,13 +92,21 @@ describe('GET challenges/group/:groupId', () => {
});
});
it('should return group challenges for member', async () => {
it('should return group challenges for member with populated leader', async () => {
let challenges = await user.get(`/challenges/groups/${privateGuild._id}`);
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: privateGuild.leader._id,
profile: {name: user.profile.name},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: privateGuild.leader._id,
profile: {name: user.profile.name},
});
});
});
});