api: expose user's inbox.optOut for api/v3/members/:memberId #7798 (#7893)

* api: expose user's inbox.optOut for `api/v3/members/:memberId` #7798

* test: fixed chai exist vs exists typos

* _getMembersForItem: fixed typo in api docs
This commit is contained in:
Jaka Kranjc
2016-08-16 05:21:14 +02:00
committed by Blade Barringer
parent 1a409848a8
commit 408d988341
10 changed files with 29 additions and 25 deletions

View File

@@ -79,15 +79,17 @@ describe('GET /groups/:groupId/members', () => {
expect(memberRes).to.have.all.keys([ // works as: object has all and only these keys expect(memberRes).to.have.all.keys([ // works as: object has all and only these keys
'_id', 'id', 'preferences', 'profile', 'stats', 'achievements', 'party', '_id', 'id', 'preferences', 'profile', 'stats', 'achievements', 'party',
'backer', 'contributor', 'auth', 'items', 'backer', 'contributor', 'auth', 'items', 'inbox',
]); ]);
expect(Object.keys(memberRes.auth)).to.eql(['timestamps']); expect(Object.keys(memberRes.auth)).to.eql(['timestamps']);
expect(Object.keys(memberRes.preferences).sort()).to.eql(['size', 'hair', 'skin', 'shirt', expect(Object.keys(memberRes.preferences).sort()).to.eql(['size', 'hair', 'skin', 'shirt',
'chair', 'costume', 'sleep', 'background'].sort()); 'chair', 'costume', 'sleep', 'background'].sort());
expect(memberRes.stats.maxMP).to.exists; expect(memberRes.stats.maxMP).to.exist;
expect(memberRes.stats.maxHealth).to.equal(common.maxHealth); expect(memberRes.stats.maxHealth).to.equal(common.maxHealth);
expect(memberRes.stats.toNextLevel).to.equal(common.tnl(memberRes.stats.lvl)); expect(memberRes.stats.toNextLevel).to.equal(common.tnl(memberRes.stats.lvl));
expect(memberRes.inbox.optOut).to.exist;
expect(memberRes.inbox.messages).to.not.exist;
}); });
it('returns only first 30 members', async () => { it('returns only first 30 members', async () => {

View File

@@ -32,15 +32,17 @@ describe('GET /members/:memberId', () => {
let memberRes = await user.get(`/members/${member._id}`); let memberRes = await user.get(`/members/${member._id}`);
expect(memberRes).to.have.all.keys([ // works as: object has all and only these keys expect(memberRes).to.have.all.keys([ // works as: object has all and only these keys
'_id', 'id', 'preferences', 'profile', 'stats', 'achievements', 'party', '_id', 'id', 'preferences', 'profile', 'stats', 'achievements', 'party',
'backer', 'contributor', 'auth', 'items', 'backer', 'contributor', 'auth', 'items', 'inbox',
]); ]);
expect(Object.keys(memberRes.auth)).to.eql(['timestamps']); expect(Object.keys(memberRes.auth)).to.eql(['timestamps']);
expect(Object.keys(memberRes.preferences).sort()).to.eql(['size', 'hair', 'skin', 'shirt', expect(Object.keys(memberRes.preferences).sort()).to.eql(['size', 'hair', 'skin', 'shirt',
'chair', 'costume', 'sleep', 'background'].sort()); 'chair', 'costume', 'sleep', 'background'].sort());
expect(memberRes.stats.maxMP).to.exists; expect(memberRes.stats.maxMP).to.exist;
expect(memberRes.stats.maxHealth).to.equal(common.maxHealth); expect(memberRes.stats.maxHealth).to.equal(common.maxHealth);
expect(memberRes.stats.toNextLevel).to.equal(common.tnl(memberRes.stats.lvl)); expect(memberRes.stats.toNextLevel).to.equal(common.tnl(memberRes.stats.lvl));
expect(memberRes.inbox.optOut).to.exist;
expect(memberRes.inbox.messages).to.not.exist;
}); });
it('handles non-existing members', async () => { it('handles non-existing members', async () => {

View File

@@ -14,7 +14,7 @@ describe('GET /user', () => {
let returnedUser = await user.get('/user'); let returnedUser = await user.get('/user');
expect(returnedUser._id).to.equal(user._id); expect(returnedUser._id).to.equal(user._id);
expect(returnedUser.stats.maxMP).to.exists; expect(returnedUser.stats.maxMP).to.exist;
expect(returnedUser.stats.maxHealth).to.equal(common.maxHealth); expect(returnedUser.stats.maxHealth).to.equal(common.maxHealth);
expect(returnedUser.stats.toNextLevel).to.equal(common.tnl(returnedUser.stats.lvl)); expect(returnedUser.stats.toNextLevel).to.equal(common.tnl(returnedUser.stats.lvl));
}); });

View File

@@ -156,7 +156,7 @@ describe('POST /user/class/cast/:spellId', () => {
await groupLeader.post('/user/class/cast/earth'); await groupLeader.post('/user/class/cast/earth');
await sleep(1); await sleep(1);
await group.sync(); await group.sync();
expect(group.chat[0]).to.exists; expect(group.chat[0]).to.exist;
expect(group.chat[0].uuid).to.equal('system'); expect(group.chat[0].uuid).to.equal('system');
}); });

