Mods blocking (#8364)

* updated logic for blocking/unblocking

* updated 1 test and added 2
This commit is contained in:
Myles Louis Dakan
2017-02-06 00:32:10 -05:00
committed by Keith Holliday
parent 07ce68c596
commit dbb1e3aa18
2 changed files with 39 additions and 6 deletions

View File

@@ -40,13 +40,14 @@ describe('PUT /heroes/:heroId', () => {
});
});
it('updates contributor level, balance, ads, blocked', async () => {
it('change contributor level, balance, ads', async () => {
let hero = await generateUser();
let prevBlockState = hero.auth.blocked;
let prevSleepState = hero.preferences.sleep;
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
balance: 3,
contributor: {level: 1},
purchased: {ads: true},
auth: {blocked: true},
});
// test response
@@ -61,18 +62,47 @@ describe('PUT /heroes/:heroId', () => {
expect(heroRes.balance).to.equal(3 + 0.75); // 3+0.75 for first contrib level
expect(heroRes.contributor.level).to.equal(1);
expect(heroRes.purchased.ads).to.equal(true);
expect(heroRes.auth.blocked).to.equal(true);
// test hero values
await hero.sync();
expect(hero.balance).to.equal(3 + 0.75); // 3+0.75 for first contrib level
expect(hero.contributor.level).to.equal(1);
expect(hero.purchased.ads).to.equal(true);
expect(hero.auth.blocked).to.equal(true);
expect(hero.preferences.sleep).to.equal(true);
expect(hero.auth.blocked).to.equal(prevBlockState);
expect(hero.preferences.sleep).to.equal(prevSleepState);
expect(hero.notifications.length).to.equal(1);
expect(hero.notifications[0].type).to.equal('NEW_CONTRIBUTOR_LEVEL');
});
it('block a user', async () => {
let hero = await generateUser();
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
auth: {blocked: true},
preferences: {sleep: true},
});
// test response values
expect(heroRes.auth.blocked).to.equal(true);
// test hero values
await hero.sync();
expect(hero.auth.blocked).to.equal(true);
expect(hero.preferences.sleep).to.equal(true);
});
it('unblock a user', async () => {
let hero = await generateUser();
let prevSleepState = hero.preferences.sleep;
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
auth: {blocked: false},
});
// test response values
expect(heroRes.auth.blocked).to.equal(false);
// test hero values
await hero.sync();
expect(hero.auth.blocked).to.equal(false);
expect(hero.preferences.sleep).to.equal(prevSleepState);
});
it('updates chatRevoked flag', async () => {
let hero = await generateUser();

View File

@@ -177,10 +177,13 @@ api.updateHero = {
_.set(hero, updateData.itemPath, updateData.itemVal); // Sanitization at 5c30944 (deemed unnecessary)
}
if (updateData.auth && _.isBoolean(updateData.auth.blocked)) {
if (updateData.auth && updateData.auth.blocked === true) {
hero.auth.blocked = updateData.auth.blocked;
hero.preferences.sleep = true; // when blocking, have them rest at an inn to prevent damage
}
if (updateData.auth && updateData.auth.blocked === false) {
hero.auth.blocked = false;
}
if (updateData.flags && _.isBoolean(updateData.flags.chatRevoked)) hero.flags.chatRevoked = updateData.flags.chatRevoked;
let savedHero = await hero.save();