Merge branch 'develop' of github.com:HabitRPG/habitrpg into develop

This commit is contained in:
Matteo Pagliazzi
2016-08-04 20:00:19 +02:00
8 changed files with 96 additions and 17 deletions

View File

@@ -4,12 +4,21 @@ import {
translate as t,
} from '../../../../helpers/api-v3-integration.helper';
import { v4 as generateUUID } from 'uuid';
import common from '../../../../../common';
describe('GET /groups/:groupId/members', () => {
let user;
beforeEach(async () => {
user = await generateUser();
user = await generateUser({
balance: 10,
contributor: {level: 1},
backer: {tier: 3},
preferences: {
costume: false,
background: 'volcano',
},
});
});
it('validates optional req.query.lastId to be an UUID', async () => {
@@ -57,6 +66,30 @@ describe('GET /groups/:groupId/members', () => {
expect(res[0].profile).to.have.all.keys(['name']);
});
it('req.query.includeAllPublicFields === true only works with parties', async () => {
let group = await generateGroup(user, {type: 'guild', name: generateUUID()});
let res = await user.get(`/groups/${group._id}/members?includeAllPublicFields=true`);
expect(res[0]).to.have.all.keys(['_id', 'id', 'profile']);
expect(res[0].profile).to.have.all.keys(['name']);
});
it('populates all public fields if req.query.includeAllPublicFields === true and it is a party', async () => {
await generateGroup(user, {type: 'party', name: generateUUID()});
let [memberRes] = await user.get('/groups/party/members?includeAllPublicFields=true');
expect(memberRes).to.have.all.keys([ // works as: object has all and only these keys
'_id', 'id', 'preferences', 'profile', 'stats', 'achievements', 'party',
'backer', 'contributor', 'auth', 'items',
]);
expect(Object.keys(memberRes.auth)).to.eql(['timestamps']);
expect(Object.keys(memberRes.preferences).sort()).to.eql(['size', 'hair', 'skin', 'shirt',
'chair', 'costume', 'sleep', 'background'].sort());
expect(memberRes.stats.maxMP).to.exists;
expect(memberRes.stats.maxHealth).to.equal(common.maxHealth);
expect(memberRes.stats.toNextLevel).to.equal(common.tnl(memberRes.stats.lvl));
});
it('returns only first 30 members', async () => {
let group = await generateGroup(user, {type: 'party', name: generateUUID()});

View File

@@ -1,9 +1,12 @@
import {
generateUser,
resetHabiticaDB,
} from '../../../../helpers/api-v3-integration.helper';
describe('GET /hall/heroes', () => {
it('returns all heroes sorted by -contributor.level and with correct fields', async () => {
await resetHabiticaDB();
let nonHero = await generateUser();
let hero1 = await generateUser({
contributor: {level: 1},

View File

@@ -3,6 +3,7 @@ import {
translate as t,
} from '../../../../helpers/api-v3-integration.helper';
import { v4 as generateUUID } from 'uuid';
import common from '../../../../../common';
describe('GET /members/:memberId', () => {
let user;
@@ -36,6 +37,10 @@ describe('GET /members/:memberId', () => {
expect(Object.keys(memberRes.auth)).to.eql(['timestamps']);
expect(Object.keys(memberRes.preferences).sort()).to.eql(['size', 'hair', 'skin', 'shirt',
'chair', 'costume', 'sleep', 'background'].sort());
expect(memberRes.stats.maxMP).to.exists;
expect(memberRes.stats.maxHealth).to.equal(common.maxHealth);
expect(memberRes.stats.toNextLevel).to.equal(common.tnl(memberRes.stats.lvl));
});
it('handles non-existing members', async () => {

View File

@@ -1,6 +1,7 @@
import {
generateUser,
} from '../../../../helpers/api-integration/v3';
import common from '../../../../../common';
describe('GET /user', () => {
let user;
@@ -9,9 +10,13 @@ describe('GET /user', () => {
user = await generateUser();
});
it('returns the authenticated user', async () => {
it('returns the authenticated user with computed stats', async () => {
let returnedUser = await user.get('/user');
expect(returnedUser._id).to.equal(user._id);
expect(returnedUser.stats.maxMP).to.exists;
expect(returnedUser.stats.maxHealth).to.equal(common.maxHealth);
expect(returnedUser.stats.toNextLevel).to.equal(common.tnl(returnedUser.stats.lvl));
});
it('does not return private paths (and apiToken)', async () => {

View File

@@ -1,4 +1,5 @@
import { model as User } from '../../../../../website/server/models/user';
import common from '../../../../../common';
describe('User Model', () => {
it('keeps user._tmp when calling .toJSON', () => {
@@ -31,6 +32,21 @@ describe('User Model', () => {
expect(toJSON).to.not.have.keys('_nonTmp');
});
it('can add computed stats to a JSONified user object', () => {
let user = new User();
let userToJSON = user.toJSON();
expect(userToJSON.stats.maxMP).to.not.exists;
expect(userToJSON.stats.maxHealth).to.not.exists;
expect(userToJSON.stats.toNextLevel).to.not.exists;
user.addComputedStatsToJSONObj(userToJSON);
expect(userToJSON.stats.maxMP).to.exists;
expect(userToJSON.stats.maxHealth).to.equal(common.maxHealth);
expect(userToJSON.stats.toNextLevel).to.equal(common.tnl(user.stats.lvl));
});
context('notifications', () => {
it('can add notifications with data', () => {
let user = new User();