View File

@@ -36,13 +36,13 @@ describe('User Model', () => {
let user = new User(); let user = new User();
let userToJSON = user.toJSON(); let userToJSON = user.toJSON();
expect(userToJSON.stats.maxMP).to.not.exists; expect(userToJSON.stats.maxMP).to.not.exist;
expect(userToJSON.stats.maxHealth).to.not.exists; expect(userToJSON.stats.maxHealth).to.not.exist;
expect(userToJSON.stats.toNextLevel).to.not.exists; expect(userToJSON.stats.toNextLevel).to.not.exist;
user.addComputedStatsToJSONObj(userToJSON); user.addComputedStatsToJSONObj(userToJSON);
expect(userToJSON.stats.maxMP).to.exists; expect(userToJSON.stats.maxMP).to.exist;
expect(userToJSON.stats.maxHealth).to.equal(common.maxHealth); expect(userToJSON.stats.maxHealth).to.equal(common.maxHealth);
expect(userToJSON.stats.toNextLevel).to.equal(common.tnl(user.stats.lvl)); expect(userToJSON.stats.toNextLevel).to.equal(common.tnl(user.stats.lvl));
}); });

View File

@@ -32,7 +32,7 @@ describe('shared.ops.addTask', () => {
expect(habit.up).to.equal(true); expect(habit.up).to.equal(true);
expect(habit.down).to.equal(false); expect(habit.down).to.equal(false);
expect(habit.history).to.eql([]); expect(habit.history).to.eql([]);
expect(habit.checklist).to.not.exists; expect(habit.checklist).to.not.exist;
}); });
it('adds an habtit when type is invalid', () => { it('adds an habtit when type is invalid', () => {
@@ -53,7 +53,7 @@ describe('shared.ops.addTask', () => {
expect(habit.up).to.equal(true); expect(habit.up).to.equal(true);
expect(habit.down).to.equal(false); expect(habit.down).to.equal(false);
expect(habit.history).to.eql([]); expect(habit.history).to.eql([]);
expect(habit.checklist).to.not.exists; expect(habit.checklist).to.not.exist;
}); });
it('adds a daily', () => { it('adds a daily', () => {
@@ -73,7 +73,7 @@ describe('shared.ops.addTask', () => {
expect(daily.history).to.eql([]); expect(daily.history).to.eql([]);
expect(daily.checklist).to.eql([]); expect(daily.checklist).to.eql([]);
expect(daily.completed).to.be.false; expect(daily.completed).to.be.false;
expect(daily.up).to.not.exists; expect(daily.up).to.not.exist;
}); });
it('adds a todo', () => { it('adds a todo', () => {
@@ -92,7 +92,7 @@ describe('shared.ops.addTask', () => {
expect(todo.text).to.equal('todo'); expect(todo.text).to.equal('todo');
expect(todo.checklist).to.eql([]); expect(todo.checklist).to.eql([]);
expect(todo.completed).to.be.false; expect(todo.completed).to.be.false;
expect(todo.up).to.not.exists; expect(todo.up).to.not.exist;
}); });
it('adds a reward', () => { it('adds a reward', () => {
@@ -110,7 +110,7 @@ describe('shared.ops.addTask', () => {
expect(reward.type).to.equal('reward'); expect(reward.type).to.equal('reward');
expect(reward.text).to.equal('reward'); expect(reward.text).to.equal('reward');
expect(reward.value).to.equal(10); expect(reward.value).to.equal(10);
expect(reward.up).to.not.exists; expect(reward.up).to.not.exist;
}); });
context('user preferences', () => { context('user preferences', () => {

View File

@@ -38,19 +38,19 @@ describe('shared.ops.equip', () => {
// one-handed to one-handed // one-handed to one-handed
let [, message] = equip(user, {params: {key: 'weapon_warrior_2'}}); let [, message] = equip(user, {params: {key: 'weapon_warrior_2'}});
expect(message).to.not.exists; expect(message).to.not.exist;
// one-handed to two-handed // one-handed to two-handed
[, message] = equip(user, {params: {key: 'weapon_wizard_1'}}); [, message] = equip(user, {params: {key: 'weapon_wizard_1'}});
expect(message).to.not.exists; expect(message).to.not.exist;
// two-handed to two-handed // two-handed to two-handed
[, message] = equip(user, {params: {key: 'weapon_wizard_2'}}); [, message] = equip(user, {params: {key: 'weapon_wizard_2'}});
expect(message).to.not.exists; expect(message).to.not.exist;
// two-handed to one-handed // two-handed to one-handed
[, message] = equip(user, {params: {key: 'weapon_warrior_2'}}); [, message] = equip(user, {params: {key: 'weapon_warrior_2'}});
expect(message).to.not.exists; expect(message).to.not.exist;
}); });
it('should send messages if equipping a two-hander causes the off-hander to be unequipped', () => { it('should send messages if equipping a two-hander causes the off-hander to be unequipped', () => {

View File

@@ -67,19 +67,19 @@ describe('shared.ops.unlock', () => {
}); });
it('equips an item already owned', () => { it('equips an item already owned', () => {
expect(user.purchased.background.giant_florals).to.not.exists; expect(user.purchased.background.giant_florals).to.not.exist;
unlock(user, {query: {path: backgroundUnlockPath}}); unlock(user, {query: {path: backgroundUnlockPath}});
let afterBalance = user.balance; let afterBalance = user.balance;
let response = unlock(user, {query: {path: backgroundUnlockPath}}); let response = unlock(user, {query: {path: backgroundUnlockPath}});
expect(user.balance).to.equal(afterBalance); // do not bill twice expect(user.balance).to.equal(afterBalance); // do not bill twice
expect(response.message).to.not.exists; expect(response.message).to.not.exist;
expect(user.preferences.background).to.equal('giant_florals'); expect(user.preferences.background).to.equal('giant_florals');
}); });
it('un-equips an item already equipped', () => { it('un-equips an item already equipped', () => {
expect(user.purchased.background.giant_florals).to.not.exists; expect(user.purchased.background.giant_florals).to.not.exist;
unlock(user, {query: {path: backgroundUnlockPath}}); // unlock unlock(user, {query: {path: backgroundUnlockPath}}); // unlock
let afterBalance = user.balance; let afterBalance = user.balance;
@@ -87,7 +87,7 @@ describe('shared.ops.unlock', () => {
let response = unlock(user, {query: {path: backgroundUnlockPath}}); let response = unlock(user, {query: {path: backgroundUnlockPath}});
expect(user.balance).to.equal(afterBalance); // do not bill twice expect(user.balance).to.equal(afterBalance); // do not bill twice
expect(response.message).to.not.exists; expect(response.message).to.not.exist;
expect(user.preferences.background).to.equal(''); expect(user.preferences.background).to.equal('');
}); });

View File

@@ -162,7 +162,7 @@ function _getMembersForItem (type) {
* *
* @apiParam {UUID} groupId The group id * @apiParam {UUID} groupId The group id
* @apiParam {UUID} lastId Query parameter to specify the last member returned in a previous request to this route and get the next batch of results * @apiParam {UUID} lastId Query parameter to specify the last member returned in a previous request to this route and get the next batch of results
* @apiParam {boolean} includeAllPublicFields Query parameter available only when fetching a party. If === `true` then all public fields for members will be returned (liek when making a request for a single member) * @apiParam {boolean} includeAllPublicFields Query parameter available only when fetching a party. If === `true` then all public fields for members will be returned (like when making a request for a single member)
* *
* @apiSuccess {array} data An array of members, sorted by _id * @apiSuccess {array} data An array of members, sorted by _id
*/ */

View File

@@ -8,7 +8,7 @@ require('./methods');
// A list of publicly accessible fields (not everything from preferences because there are also a lot of settings tha should remain private) // A list of publicly accessible fields (not everything from preferences because there are also a lot of settings tha should remain private)
export let publicFields = `preferences.size preferences.hair preferences.skin preferences.shirt export let publicFields = `preferences.size preferences.hair preferences.skin preferences.shirt
preferences.chair preferences.costume preferences.sleep preferences.background profile stats preferences.chair preferences.costume preferences.sleep preferences.background profile stats
achievements party backer contributor auth.timestamps items`; achievements party backer contributor auth.timestamps items inbox.optOut`;
// The minimum amount of data needed when populating multiple users // The minimum amount of data needed when populating multiple users
export let nameFields = 'profile.name'; export let nameFields = 'profile.name';