diff --git a/test/api/v3/integration/hall/PUT-hall_heores_heroId.test.js b/test/api/v3/integration/hall/PUT-hall_heores_heroId.test.js index 7653d08dbf..edfb9015be 100644 --- a/test/api/v3/integration/hall/PUT-hall_heores_heroId.test.js +++ b/test/api/v3/integration/hall/PUT-hall_heores_heroId.test.js @@ -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(); diff --git a/website/server/controllers/api-v3/hall.js b/website/server/controllers/api-v3/hall.js index b209fa64d2..a42bb6280f 100644 --- a/website/server/controllers/api-v3/hall.js +++ b/website/server/controllers/api-v3/hall.js @@ -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();