mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Mods blocking (#8364)
* updated logic for blocking/unblocking * updated 1 test and added 2
This commit is contained in:
committed by
Keith Holliday
parent
07ce68c596
commit
dbb1e3aa18
@@ -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 hero = await generateUser();
|
||||||
|
let prevBlockState = hero.auth.blocked;
|
||||||
|
let prevSleepState = hero.preferences.sleep;
|
||||||
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
let heroRes = await user.put(`/hall/heroes/${hero._id}`, {
|
||||||
balance: 3,
|
balance: 3,
|
||||||
contributor: {level: 1},
|
contributor: {level: 1},
|
||||||
purchased: {ads: true},
|
purchased: {ads: true},
|
||||||
auth: {blocked: true},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// test response
|
// 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.balance).to.equal(3 + 0.75); // 3+0.75 for first contrib level
|
||||||
expect(heroRes.contributor.level).to.equal(1);
|
expect(heroRes.contributor.level).to.equal(1);
|
||||||
expect(heroRes.purchased.ads).to.equal(true);
|
expect(heroRes.purchased.ads).to.equal(true);
|
||||||
expect(heroRes.auth.blocked).to.equal(true);
|
|
||||||
// test hero values
|
// test hero values
|
||||||
await hero.sync();
|
await hero.sync();
|
||||||
expect(hero.balance).to.equal(3 + 0.75); // 3+0.75 for first contrib level
|
expect(hero.balance).to.equal(3 + 0.75); // 3+0.75 for first contrib level
|
||||||
expect(hero.contributor.level).to.equal(1);
|
expect(hero.contributor.level).to.equal(1);
|
||||||
expect(hero.purchased.ads).to.equal(true);
|
expect(hero.purchased.ads).to.equal(true);
|
||||||
expect(hero.auth.blocked).to.equal(true);
|
expect(hero.auth.blocked).to.equal(prevBlockState);
|
||||||
expect(hero.preferences.sleep).to.equal(true);
|
expect(hero.preferences.sleep).to.equal(prevSleepState);
|
||||||
expect(hero.notifications.length).to.equal(1);
|
expect(hero.notifications.length).to.equal(1);
|
||||||
expect(hero.notifications[0].type).to.equal('NEW_CONTRIBUTOR_LEVEL');
|
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 () => {
|
it('updates chatRevoked flag', async () => {
|
||||||
let hero = await generateUser();
|
let hero = await generateUser();
|
||||||
|
|
||||||
|
|||||||
@@ -177,10 +177,13 @@ api.updateHero = {
|
|||||||
_.set(hero, updateData.itemPath, updateData.itemVal); // Sanitization at 5c30944 (deemed unnecessary)
|
_.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.auth.blocked = updateData.auth.blocked;
|
||||||
hero.preferences.sleep = true; // when blocking, have them rest at an inn to prevent damage
|
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;
|
if (updateData.flags && _.isBoolean(updateData.flags.chatRevoked)) hero.flags.chatRevoked = updateData.flags.chatRevoked;
|
||||||
|
|
||||||
let savedHero = await hero.save();
|
let savedHero = await hero.save();
|
||||||
|
|||||||
Reference in New Issue
Block a user