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
@@ -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},
});
});
});
});
@@ -5,7 +5,7 @@ import {
} from '../../../../helpers/api-v3-integration.helper';
describe('GET challenges/user', () => {
let user, member, nonMember, challenge, challenge2;
let user, member, nonMember, challenge, challenge2, publicGuild;
before(async () => {
let { group, groupLeader, members } = await createAndPopulateGroup({
@@ -18,7 +18,7 @@ describe('GET challenges/user', () => {
});
user = groupLeader;
publicGuild = group;
member = members[0];
nonMember = await generateUser();
@@ -33,6 +33,16 @@ describe('GET challenges/user', () => {
let foundChallenge = _.find(challenges, { _id: challenge._id });
expect(foundChallenge).to.exist;
expect(foundChallenge.leader).to.eql({
_id: publicGuild.leader._id,
profile: {name: user.profile.name},
});
expect(foundChallenge.group).to.eql({
_id: publicGuild._id,
type: publicGuild.type,
privacy: publicGuild.privacy,
name: publicGuild.name,
});
});
it('should return challenges user has created', async () => {
@@ -40,8 +50,28 @@ describe('GET challenges/user', () => {
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},
});
expect(foundChallenge1.group).to.eql({
_id: publicGuild._id,
type: publicGuild.type,
privacy: publicGuild.privacy,
name: publicGuild.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},
});
expect(foundChallenge2.group).to.eql({
_id: publicGuild._id,
type: publicGuild.type,
privacy: publicGuild.privacy,
name: publicGuild.name,
});
});
it('should return challenges in user\'s group', async () => {
@@ -49,8 +79,28 @@ describe('GET challenges/user', () => {
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},
});
expect(foundChallenge1.group).to.eql({
_id: publicGuild._id,
type: publicGuild.type,
privacy: publicGuild.privacy,
name: publicGuild.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},
});
expect(foundChallenge2.group).to.eql({
_id: publicGuild._id,
type: publicGuild.type,
privacy: publicGuild.privacy,
name: publicGuild.name,
});
});
it('should not return challenges user doesn\'t have access to', async () => {
@@ -50,7 +50,7 @@ describe('PUT /challenges/:challengeId', () => {
let res = await user.put(`/challenges/${challenge._id}`, {
// ignored
prize: 33,
groupId: 'blabla',
group: 'blabla',
memberCount: 33,
tasksOrder: 'new order',
official: true,
@@ -63,7 +63,7 @@ describe('PUT /challenges/:challengeId', () => {
});
expect(res.prize).to.equal(0);
expect(res.groupId).to.equal(privateGuild._id);
expect(res.group).to.equal(privateGuild._id);
expect(res.memberCount).to.equal(2);
expect(res.tasksOrder).not.to.equal('new order');
expect(res.official).to.equal(false);
@@ -43,10 +43,6 @@ describe('GET /groups/:id', () => {
expect(group.leader._id).to.eql(leader._id);
expect(group.leader.profile.name).to.eql(leader.profile.name);
expect(group.leader.items).to.exist;
expect(group.leader.stats).to.exist;
expect(group.leader.achievements).to.exist;
expect(group.leader.contributor).to.exist;
});
});
});
@@ -32,12 +32,17 @@ describe('POST /group', () => {
});
it('sets the group leader to the user who created the group', async () => {
await expect(
user.post('/groups', {
name: 'Test Public Guild',
type: 'guild',
})
).to.eventually.have.property('leader', user._id);
let group = await user.post('/groups', {
name: 'Test Public Guild',
type: 'guild',
});
expect(group.leader).to.eql({
_id: user._id,
profile: {
name: user.profile.name,
},
});
});
});
@@ -86,6 +91,12 @@ describe('POST /group', () => {
expect(publicGuild.type).to.equal(groupType);
expect(publicGuild.memberCount).to.equal(1);
expect(publicGuild.privacy).to.equal(groupPrivacy);
expect(publicGuild.leader).to.eql({
_id: user._id,
profile: {
name: user.profile.name,
},
});
});
});
@@ -106,6 +117,12 @@ describe('POST /group', () => {
expect(privateGuild.type).to.equal(groupType);
expect(privateGuild.memberCount).to.equal(1);
expect(privateGuild.privacy).to.equal(groupPrivacy);
expect(privateGuild.leader).to.eql({
_id: user._id,
profile: {
name: user.profile.name,
},
});
});
it('deducts gems from user and adds them to guild bank', async () => {
@@ -138,6 +155,12 @@ describe('POST /group', () => {
expect(party.name).to.equal(partyName);
expect(party.type).to.equal(partyType);
expect(party.memberCount).to.equal(1);
expect(party.leader).to.eql({
_id: user._id,
profile: {
name: user.profile.name,
},
});
});
it('does not require gems to create a party', async () => {