mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
port shared.ops.allocate
This commit is contained in:
59
test/common/ops/allocate.js
Normal file
59
test/common/ops/allocate.js
Normal file
@@ -0,0 +1,59 @@
|
||||
import allocate from '../../../common/script/ops/allocate';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
|
||||
describe('shared.ops.allocate', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser();
|
||||
});
|
||||
|
||||
it('throws an error if an invalid attribute is supplied', () => {
|
||||
try {
|
||||
expect(allocate(user, {
|
||||
query: {stat: 'notValid'},
|
||||
})).to.throw(BadRequest);
|
||||
} catch (err) {
|
||||
expect(err.message).to.equal(i18n.t('invalidAttribute', {attr: 'notValid'}));
|
||||
}
|
||||
});
|
||||
|
||||
it('throws an error if the user doesn\'t have attribute points', () => {
|
||||
try {
|
||||
expect(allocate(user)).to.throw(NotAuthorized);
|
||||
} catch (err) {
|
||||
expect(err.message).to.equal(i18n.t('notEnoughAttrPoints'));
|
||||
}
|
||||
});
|
||||
|
||||
it('defaults to the "str" attribute', () => {
|
||||
expect(user.stats.str).to.equal(0);
|
||||
user.stats.points = 1;
|
||||
allocate(user);
|
||||
expect(user.stats.str).to.equal(1);
|
||||
});
|
||||
|
||||
it('allocates attribute points', () => {
|
||||
expect(user.stats.con).to.equal(0);
|
||||
user.stats.points = 1;
|
||||
allocate(user, {query: {stat: 'con'}});
|
||||
expect(user.stats.con).to.equal(1);
|
||||
expect(user.stats.points).to.equal(0);
|
||||
});
|
||||
|
||||
it('increases mana when allocating to "int"', () => {
|
||||
expect(user.stats.int).to.equal(0);
|
||||
expect(user.stats.mp).to.equal(10);
|
||||
user.stats.points = 1;
|
||||
allocate(user, {query: {stat: 'int'}});
|
||||
expect(user.stats.int).to.equal(1);
|
||||
expect(user.stats.mp).to.equal(11);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user