mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Ported unlock. Add unit tests. Create unlock route. Add integration tests
This commit is contained in:
37
test/api/v3/integration/user/POST-user_unlock.js
Normal file
37
test/api/v3/integration/user/POST-user_unlock.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('POST /user/unlock', () => {
|
||||
let user;
|
||||
let unlockPath = 'shirt.convict,shirt.cross,shirt.fire,shirt.horizon,shirt.ocean,shirt.purple,shirt.rainbow,shirt.redblue,shirt.thunder,shirt.tropical,shirt.zombie';
|
||||
let unlockCost = 1.25;
|
||||
let usersStartingGems = 5;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('returns an error when user balance is too low', async () => {
|
||||
await expect(user.post(`/user/unlock?path=${unlockPath}`))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('notEnoughGems'),
|
||||
});
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('reduces a user\'s balance', async () => {
|
||||
await user.update({
|
||||
balance: usersStartingGems,
|
||||
});
|
||||
let response = await user.post(`/user/unlock?path=${unlockPath}`);
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('unlocked'));
|
||||
expect(user.balance).to.equal(usersStartingGems - unlockCost);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user