mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
* Changed files to fix Bug 7958: - website/client-old/.../userCtrl.js#38: removed to keep inventory constant - website/common/.../changeClass.js#33: removed to stop 'classes' introduction * Adjustments following Bug Review - Removed remaining 'foundKey' logic - Adjusted test logic to reflect feature change * Reverting userCtrl.js to development version - Reintroduces "classes" Guide tour * New version of Fixes #7958 - Changed logic to only notify user the first time they choose a class - Changed message to represent this change in logic - #LINT: Cleaned interface for changing class - New method: enableClasses() -- because, really, should we be calling User.changeClass({}) from the UX? - New method: payForNewClass() -- handles prompting the user to confirm that they want to change class * Remove new User Flag, use flags.tour.classes * Whoopsie. Fix PR conflict. * Changed files to fix Bug 7958: - website/client-old/.../userCtrl.js#38: removed to keep inventory constant - website/common/.../changeClass.js#33: removed to stop 'classes' introduction * Adjustments following Bug Review - Removed remaining 'foundKey' logic - Adjusted test logic to reflect feature change * Reverting userCtrl.js to development version - Reintroduces "classes" Guide tour * New version of Fixes #7958 - Changed logic to only notify user the first time they choose a class - Changed message to represent this change in logic - #LINT: Cleaned interface for changing class - New method: enableClasses() -- because, really, should we be calling User.changeClass({}) from the UX? - New method: payForNewClass() -- handles prompting the user to confirm that they want to change class * Remove new User Flag, use flags.tour.classes * Whoopsie. Fix PR conflict. * Removed Extraneous Flag * Removed Extraneous Flag * Changed files to fix Bug 7958: - website/client-old/.../userCtrl.js#38: removed to keep inventory constant - website/common/.../changeClass.js#33: removed to stop 'classes' introduction * New version of Fixes #7958 - Changed logic to only notify user the first time they choose a class - Changed message to represent this change in logic - #LINT: Cleaned interface for changing class - New method: enableClasses() -- because, really, should we be calling User.changeClass({}) from the UX? - New method: payForNewClass() -- handles prompting the user to confirm that they want to change class Remove new User Flag, use flags.tour.classes Whoopsie. Fix PR conflict. Removed Extraneous Flag * Fixes handling architecture change * Updates following Review 20170418-0602 * Remove cause of mocha/no-exclusive-tests lint failure
154 lines
4.6 KiB
JavaScript
154 lines
4.6 KiB
JavaScript
/* eslint-disable camelcase */
|
|
|
|
import changeClass from '../../../website/common/script/ops/changeClass';
|
|
import {
|
|
NotAuthorized,
|
|
BadRequest,
|
|
} from '../../../website/common/script/libs/errors';
|
|
import i18n from '../../../website/common/script/i18n';
|
|
import {
|
|
generateUser,
|
|
} from '../../helpers/common.helper';
|
|
|
|
describe('shared.ops.changeClass', () => {
|
|
let user;
|
|
|
|
beforeEach(() => {
|
|
user = generateUser();
|
|
user.stats.lvl = 11;
|
|
user.stats.flagSelected = false;
|
|
});
|
|
|
|
it('user is not level 10', (done) => {
|
|
user.stats.lvl = 9;
|
|
try {
|
|
changeClass(user, {query: {class: 'rogue'}});
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
|
expect(err.message).to.equal(i18n.t('lvl10ChangeClass'));
|
|
done();
|
|
}
|
|
});
|
|
|
|
it('req.query.class is an invalid class', (done) => {
|
|
user.flags.classSelected = false;
|
|
user.preferences.disableClasses = false;
|
|
|
|
try {
|
|
changeClass(user, {query: {class: 'cellist'}});
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(BadRequest);
|
|
expect(err.message).to.equal(i18n.t('invalidClass'));
|
|
done();
|
|
}
|
|
});
|
|
|
|
context('req.query.class is a valid class', () => {
|
|
it('errors if user.stats.flagSelected is true and user.balance < 0.75', (done) => {
|
|
user.flags.classSelected = true;
|
|
user.preferences.disableClasses = false;
|
|
user.balance = 0;
|
|
|
|
try {
|
|
changeClass(user, {query: {class: 'rogue'}});
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
|
expect(err.message).to.equal(i18n.t('notEnoughGems'));
|
|
done();
|
|
}
|
|
});
|
|
|
|
it('changes class', () => {
|
|
user.stats.class = 'healer';
|
|
user.items.gear.owned.weapon_healer_3 = true;
|
|
user.items.gear.equipped.weapon = 'weapon_healer_3';
|
|
|
|
let [data] = changeClass(user, {query: {class: 'rogue'}});
|
|
expect(data).to.eql({
|
|
preferences: user.preferences,
|
|
stats: user.stats,
|
|
flags: user.flags,
|
|
items: user.items,
|
|
});
|
|
|
|
expect(user.stats.class).to.equal('rogue');
|
|
expect(user.flags.classSelected).to.be.true;
|
|
expect(user.items.gear.owned.weapon_rogue_0).to.be.true;
|
|
expect(user.items.gear.owned.shield_rogue_0).to.be.true;
|
|
expect(user.items.gear.owned.weapon_healer_3).to.be.true;
|
|
expect(user.items.gear.equipped.weapon).to.equal('weapon_healer_3');
|
|
});
|
|
});
|
|
|
|
context('req.query.class is missing or user.stats.flagSelected is true', () => {
|
|
it('has user.preferences.disableClasses === true', () => {
|
|
user.balance = 1;
|
|
user.preferences.disableClasses = true;
|
|
user.preferences.autoAllocate = true;
|
|
user.stats.points = 45;
|
|
user.stats.str = 1;
|
|
user.stats.con = 2;
|
|
user.stats.per = 3;
|
|
user.stats.int = 4;
|
|
user.flags.classSelected = true;
|
|
|
|
let [data] = changeClass(user);
|
|
expect(data).to.eql({
|
|
preferences: user.preferences,
|
|
stats: user.stats,
|
|
flags: user.flags,
|
|
items: user.items,
|
|
});
|
|
|
|
expect(user.preferences.disableClasses).to.be.false;
|
|
expect(user.preferences.autoAllocate).to.be.false;
|
|
expect(user.balance).to.equal(1);
|
|
expect(user.stats.str).to.equal(0);
|
|
expect(user.stats.con).to.equal(0);
|
|
expect(user.stats.per).to.equal(0);
|
|
expect(user.stats.int).to.equal(0);
|
|
expect(user.stats.points).to.equal(11);
|
|
expect(user.flags.classSelected).to.equal(false);
|
|
});
|
|
|
|
context('has user.preferences.disableClasses !== true', () => {
|
|
it('and less than 3 gems', (done) => {
|
|
user.balance = 0.5;
|
|
try {
|
|
changeClass(user);
|
|
} catch (err) {
|
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
|
expect(err.message).to.equal(i18n.t('notEnoughGems'));
|
|
done();
|
|
}
|
|
});
|
|
|
|
it('and at least 3 gems', () => {
|
|
user.balance = 1;
|
|
user.stats.points = 45;
|
|
user.stats.str = 1;
|
|
user.stats.con = 2;
|
|
user.stats.per = 3;
|
|
user.stats.int = 4;
|
|
user.flags.classSelected = true;
|
|
|
|
let [data] = changeClass(user);
|
|
expect(data).to.eql({
|
|
preferences: user.preferences,
|
|
stats: user.stats,
|
|
flags: user.flags,
|
|
items: user.items,
|
|
});
|
|
|
|
expect(user.balance).to.equal(0.25);
|
|
expect(user.stats.str).to.equal(0);
|
|
expect(user.stats.con).to.equal(0);
|
|
expect(user.stats.per).to.equal(0);
|
|
expect(user.stats.int).to.equal(0);
|
|
expect(user.stats.points).to.equal(11);
|
|
expect(user.flags.classSelected).to.equal(false);
|
|
});
|
|
});
|
|
});
|
|
});
|