mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user