API: return computed stats for members routes (#7870)

* api: return computed stats for members responses

* add integration tests for computed stats

* add unit tests for computed stats

* clarify test name

* add missing query parameter to test case

* reset test database before running API tests for the Hall
This commit is contained in:
Matteo Pagliazzi
2016-08-04 19:56:00 +02:00
committed by GitHub
parent d097868cad
commit d7ccf2bbe1
8 changed files with 96 additions and 17 deletions

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();