mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
fix test lint
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
find,
|
||||
each,
|
||||
map,
|
||||
} from 'lodash';
|
||||
import {
|
||||
checkExistence,
|
||||
createAndPopulateGroup,
|
||||
@@ -6,11 +11,6 @@ import {
|
||||
generateChallenge,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import {
|
||||
find,
|
||||
each,
|
||||
map,
|
||||
} from 'lodash';
|
||||
import {
|
||||
sha1MakeSalt,
|
||||
sha1Encrypt as sha1EncryptPassword,
|
||||
@@ -21,11 +21,11 @@ const DELETE_CONFIRMATION = 'DELETE';
|
||||
|
||||
describe('DELETE /user', () => {
|
||||
let user;
|
||||
let password = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
|
||||
const password = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
|
||||
|
||||
context('user with local auth', async () => {
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({balance: 10});
|
||||
user = await generateUser({ balance: 10 });
|
||||
});
|
||||
|
||||
it('returns an error if password is wrong', async () => {
|
||||
@@ -56,10 +56,10 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
it('returns an error if excessive feedback is supplied', async () => {
|
||||
let feedbackText = 'spam feedback ';
|
||||
const feedbackText = 'spam feedback ';
|
||||
let feedback = feedbackText;
|
||||
while (feedback.length < 10000) {
|
||||
feedback = feedback + feedbackText;
|
||||
feedback += feedbackText;
|
||||
}
|
||||
|
||||
await expect(user.del('/user', {
|
||||
@@ -73,7 +73,7 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
it('returns an error if user has active subscription', async () => {
|
||||
let userWithSubscription = await generateUser({'purchased.plan.customerId': 'fake-customer-id'});
|
||||
const userWithSubscription = await generateUser({ 'purchased.plan.customerId': 'fake-customer-id' });
|
||||
|
||||
await expect(userWithSubscription.del('/user', {
|
||||
password,
|
||||
@@ -92,8 +92,8 @@ describe('DELETE /user', () => {
|
||||
await user.sync();
|
||||
|
||||
// gets the user's tasks ids
|
||||
let ids = [];
|
||||
each(user.tasksOrder, (idsForOrder) => {
|
||||
const ids = [];
|
||||
each(user.tasksOrder, idsForOrder => {
|
||||
ids.push(...idsForOrder);
|
||||
});
|
||||
|
||||
@@ -103,20 +103,18 @@ describe('DELETE /user', () => {
|
||||
password,
|
||||
});
|
||||
|
||||
await Promise.all(map(ids, id => {
|
||||
return expect(checkExistence('tasks', id)).to.eventually.eql(false);
|
||||
}));
|
||||
await Promise.all(map(ids, id => expect(checkExistence('tasks', id)).to.eventually.eql(false)));
|
||||
});
|
||||
|
||||
it('reduces memberCount in challenges user is linked to', async () => {
|
||||
let populatedGroup = await createAndPopulateGroup({
|
||||
const populatedGroup = await createAndPopulateGroup({
|
||||
members: 2,
|
||||
});
|
||||
|
||||
let group = populatedGroup.group;
|
||||
let authorizedUser = populatedGroup.members[1];
|
||||
const { group } = populatedGroup;
|
||||
const authorizedUser = populatedGroup.members[1];
|
||||
|
||||
let challenge = await generateChallenge(populatedGroup.groupLeader, group);
|
||||
const challenge = await generateChallenge(populatedGroup.groupLeader, group);
|
||||
await populatedGroup.groupLeader.post(`/challenges/${challenge._id}/join`);
|
||||
await authorizedUser.post(`/challenges/${challenge._id}/join`);
|
||||
|
||||
@@ -136,7 +134,7 @@ describe('DELETE /user', () => {
|
||||
it('sends feedback to the admin email', async () => {
|
||||
sandbox.spy(email, 'sendTxn');
|
||||
|
||||
let feedback = 'Reasons for Deletion';
|
||||
const feedback = 'Reasons for Deletion';
|
||||
await user.del('/user', {
|
||||
password,
|
||||
feedback,
|
||||
@@ -160,9 +158,9 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
it('deletes the user with a legacy sha1 password', async () => {
|
||||
let textPassword = 'mySecretPassword';
|
||||
let salt = sha1MakeSalt();
|
||||
let sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
const textPassword = 'mySecretPassword';
|
||||
const salt = sha1MakeSalt();
|
||||
const sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
|
||||
await user.update({
|
||||
'auth.local.hashed_password': sha1HashedPassword,
|
||||
@@ -220,10 +218,11 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
context('groups user is leader of', () => {
|
||||
let guild, oldLeader, newLeader;
|
||||
let guild; let oldLeader; let
|
||||
newLeader;
|
||||
|
||||
beforeEach(async () => {
|
||||
let { group, groupLeader, members } = await createAndPopulateGroup({
|
||||
const { group, groupLeader, members } = await createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
@@ -232,7 +231,7 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
guild = group;
|
||||
newLeader = members[0];
|
||||
newLeader = members[0]; // eslint-disable-line prefer-destructuring
|
||||
oldLeader = groupLeader;
|
||||
});
|
||||
|
||||
@@ -241,7 +240,7 @@ describe('DELETE /user', () => {
|
||||
password,
|
||||
});
|
||||
|
||||
let updatedGuild = await newLeader.get(`/groups/${guild._id}`);
|
||||
const updatedGuild = await newLeader.get(`/groups/${guild._id}`);
|
||||
|
||||
expect(updatedGuild.leader).to.exist;
|
||||
expect(updatedGuild.leader._id).to.not.eql(oldLeader._id);
|
||||
@@ -249,17 +248,18 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
context('groups user is a part of', () => {
|
||||
let group1, group2, userToDelete, otherUser;
|
||||
let group1; let group2; let userToDelete; let
|
||||
otherUser;
|
||||
|
||||
beforeEach(async () => {
|
||||
userToDelete = await generateUser({balance: 10});
|
||||
userToDelete = await generateUser({ balance: 10 });
|
||||
|
||||
group1 = await generateGroup(userToDelete, {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
});
|
||||
|
||||
let {group, members} = await createAndPopulateGroup({
|
||||
const { group, members } = await createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
@@ -268,7 +268,7 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
group2 = group;
|
||||
otherUser = members[0];
|
||||
otherUser = members[0]; // eslint-disable-line prefer-destructuring
|
||||
|
||||
await userToDelete.post(`/groups/${group2._id}/join`);
|
||||
});
|
||||
@@ -278,11 +278,9 @@ describe('DELETE /user', () => {
|
||||
password,
|
||||
});
|
||||
|
||||
let updatedGroup1Members = await otherUser.get(`/groups/${group1._id}/members`);
|
||||
let updatedGroup2Members = await otherUser.get(`/groups/${group2._id}/members`);
|
||||
let userInGroup = find(updatedGroup2Members, (member) => {
|
||||
return member._id === userToDelete._id;
|
||||
});
|
||||
const updatedGroup1Members = await otherUser.get(`/groups/${group1._id}/members`);
|
||||
const updatedGroup2Members = await otherUser.get(`/groups/${group2._id}/members`);
|
||||
const userInGroup = find(updatedGroup2Members, member => member._id === userToDelete._id);
|
||||
|
||||
expect(updatedGroup1Members).to.be.empty;
|
||||
expect(updatedGroup2Members).to.not.be.empty;
|
||||
@@ -308,7 +306,7 @@ describe('DELETE /user', () => {
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('incorrectDeletePhrase', {magicWord: 'DELETE'}),
|
||||
message: t('incorrectDeletePhrase', { magicWord: 'DELETE' }),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ import {
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('DELETE user message', () => {
|
||||
let user, messagesId, otherUser;
|
||||
let user; let messagesId; let
|
||||
otherUser;
|
||||
|
||||
before(async () => {
|
||||
[user, otherUser] = await Promise.all([generateUser(), generateUser()]);
|
||||
@@ -16,7 +17,7 @@ describe('DELETE user message', () => {
|
||||
message: 'second',
|
||||
});
|
||||
|
||||
let userRes = await user.get('/user');
|
||||
const userRes = await user.get('/user');
|
||||
|
||||
messagesId = Object.keys(userRes.inbox.messages);
|
||||
expect(messagesId.length).to.eql(2);
|
||||
@@ -25,18 +26,18 @@ describe('DELETE user message', () => {
|
||||
});
|
||||
|
||||
it('one message', async () => {
|
||||
let result = await user.del(`/user/messages/${messagesId[0]}`);
|
||||
const result = await user.del(`/user/messages/${messagesId[0]}`);
|
||||
messagesId = Object.keys(result);
|
||||
expect(messagesId.length).to.eql(1);
|
||||
|
||||
let userRes = await user.get('/user');
|
||||
const userRes = await user.get('/user');
|
||||
expect(Object.keys(userRes.inbox.messages).length).to.eql(1);
|
||||
expect(userRes.inbox.messages[messagesId[0]].text).to.eql('first');
|
||||
});
|
||||
|
||||
it('clear all', async () => {
|
||||
let result = await user.del('/user/messages');
|
||||
let userRes = await user.get('/user');
|
||||
const result = await user.del('/user/messages');
|
||||
const userRes = await user.get('/user');
|
||||
expect(userRes.inbox.messages).to.eql({});
|
||||
expect(result).to.eql({});
|
||||
});
|
||||
|
||||
@@ -5,8 +5,8 @@ import {
|
||||
|
||||
describe('DELETE /user/push-devices', () => {
|
||||
let user;
|
||||
let regId = '10';
|
||||
let type = 'ios';
|
||||
const regId = '10';
|
||||
const type = 'ios';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
@@ -22,8 +22,8 @@ describe('DELETE /user/push-devices', () => {
|
||||
});
|
||||
|
||||
it('removes a push device from the user', async () => {
|
||||
await user.post('/user/push-devices', {type, regId});
|
||||
let response = await user.del(`/user/push-devices/${regId}`);
|
||||
await user.post('/user/push-devices', { type, regId });
|
||||
const response = await user.del(`/user/push-devices/${regId}`);
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('pushDeviceRemoved'));
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('GET /user', () => {
|
||||
});
|
||||
|
||||
it('returns the authenticated user with computed stats', async () => {
|
||||
let returnedUser = await user.get('/user');
|
||||
const returnedUser = await user.get('/user');
|
||||
expect(returnedUser._id).to.equal(user._id);
|
||||
|
||||
expect(returnedUser.stats.maxMP).to.exist;
|
||||
@@ -20,7 +20,7 @@ describe('GET /user', () => {
|
||||
});
|
||||
|
||||
it('does not return private paths (and apiToken)', async () => {
|
||||
let returnedUser = await user.get('/user');
|
||||
const returnedUser = await user.get('/user');
|
||||
|
||||
expect(returnedUser.auth.local.hashed_password).to.not.exist;
|
||||
expect(returnedUser.auth.local.passwordHashMethod).to.not.exist;
|
||||
@@ -29,7 +29,7 @@ describe('GET /user', () => {
|
||||
});
|
||||
|
||||
it('returns only user properties requested', async () => {
|
||||
let returnedUser = await user.get('/user?userFields=achievements,items.mounts');
|
||||
const returnedUser = await user.get('/user?userFields=achievements,items.mounts');
|
||||
|
||||
expect(returnedUser._id).to.equal(user._id);
|
||||
expect(returnedUser.achievements).to.exist;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
import {
|
||||
generateUser,
|
||||
generateHabit,
|
||||
@@ -5,11 +6,10 @@ import {
|
||||
generateReward,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import common from '../../../../../website/common';
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
|
||||
describe('GET /user/anonymized', () => {
|
||||
let user;
|
||||
let endpoint = '/user/anonymized';
|
||||
const endpoint = '/user/anonymized';
|
||||
|
||||
before(async () => {
|
||||
user = await generateUser();
|
||||
@@ -26,7 +26,7 @@ describe('GET /user/anonymized', () => {
|
||||
},
|
||||
'items.special.nyeReceived': 'some',
|
||||
'items.special.valentineReceived': 'some',
|
||||
webhooks: [{url: 'https://somurl.com'}],
|
||||
webhooks: [{ url: 'https://somurl.com' }],
|
||||
'achievements.challenges': 'some',
|
||||
'inbox.messages': [{ text: 'some text' }],
|
||||
tags: [{ name: 'some name', challenge: 'some challenge' }],
|
||||
@@ -35,7 +35,7 @@ describe('GET /user/anonymized', () => {
|
||||
|
||||
await generateHabit({ userId: user._id });
|
||||
await generateHabit({ userId: user._id, text: generateUUID() });
|
||||
let daily = await generateDaily({ userId: user._id, checklist: [{ completed: false, text: 'this-text' }] });
|
||||
const daily = await generateDaily({ userId: user._id, checklist: [{ completed: false, text: 'this-text' }] });
|
||||
expect(daily.checklist[0].text.substr(0, 5)).to.not.eql('item ');
|
||||
await generateReward({ userId: user._id, text: 'some text 4' });
|
||||
|
||||
@@ -63,7 +63,7 @@ describe('GET /user/anonymized', () => {
|
||||
|
||||
it('does not return private paths (and apiToken)', async () => {
|
||||
let returnedUser = await user.get(endpoint);
|
||||
let tasks2 = returnedUser.tasks;
|
||||
const tasks2 = returnedUser.tasks;
|
||||
returnedUser = returnedUser.user;
|
||||
expect(returnedUser.auth.local).to.not.exist;
|
||||
expect(returnedUser.apiToken).to.not.exist;
|
||||
@@ -80,10 +80,10 @@ describe('GET /user/anonymized', () => {
|
||||
expect(returnedUser.items.special.valentineReceived).to.not.exist;
|
||||
expect(returnedUser.webhooks).to.not.exist;
|
||||
expect(returnedUser.achievements.challenges).to.not.exist;
|
||||
_.forEach(returnedUser.inbox.messages, (msg) => {
|
||||
_.forEach(returnedUser.inbox.messages, msg => {
|
||||
expect(msg.text).to.eql('inbox message text');
|
||||
});
|
||||
_.forEach(returnedUser.tags, (tag) => {
|
||||
_.forEach(returnedUser.tags, tag => {
|
||||
expect(tag.name).to.eql('tag');
|
||||
expect(tag.challenge).to.eql('challenge');
|
||||
});
|
||||
@@ -91,11 +91,11 @@ describe('GET /user/anonymized', () => {
|
||||
expect(tasks2).to.exist;
|
||||
expect(tasks2.length).to.eql(5);
|
||||
expect(tasks2[0].checklist).to.exist;
|
||||
_.forEach(tasks2, (task) => {
|
||||
_.forEach(tasks2, task => {
|
||||
expect(task.text).to.eql('task text');
|
||||
expect(task.notes).to.eql('task notes');
|
||||
if (task.checklist) {
|
||||
_.forEach(task.checklist, (c) => {
|
||||
_.forEach(task.checklist, c => {
|
||||
expect(c.text.substr(0, 5)).to.eql('item ');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,14 +11,10 @@ describe('GET /user/in-app-rewards', () => {
|
||||
});
|
||||
|
||||
it('returns the reward items available for purchase', async () => {
|
||||
let buyList = await user.get('/user/in-app-rewards');
|
||||
const buyList = await user.get('/user/in-app-rewards');
|
||||
|
||||
expect(_.find(buyList, item => {
|
||||
return item.text === t('armorWarrior1Text');
|
||||
})).to.exist;
|
||||
expect(_.find(buyList, item => item.text === t('armorWarrior1Text'))).to.exist;
|
||||
|
||||
expect(_.find(buyList, item => {
|
||||
return item.text === t('armorWarrior2Text');
|
||||
})).to.not.exist;
|
||||
expect(_.find(buyList, item => item.text === t('armorWarrior2Text'))).to.not.exist;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,14 +13,10 @@ describe('GET /user/inventory/buy', () => {
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('returns the gear items available for purchase', async () => {
|
||||
let buyList = await user.get('/user/inventory/buy');
|
||||
const buyList = await user.get('/user/inventory/buy');
|
||||
|
||||
expect(_.find(buyList, item => {
|
||||
return item.text === t('armorWarrior1Text');
|
||||
})).to.exist;
|
||||
expect(_.find(buyList, item => item.text === t('armorWarrior1Text'))).to.exist;
|
||||
|
||||
expect(_.find(buyList, item => {
|
||||
return item.text === t('armorWarrior2Text');
|
||||
})).to.not.exist;
|
||||
expect(_.find(buyList, item => item.text === t('armorWarrior2Text'))).to.not.exist;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ describe('GET /user/toggle-pinned-item', () => {
|
||||
});
|
||||
|
||||
it('can pin shield_rogue_5', async () => {
|
||||
let result = await user.get('/user/toggle-pinned-item/marketGear/gear.flat.shield_rogue_5');
|
||||
const result = await user.get('/user/toggle-pinned-item/marketGear/gear.flat.shield_rogue_5');
|
||||
|
||||
expect(result.pinnedItems.length).to.be.eql(user.pinnedItems.length + 1);
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
generateUser,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
import getOfficialPinnedItems from '../../../../../website/common/script/libs/getOfficialPinnedItems.js';
|
||||
import getOfficialPinnedItems from '../../../../../website/common/script/libs/getOfficialPinnedItems';
|
||||
|
||||
describe('POST /user/move-pinned-item/:path/move/to/:position', () => {
|
||||
let user;
|
||||
@@ -14,14 +14,15 @@ describe('POST /user/move-pinned-item/:path/move/to/:position', () => {
|
||||
officialPinnedItems = getOfficialPinnedItems(user);
|
||||
|
||||
officialPinnedItemPaths = [];
|
||||
// officialPinnedItems are returned in { type: ..., path:... } format but we just need the paths for testPinnedItemsOrder
|
||||
// officialPinnedItems are returned in { type: ..., path:... } format
|
||||
// but we just need the paths for testPinnedItemsOrder
|
||||
if (officialPinnedItems.length > 0) {
|
||||
officialPinnedItemPaths = officialPinnedItems.map(item => item.path);
|
||||
}
|
||||
});
|
||||
|
||||
it('adjusts the order of pinned items with no order mismatch', async () => {
|
||||
let testPinnedItems = [
|
||||
const testPinnedItems = [
|
||||
{ type: 'armoire', path: 'armoire' },
|
||||
{ type: 'potion', path: 'potion' },
|
||||
{ type: 'marketGear', path: 'gear.flat.weapon_warrior_1' },
|
||||
@@ -56,7 +57,7 @@ describe('POST /user/move-pinned-item/:path/move/to/:position', () => {
|
||||
pinnedItemsOrder: testPinnedItemsOrder,
|
||||
});
|
||||
|
||||
let res = await user.post('/user/move-pinned-item/armoire/move/to/5');
|
||||
const res = await user.post('/user/move-pinned-item/armoire/move/to/5');
|
||||
await user.sync();
|
||||
|
||||
expect(user.pinnedItemsOrder[5]).to.equal('armoire');
|
||||
@@ -83,14 +84,14 @@ describe('POST /user/move-pinned-item/:path/move/to/:position', () => {
|
||||
});
|
||||
|
||||
it('adjusts the order of pinned items with order mismatch', async () => {
|
||||
let testPinnedItems = [
|
||||
const testPinnedItems = [
|
||||
{ type: 'card', path: 'cardTypes.thankyou' },
|
||||
{ type: 'card', path: 'cardTypes.greeting' },
|
||||
{ type: 'potion', path: 'potion' },
|
||||
{ type: 'armoire', path: 'armoire' },
|
||||
];
|
||||
|
||||
let testPinnedItemsOrder = [
|
||||
const testPinnedItemsOrder = [
|
||||
'armoire',
|
||||
'potion',
|
||||
];
|
||||
@@ -100,7 +101,7 @@ describe('POST /user/move-pinned-item/:path/move/to/:position', () => {
|
||||
pinnedItemsOrder: testPinnedItemsOrder,
|
||||
});
|
||||
|
||||
let res = await user.post('/user/move-pinned-item/armoire/move/to/1');
|
||||
const res = await user.post('/user/move-pinned-item/armoire/move/to/1');
|
||||
await user.sync();
|
||||
|
||||
// The basic test
|
||||
@@ -115,7 +116,8 @@ describe('POST /user/move-pinned-item/:path/move/to/:position', () => {
|
||||
'cardTypes.greeting',
|
||||
'potion',
|
||||
];
|
||||
// inAppRewards is used here and will by default put these seasonal items in the front like this:
|
||||
// inAppRewards is used here and will by default
|
||||
// put these seasonal items in the front like this:
|
||||
expectedResponse = officialPinnedItemPaths.concat(expectedResponse);
|
||||
// now put "armoire" in where we moved it:
|
||||
expectedResponse.splice(1, 0, 'armoire');
|
||||
@@ -124,12 +126,12 @@ describe('POST /user/move-pinned-item/:path/move/to/:position', () => {
|
||||
});
|
||||
|
||||
it('cannot move pinned item that you do not have pinned', async () => {
|
||||
let testPinnedItems = [
|
||||
const testPinnedItems = [
|
||||
{ type: 'potion', path: 'potion' },
|
||||
{ type: 'armoire', path: 'armoire' },
|
||||
];
|
||||
|
||||
let testPinnedItemsOrder = [
|
||||
const testPinnedItemsOrder = [
|
||||
'armoire',
|
||||
'potion',
|
||||
];
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('block user', () => {
|
||||
});
|
||||
|
||||
it('successfully', async () => {
|
||||
let response = await user.post(`/user/block/${blockedUser2._id}`);
|
||||
const response = await user.post(`/user/block/${blockedUser2._id}`);
|
||||
await user.sync();
|
||||
expect(response).to.eql([blockedUser._id, blockedUser2._id]);
|
||||
expect(user.inbox.blocks.length).to.eql(2);
|
||||
|
||||
@@ -15,7 +15,7 @@ describe('POST /user/change-class', () => {
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('changes class', async () => {
|
||||
let res = await user.post('/user/change-class?class=rogue');
|
||||
const res = await user.post('/user/change-class?class=rogue');
|
||||
await user.sync();
|
||||
|
||||
expect(res).to.eql(JSON.parse(
|
||||
@@ -24,7 +24,7 @@ describe('POST /user/change-class', () => {
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
})
|
||||
}),
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
import { find } from 'lodash';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
@@ -6,9 +9,6 @@ import {
|
||||
generateChallenge,
|
||||
sleep,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
import { find } from 'lodash';
|
||||
import apiError from '../../../../../website/server/libs/apiError';
|
||||
|
||||
describe('POST /user/class/cast/:spellId', () => {
|
||||
@@ -19,28 +19,28 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('returns an error if spell does not exist', async () => {
|
||||
await user.update({'stats.class': 'rogue'});
|
||||
let spellId = 'invalidSpell';
|
||||
await user.update({ 'stats.class': 'rogue' });
|
||||
const spellId = 'invalidSpell';
|
||||
await expect(user.post(`/user/class/cast/${spellId}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: apiError('spellNotFound', {spellId}),
|
||||
message: apiError('spellNotFound', { spellId }),
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if spell does not exist in user\'s class', async () => {
|
||||
let spellId = 'pickPocket';
|
||||
const spellId = 'pickPocket';
|
||||
await expect(user.post(`/user/class/cast/${spellId}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: apiError('spellNotFound', {spellId}),
|
||||
message: apiError('spellNotFound', { spellId }),
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if spell.mana > user.mana', async () => {
|
||||
await user.update({'stats.class': 'rogue'});
|
||||
await user.update({ 'stats.class': 'rogue' });
|
||||
await expect(user.post('/user/class/cast/backStab'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
@@ -74,12 +74,12 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('returns an error if spell.lvl > user.level', async () => {
|
||||
await user.update({'stats.mp': 200, 'stats.class': 'wizard'});
|
||||
await user.update({ 'stats.mp': 200, 'stats.class': 'wizard' });
|
||||
await expect(user.post('/user/class/cast/earth'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('spellLevelTooHigh', {level: 13}),
|
||||
message: t('spellLevelTooHigh', { level: 13 }),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -102,7 +102,7 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('returns an error if targetId is required but missing', async () => {
|
||||
await user.update({'stats.class': 'rogue', 'stats.lvl': 11});
|
||||
await user.update({ 'stats.class': 'rogue', 'stats.lvl': 11 });
|
||||
await expect(user.post('/user/class/cast/pickPocket'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
@@ -112,7 +112,7 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('returns an error if targeted task doesn\'t exist', async () => {
|
||||
await user.update({'stats.class': 'rogue', 'stats.lvl': 11});
|
||||
await user.update({ 'stats.class': 'rogue', 'stats.lvl': 11 });
|
||||
await expect(user.post(`/user/class/cast/pickPocket?targetId=${generateUUID()}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
@@ -122,13 +122,13 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('returns an error if a challenge task was targeted', async () => {
|
||||
let {group, groupLeader} = await createAndPopulateGroup();
|
||||
let challenge = await generateChallenge(groupLeader, group);
|
||||
const { group, groupLeader } = await createAndPopulateGroup();
|
||||
const challenge = await generateChallenge(groupLeader, group);
|
||||
await groupLeader.post(`/challenges/${challenge._id}/join`);
|
||||
await groupLeader.post(`/tasks/challenge/${challenge._id}`, [
|
||||
{type: 'habit', text: 'task text'},
|
||||
{ type: 'habit', text: 'task text' },
|
||||
]);
|
||||
await groupLeader.update({'stats.class': 'rogue', 'stats.lvl': 11});
|
||||
await groupLeader.update({ 'stats.class': 'rogue', 'stats.lvl': 11 });
|
||||
await sleep(0.5);
|
||||
await groupLeader.sync();
|
||||
await expect(groupLeader.post(`/user/class/cast/pickPocket?targetId=${groupLeader.tasksOrder.habits[0]}`))
|
||||
@@ -140,19 +140,17 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('returns an error if a group task was targeted', async () => {
|
||||
let {group, groupLeader} = await createAndPopulateGroup();
|
||||
const { group, groupLeader } = await createAndPopulateGroup();
|
||||
|
||||
let groupTask = await groupLeader.post(`/tasks/group/${group._id}`, {
|
||||
const groupTask = await groupLeader.post(`/tasks/group/${group._id}`, {
|
||||
text: 'todo group',
|
||||
type: 'todo',
|
||||
});
|
||||
await groupLeader.post(`/tasks/${groupTask._id}/assign/${groupLeader._id}`);
|
||||
let memberTasks = await groupLeader.get('/tasks/user');
|
||||
let syncedGroupTask = find(memberTasks, function findAssignedTask (memberTask) {
|
||||
return memberTask.group.id === group._id;
|
||||
});
|
||||
const memberTasks = await groupLeader.get('/tasks/user');
|
||||
const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === group._id);
|
||||
|
||||
await groupLeader.update({'stats.class': 'rogue', 'stats.lvl': 11});
|
||||
await groupLeader.update({ 'stats.class': 'rogue', 'stats.lvl': 11 });
|
||||
await sleep(0.5);
|
||||
await groupLeader.sync();
|
||||
|
||||
@@ -165,23 +163,23 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('returns an error if targeted party member doesn\'t exist', async () => {
|
||||
let {groupLeader} = await createAndPopulateGroup({
|
||||
const { groupLeader } = await createAndPopulateGroup({
|
||||
groupDetails: { type: 'party', privacy: 'private' },
|
||||
members: 1,
|
||||
});
|
||||
await groupLeader.update({'items.special.snowball': 3});
|
||||
await groupLeader.update({ 'items.special.snowball': 3 });
|
||||
|
||||
let target = generateUUID();
|
||||
const target = generateUUID();
|
||||
await expect(groupLeader.post(`/user/class/cast/snowball?targetId=${target}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('userWithIDNotFound', {userId: target}),
|
||||
message: t('userWithIDNotFound', { userId: target }),
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if party does not exists', async () => {
|
||||
await user.update({'items.special.snowball': 3});
|
||||
await user.update({ 'items.special.snowball': 3 });
|
||||
|
||||
await expect(user.post(`/user/class/cast/snowball?targetId=${generateUUID()}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
@@ -192,11 +190,11 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('send message in party chat if party && !spell.silent', async () => {
|
||||
let { group, groupLeader } = await createAndPopulateGroup({
|
||||
const { group, groupLeader } = await createAndPopulateGroup({
|
||||
groupDetails: { type: 'party', privacy: 'private' },
|
||||
members: 1,
|
||||
});
|
||||
await groupLeader.update({'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 13});
|
||||
await groupLeader.update({ 'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 13 });
|
||||
|
||||
await groupLeader.post('/user/class/cast/earth');
|
||||
await sleep(1);
|
||||
@@ -207,17 +205,17 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('Ethereal Surge does not recover mp of other mages', async () => {
|
||||
let group = await createAndPopulateGroup({
|
||||
const group = await createAndPopulateGroup({
|
||||
groupDetails: { type: 'party', privacy: 'private' },
|
||||
members: 4,
|
||||
});
|
||||
|
||||
let promises = [];
|
||||
promises.push(group.groupLeader.update({'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 20}));
|
||||
promises.push(group.members[0].update({'stats.mp': 0, 'stats.class': 'warrior', 'stats.lvl': 20}));
|
||||
promises.push(group.members[1].update({'stats.mp': 0, 'stats.class': 'wizard', 'stats.lvl': 20}));
|
||||
promises.push(group.members[2].update({'stats.mp': 0, 'stats.class': 'rogue', 'stats.lvl': 20}));
|
||||
promises.push(group.members[3].update({'stats.mp': 0, 'stats.class': 'healer', 'stats.lvl': 20}));
|
||||
promises.push(group.groupLeader.update({ 'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 20 }));
|
||||
promises.push(group.members[0].update({ 'stats.mp': 0, 'stats.class': 'warrior', 'stats.lvl': 20 }));
|
||||
promises.push(group.members[1].update({ 'stats.mp': 0, 'stats.class': 'wizard', 'stats.lvl': 20 }));
|
||||
promises.push(group.members[2].update({ 'stats.mp': 0, 'stats.class': 'rogue', 'stats.lvl': 20 }));
|
||||
promises.push(group.members[3].update({ 'stats.mp': 0, 'stats.class': 'healer', 'stats.lvl': 20 }));
|
||||
await Promise.all(promises);
|
||||
|
||||
await group.groupLeader.post('/user/class/cast/mpheal');
|
||||
@@ -236,13 +234,13 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('cast bulk', async () => {
|
||||
let { group, groupLeader } = await createAndPopulateGroup({
|
||||
let { group, groupLeader } = await createAndPopulateGroup({ // eslint-disable-line prefer-const
|
||||
groupDetails: { type: 'party', privacy: 'private' },
|
||||
members: 1,
|
||||
});
|
||||
|
||||
await groupLeader.update({'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 13});
|
||||
await groupLeader.post('/user/class/cast/earth', {quantity: 2});
|
||||
await groupLeader.update({ 'stats.mp': 200, 'stats.class': 'wizard', 'stats.lvl': 13 });
|
||||
await groupLeader.post('/user/class/cast/earth', { quantity: 2 });
|
||||
|
||||
await sleep(1);
|
||||
group = await groupLeader.get(`/groups/${group._id}`);
|
||||
@@ -252,33 +250,32 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('searing brightness does not affect challenge or group tasks', async () => {
|
||||
let guild = await generateGroup(user);
|
||||
let challenge = await generateChallenge(user, guild);
|
||||
const guild = await generateGroup(user);
|
||||
const challenge = await generateChallenge(user, guild);
|
||||
await user.post(`/challenges/${challenge._id}/join`);
|
||||
await user.post(`/tasks/challenge/${challenge._id}`, {
|
||||
text: 'test challenge habit',
|
||||
type: 'habit',
|
||||
});
|
||||
|
||||
let groupTask = await user.post(`/tasks/group/${guild._id}`, {
|
||||
const groupTask = await user.post(`/tasks/group/${guild._id}`, {
|
||||
text: 'todo group',
|
||||
type: 'todo',
|
||||
});
|
||||
await user.update({'stats.class': 'healer', 'stats.mp': 200, 'stats.lvl': 15});
|
||||
await user.update({ 'stats.class': 'healer', 'stats.mp': 200, 'stats.lvl': 15 });
|
||||
await user.post(`/tasks/${groupTask._id}/assign/${user._id}`);
|
||||
|
||||
await user.post('/user/class/cast/brightness');
|
||||
await user.sync();
|
||||
|
||||
let memberTasks = await user.get('/tasks/user');
|
||||
const memberTasks = await user.get('/tasks/user');
|
||||
|
||||
let syncedGroupTask = find(memberTasks, function findAssignedTask (memberTask) {
|
||||
return memberTask.group.id === guild._id;
|
||||
});
|
||||
const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === guild._id);
|
||||
|
||||
let userChallengeTask = find(memberTasks, function findAssignedTask (memberTask) {
|
||||
return memberTask.challenge.id === challenge._id;
|
||||
});
|
||||
const userChallengeTask = find(
|
||||
memberTasks,
|
||||
memberTask => memberTask.challenge.id === challenge._id,
|
||||
);
|
||||
|
||||
expect(userChallengeTask).to.exist;
|
||||
expect(syncedGroupTask).to.exist;
|
||||
@@ -287,12 +284,12 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('increases both user\'s achievement values', async () => {
|
||||
let party = await createAndPopulateGroup({
|
||||
const party = await createAndPopulateGroup({
|
||||
members: 1,
|
||||
});
|
||||
let leader = party.groupLeader;
|
||||
let recipient = party.members[0];
|
||||
await leader.update({'stats.gp': 10});
|
||||
const leader = party.groupLeader;
|
||||
const recipient = party.members[0];
|
||||
await leader.update({ 'stats.gp': 10 });
|
||||
await leader.post(`/user/class/cast/birthday?targetId=${recipient._id}`);
|
||||
await leader.sync();
|
||||
await recipient.sync();
|
||||
@@ -301,29 +298,29 @@ describe('POST /user/class/cast/:spellId', () => {
|
||||
});
|
||||
|
||||
it('only increases user\'s achievement one if target == caster', async () => {
|
||||
await user.update({'stats.gp': 10});
|
||||
await user.update({ 'stats.gp': 10 });
|
||||
await user.post(`/user/class/cast/birthday?targetId=${user._id}`);
|
||||
await user.sync();
|
||||
expect(user.achievements.birthday).to.equal(1);
|
||||
});
|
||||
|
||||
it('passes correct target to spell when targetType === \'task\'', async () => {
|
||||
await user.update({'stats.class': 'wizard', 'stats.lvl': 11});
|
||||
await user.update({ 'stats.class': 'wizard', 'stats.lvl': 11 });
|
||||
|
||||
let task = await user.post('/tasks/user', {
|
||||
const task = await user.post('/tasks/user', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
});
|
||||
|
||||
let result = await user.post(`/user/class/cast/fireball?targetId=${task._id}`);
|
||||
const result = await user.post(`/user/class/cast/fireball?targetId=${task._id}`);
|
||||
|
||||
expect(result.task._id).to.equal(task._id);
|
||||
});
|
||||
|
||||
it('passes correct target to spell when targetType === \'self\'', async () => {
|
||||
await user.update({'stats.class': 'wizard', 'stats.lvl': 14, 'stats.mp': 50});
|
||||
await user.update({ 'stats.class': 'wizard', 'stats.lvl': 14, 'stats.mp': 50 });
|
||||
|
||||
let result = await user.post('/user/class/cast/frost');
|
||||
const result = await user.post('/user/class/cast/frost');
|
||||
|
||||
expect(result.user.stats.mp).to.equal(10);
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
let user;
|
||||
let endpoint = '/user/custom-day-start';
|
||||
const endpoint = '/user/custom-day-start';
|
||||
|
||||
describe('POST /user/custom-day-start', () => {
|
||||
beforeEach(async () => {
|
||||
@@ -22,9 +22,9 @@ describe('POST /user/custom-day-start', () => {
|
||||
});
|
||||
|
||||
it('sets lastCron to the current time to prevent an unexpected cron', async () => {
|
||||
let oldCron = moment().subtract(7, 'hours');
|
||||
const oldCron = moment().subtract(7, 'hours');
|
||||
|
||||
await user.update({lastCron: oldCron});
|
||||
await user.update({ lastCron: oldCron });
|
||||
await user.post(endpoint, { dayStart: 1 });
|
||||
await user.sync();
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('POST /user/custom-day-start', () => {
|
||||
});
|
||||
|
||||
it('returns a confirmation message', async () => {
|
||||
let {message} = await user.post(endpoint, { dayStart: 1 });
|
||||
const { message } = await user.post(endpoint, { dayStart: 1 });
|
||||
|
||||
expect(message).to.eql(t('customDayStartHasChanged'));
|
||||
});
|
||||
@@ -41,7 +41,7 @@ describe('POST /user/custom-day-start', () => {
|
||||
await expect(user.post(endpoint, { dayStart: 'foo' }))
|
||||
.to.eventually.be.rejected;
|
||||
|
||||
await expect(user.post(endpoint, { dayStart: 24}))
|
||||
await expect(user.post(endpoint, { dayStart: 24 }))
|
||||
.to.eventually.be.rejected;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('POST /user/disable-classes', () => {
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('disable classes', async () => {
|
||||
let res = await user.post('/user/disable-classes');
|
||||
const res = await user.post('/user/disable-classes');
|
||||
await user.sync();
|
||||
|
||||
expect(res).to.eql(JSON.parse(
|
||||
@@ -20,7 +20,7 @@ describe('POST /user/disable-classes', () => {
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
})
|
||||
}),
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('POST /user/equip/:type/:key', () => {
|
||||
});
|
||||
|
||||
await user.post('/user/equip/equipped/weapon_warrior_1');
|
||||
let res = await user.post('/user/equip/equipped/weapon_warrior_2');
|
||||
const res = await user.post('/user/equip/equipped/weapon_warrior_2');
|
||||
await user.sync();
|
||||
|
||||
expect(res).to.eql(JSON.parse(JSON.stringify(user.items)));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* eslint-disable camelcase */
|
||||
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
@@ -7,7 +8,6 @@ import {
|
||||
sleep,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import content from '../../../../../website/common/script/content';
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
|
||||
describe('POST /user/feed/:pet/:food', () => {
|
||||
let user;
|
||||
@@ -24,10 +24,10 @@ describe('POST /user/feed/:pet/:food', () => {
|
||||
'items.food.Milk': 2,
|
||||
});
|
||||
|
||||
let food = content.food.Milk;
|
||||
let pet = content.petInfo['Wolf-Base'];
|
||||
const food = content.food.Milk;
|
||||
const pet = content.petInfo['Wolf-Base'];
|
||||
|
||||
let res = await user.post('/user/feed/Wolf-Base/Milk');
|
||||
const res = await user.post('/user/feed/Wolf-Base/Milk');
|
||||
await user.sync();
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Base'],
|
||||
@@ -51,7 +51,7 @@ describe('POST /user/feed/:pet/:food', () => {
|
||||
});
|
||||
|
||||
it('sends user activity webhook when a new mount is raised', async () => {
|
||||
let uuid = generateUUID();
|
||||
const uuid = generateUUID();
|
||||
|
||||
await user.post('/user/webhook', {
|
||||
url: `http://localhost:${server.port}/webhooks/${uuid}`,
|
||||
@@ -66,11 +66,11 @@ describe('POST /user/feed/:pet/:food', () => {
|
||||
'items.pets.Wolf-Base': 49,
|
||||
'items.food.Milk': 2,
|
||||
});
|
||||
let res = await user.post('/user/feed/Wolf-Base/Milk');
|
||||
const res = await user.post('/user/feed/Wolf-Base/Milk');
|
||||
|
||||
await sleep();
|
||||
|
||||
let body = server.getWebhookData(uuid);
|
||||
const body = server.getWebhookData(uuid);
|
||||
|
||||
expect(body.type).to.eql('mountRaised');
|
||||
expect(body.pet).to.eql('Wolf-Base');
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
server,
|
||||
sleep,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
|
||||
describe('POST /user/hatch/:egg/:hatchingPotion', () => {
|
||||
let user;
|
||||
@@ -20,7 +20,7 @@ describe('POST /user/hatch/:egg/:hatchingPotion', () => {
|
||||
'items.eggs.Wolf': 1,
|
||||
'items.hatchingPotions.Base': 1,
|
||||
});
|
||||
let res = await user.post('/user/hatch/Wolf/Base');
|
||||
const res = await user.post('/user/hatch/Wolf/Base');
|
||||
await user.sync();
|
||||
expect(user.items.pets['Wolf-Base']).to.equal(5);
|
||||
expect(user.items.eggs.Wolf).to.equal(0);
|
||||
@@ -42,7 +42,7 @@ describe('POST /user/hatch/:egg/:hatchingPotion', () => {
|
||||
});
|
||||
|
||||
it('sends user activity webhook when a new pet is hatched', async () => {
|
||||
let uuid = generateUUID();
|
||||
const uuid = generateUUID();
|
||||
|
||||
await user.post('/user/webhook', {
|
||||
url: `http://localhost:${server.port}/webhooks/${uuid}`,
|
||||
@@ -57,11 +57,11 @@ describe('POST /user/hatch/:egg/:hatchingPotion', () => {
|
||||
'items.eggs.Wolf': 1,
|
||||
'items.hatchingPotions.Base': 1,
|
||||
});
|
||||
let res = await user.post('/user/hatch/Wolf/Base');
|
||||
const res = await user.post('/user/hatch/Wolf/Base');
|
||||
|
||||
await sleep();
|
||||
|
||||
let body = server.getWebhookData(uuid);
|
||||
const body = server.getWebhookData(uuid);
|
||||
|
||||
expect(body.type).to.eql('petHatched');
|
||||
expect(body.pet).to.eql('Wolf-Base');
|
||||
|
||||
@@ -6,16 +6,16 @@ import content from '../../../../../website/common/script/content/index';
|
||||
|
||||
describe('POST /user/open-mystery-item', () => {
|
||||
let user;
|
||||
let mysteryItemKey = 'eyewear_special_summerRogue';
|
||||
let mysteryItemIndex = content.gear.flat[mysteryItemKey].index;
|
||||
let mysteryItemType = content.gear.flat[mysteryItemKey].type;
|
||||
let mysteryItemText = content.gear.flat[mysteryItemKey].text();
|
||||
const mysteryItemKey = 'eyewear_special_summerRogue';
|
||||
const mysteryItemIndex = content.gear.flat[mysteryItemKey].index;
|
||||
const mysteryItemType = content.gear.flat[mysteryItemKey].type;
|
||||
const mysteryItemText = content.gear.flat[mysteryItemKey].text();
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
'purchased.plan.mysteryItems': [mysteryItemKey],
|
||||
notifications: [
|
||||
{type: 'NEW_MYSTERY_ITEMS', data: { items: [mysteryItemKey] }},
|
||||
{ type: 'NEW_MYSTERY_ITEMS', data: { items: [mysteryItemKey] } },
|
||||
],
|
||||
});
|
||||
});
|
||||
@@ -24,7 +24,7 @@ describe('POST /user/open-mystery-item', () => {
|
||||
|
||||
it('opens a mystery item', async () => {
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
let response = await user.post('/user/open-mystery-item');
|
||||
const response = await user.post('/user/open-mystery-item');
|
||||
await user.sync();
|
||||
|
||||
expect(user.notifications.length).to.equal(0);
|
||||
|
||||
@@ -6,8 +6,8 @@ import {
|
||||
|
||||
describe('POST /user/purchase/:type/:key', () => {
|
||||
let user;
|
||||
let type = 'hatchingPotions';
|
||||
let key = 'Base';
|
||||
const type = 'hatchingPotions';
|
||||
const key = 'Base';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
@@ -34,7 +34,7 @@ describe('POST /user/purchase/:type/:key', () => {
|
||||
});
|
||||
|
||||
it('can convert gold to gems if subscribed', async () => {
|
||||
let oldBalance = user.balance;
|
||||
const oldBalance = user.balance;
|
||||
await user.update({
|
||||
'purchased.plan.customerId': 'group-plan',
|
||||
'stats.gp': 1000,
|
||||
@@ -45,7 +45,7 @@ describe('POST /user/purchase/:type/:key', () => {
|
||||
});
|
||||
|
||||
it('leader can convert gold to gems even if the group plan prevents it', async () => {
|
||||
let { group, groupLeader } = await createAndPopulateGroup({
|
||||
const { group, groupLeader } = await createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
name: 'test',
|
||||
type: 'guild',
|
||||
@@ -57,7 +57,7 @@ describe('POST /user/purchase/:type/:key', () => {
|
||||
'purchased.plan.customerId': 123,
|
||||
});
|
||||
await groupLeader.sync();
|
||||
let oldBalance = groupLeader.balance;
|
||||
const oldBalance = groupLeader.balance;
|
||||
|
||||
await groupLeader.update({
|
||||
'purchased.plan.customerId': 'group-plan',
|
||||
@@ -70,7 +70,7 @@ describe('POST /user/purchase/:type/:key', () => {
|
||||
});
|
||||
|
||||
it('cannot convert gold to gems if the group plan prevents it', async () => {
|
||||
let { group, members } = await createAndPopulateGroup({
|
||||
const { group, members } = await createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
name: 'test',
|
||||
type: 'guild',
|
||||
@@ -82,7 +82,7 @@ describe('POST /user/purchase/:type/:key', () => {
|
||||
'leaderOnly.getGems': true,
|
||||
'purchased.plan.customerId': 123,
|
||||
});
|
||||
let oldBalance = members[0].balance;
|
||||
const oldBalance = members[0].balance;
|
||||
|
||||
await members[0].update({
|
||||
'purchased.plan.customerId': 'group-plan',
|
||||
@@ -101,19 +101,19 @@ describe('POST /user/purchase/:type/:key', () => {
|
||||
|
||||
describe('bulk purchasing', () => {
|
||||
it('purchases a gem item', async () => {
|
||||
await user.post(`/user/purchase/${type}/${key}`, {quantity: 2});
|
||||
await user.post(`/user/purchase/${type}/${key}`, { quantity: 2 });
|
||||
await user.sync();
|
||||
|
||||
expect(user.items[type][key]).to.equal(2);
|
||||
});
|
||||
|
||||
it('can convert gold to gems if subscribed', async () => {
|
||||
let oldBalance = user.balance;
|
||||
const oldBalance = user.balance;
|
||||
await user.update({
|
||||
'purchased.plan.customerId': 'group-plan',
|
||||
'stats.gp': 1000,
|
||||
});
|
||||
await user.post('/user/purchase/gems/gem', {quantity: 2});
|
||||
await user.post('/user/purchase/gems/gem', { quantity: 2 });
|
||||
await user.sync();
|
||||
expect(user.balance).to.equal(oldBalance + 0.50);
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ describe('POST /user/purchase-hourglass/:type/:key', () => {
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('buys an hourglass pet', async () => {
|
||||
let response = await user.post('/user/purchase-hourglass/pets/MantisShrimp-Base');
|
||||
const response = await user.post('/user/purchase-hourglass/pets/MantisShrimp-Base');
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.eql(t('hourglassPurchase'));
|
||||
@@ -24,7 +24,7 @@ describe('POST /user/purchase-hourglass/:type/:key', () => {
|
||||
});
|
||||
|
||||
it('buys an hourglass quest', async () => {
|
||||
let response = await user.post('/user/purchase-hourglass/quests/robot');
|
||||
const response = await user.post('/user/purchase-hourglass/quests/robot');
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.eql(t('hourglassPurchase'));
|
||||
@@ -33,7 +33,7 @@ describe('POST /user/purchase-hourglass/:type/:key', () => {
|
||||
});
|
||||
|
||||
it('buys multiple hourglass quests', async () => {
|
||||
let response = await user.post('/user/purchase-hourglass/quests/robot', {quantity: 2});
|
||||
const response = await user.post('/user/purchase-hourglass/quests/robot', { quantity: 2 });
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.eql(t('hourglassPurchase'));
|
||||
|
||||
@@ -5,15 +5,15 @@ import {
|
||||
|
||||
describe('POST /user/push-devices', () => {
|
||||
let user;
|
||||
let regId = '10';
|
||||
let type = 'ios';
|
||||
const regId = '10';
|
||||
const type = 'ios';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('returns an error when regId is not provided', async () => {
|
||||
await expect(user.post('/user/push-devices'), {type})
|
||||
await expect(user.post('/user/push-devices'), { type })
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
@@ -22,7 +22,7 @@ describe('POST /user/push-devices', () => {
|
||||
});
|
||||
|
||||
it('returns an error when type is not provided', async () => {
|
||||
await expect(user.post('/user/push-devices', {regId}))
|
||||
await expect(user.post('/user/push-devices', { regId }))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
@@ -31,7 +31,7 @@ describe('POST /user/push-devices', () => {
|
||||
});
|
||||
|
||||
it('returns an error when type is not valid', async () => {
|
||||
await expect(user.post('/user/push-devices', {regId, type: 'invalid'}))
|
||||
await expect(user.post('/user/push-devices', { regId, type: 'invalid' }))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
@@ -40,8 +40,8 @@ describe('POST /user/push-devices', () => {
|
||||
});
|
||||
|
||||
it('fails silently if user already has the push device', async () => {
|
||||
await user.post('/user/push-devices', {type, regId});
|
||||
const response = await user.post('/user/push-devices', {type, regId});
|
||||
await user.post('/user/push-devices', { type, regId });
|
||||
const response = await user.post('/user/push-devices', { type, regId });
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('pushDeviceAdded'));
|
||||
@@ -52,7 +52,7 @@ describe('POST /user/push-devices', () => {
|
||||
});
|
||||
|
||||
it('adds a push device to the user', async () => {
|
||||
const response = await user.post('/user/push-devices', {type, regId});
|
||||
const response = await user.post('/user/push-devices', { type, regId });
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('pushDeviceAdded'));
|
||||
@@ -63,7 +63,7 @@ describe('POST /user/push-devices', () => {
|
||||
});
|
||||
|
||||
it('removes a push device to the user', async () => {
|
||||
await user.post('/user/push-devices', {type, regId});
|
||||
await user.post('/user/push-devices', { type, regId });
|
||||
|
||||
const response = await user.del(`/user/push-devices/${regId}`);
|
||||
await user.sync();
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
|
||||
describe('POST /user/read-card/:cardType', () => {
|
||||
let user;
|
||||
let cardType = 'greeting';
|
||||
const cardType = 'greeting';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
@@ -28,17 +28,17 @@ describe('POST /user/read-card/:cardType', () => {
|
||||
'flags.cardReceived': true,
|
||||
notifications: [{
|
||||
type: 'CARD_RECEIVED',
|
||||
data: {card: cardType},
|
||||
data: { card: cardType },
|
||||
}],
|
||||
});
|
||||
|
||||
await user.sync();
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
|
||||
let response = await user.post(`/user/read-card/${cardType}`);
|
||||
const response = await user.post(`/user/read-card/${cardType}`);
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('readCard', {cardType}));
|
||||
expect(response.message).to.equal(t('readCard', { cardType }));
|
||||
expect(user.items.special[`${cardType}Received`]).to.be.empty;
|
||||
expect(user.flags.cardReceived).to.be.false;
|
||||
expect(user.notifications.length).to.equal(0);
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('POST /user/rebirth', () => {
|
||||
balance: 1.5,
|
||||
});
|
||||
|
||||
let daily = await generateDaily({
|
||||
const daily = await generateDaily({
|
||||
text: 'test habit',
|
||||
type: 'daily',
|
||||
value: 1,
|
||||
@@ -36,21 +36,21 @@ describe('POST /user/rebirth', () => {
|
||||
userId: user._id,
|
||||
});
|
||||
|
||||
let reward = await generateReward({
|
||||
const reward = await generateReward({
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
value: 1,
|
||||
userId: user._id,
|
||||
});
|
||||
|
||||
let response = await user.post('/user/rebirth');
|
||||
const response = await user.post('/user/rebirth');
|
||||
await user.sync();
|
||||
|
||||
expect(user.notifications.length).to.equal(1);
|
||||
expect(user.notifications[0].type).to.equal('REBIRTH_ACHIEVEMENT');
|
||||
|
||||
let updatedDaily = await user.get(`/tasks/${daily._id}`);
|
||||
let updatedReward = await user.get(`/tasks/${reward._id}`);
|
||||
const updatedDaily = await user.get(`/tasks/${daily._id}`);
|
||||
const updatedReward = await user.get(`/tasks/${reward._id}`);
|
||||
|
||||
expect(response.message).to.equal(t('rebirthComplete'));
|
||||
expect(updatedDaily.streak).to.equal(0);
|
||||
|
||||
@@ -6,21 +6,21 @@ import content from '../../../../../website/common/script/content/index';
|
||||
|
||||
describe('POST /user/release-both', () => {
|
||||
let user;
|
||||
let animal = 'Wolf-Base';
|
||||
const animal = 'Wolf-Base';
|
||||
const loadPets = () => {
|
||||
let pets = {};
|
||||
for (let p in content.pets) {
|
||||
const pets = {};
|
||||
Object.keys(content.pets).forEach(p => {
|
||||
pets[p] = content.pets[p];
|
||||
pets[p] = 5;
|
||||
}
|
||||
});
|
||||
return pets;
|
||||
};
|
||||
const loadMounts = () => {
|
||||
let mounts = {};
|
||||
for (let m in content.pets) {
|
||||
const mounts = {};
|
||||
Object.keys(content.pets).forEach(m => {
|
||||
mounts[m] = content.pets[m];
|
||||
mounts[m] = true;
|
||||
}
|
||||
});
|
||||
return mounts;
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('POST /user/release-both', () => {
|
||||
it('grants triad bingo with gems', async () => {
|
||||
await user.update();
|
||||
|
||||
let response = await user.post('/user/release-both');
|
||||
const response = await user.post('/user/release-both');
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('mountsAndPetsReleased'));
|
||||
|
||||
@@ -6,14 +6,14 @@ import content from '../../../../../website/common/script/content/index';
|
||||
|
||||
describe('POST /user/release-mounts', () => {
|
||||
let user;
|
||||
let animal = 'Wolf-Base';
|
||||
const animal = 'Wolf-Base';
|
||||
|
||||
const loadMounts = () => {
|
||||
let mounts = {};
|
||||
for (let m in content.pets) {
|
||||
const mounts = {};
|
||||
Object.keys(content.pets).forEach(m => {
|
||||
mounts[m] = content.pets[m];
|
||||
mounts[m] = true;
|
||||
}
|
||||
});
|
||||
return mounts;
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('POST /user/release-mounts', () => {
|
||||
balance: 1,
|
||||
});
|
||||
|
||||
let response = await user.post('/user/release-mounts');
|
||||
const response = await user.post('/user/release-mounts');
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('mountsReleased'));
|
||||
|
||||
@@ -6,14 +6,14 @@ import content from '../../../../../website/common/script/content/index';
|
||||
|
||||
describe('POST /user/release-pets', () => {
|
||||
let user;
|
||||
let animal = 'Wolf-Base';
|
||||
const animal = 'Wolf-Base';
|
||||
|
||||
const loadPets = () => {
|
||||
let pets = {};
|
||||
for (let p in content.pets) {
|
||||
const pets = {};
|
||||
Object.keys(content.pets).forEach(p => {
|
||||
pets[p] = content.pets[p];
|
||||
pets[p] = 5;
|
||||
}
|
||||
});
|
||||
return pets;
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('POST /user/release-pets', () => {
|
||||
balance: 1,
|
||||
});
|
||||
|
||||
let response = await user.post('/user/release-pets');
|
||||
const response = await user.post('/user/release-pets');
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('petsReleased'));
|
||||
|
||||
@@ -28,24 +28,24 @@ describe('POST /user/reroll', () => {
|
||||
balance: 2,
|
||||
});
|
||||
|
||||
let daily = await generateDaily({
|
||||
const daily = await generateDaily({
|
||||
text: 'test habit',
|
||||
type: 'daily',
|
||||
userId: user._id,
|
||||
});
|
||||
|
||||
let reward = await generateReward({
|
||||
const reward = await generateReward({
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
value: 1,
|
||||
userId: user._id,
|
||||
});
|
||||
|
||||
let response = await user.post('/user/reroll');
|
||||
const response = await user.post('/user/reroll');
|
||||
await user.sync();
|
||||
|
||||
let updatedDaily = await user.get(`/tasks/${daily._id}`);
|
||||
let updatedReward = await user.get(`/tasks/${reward._id}`);
|
||||
const updatedDaily = await user.get(`/tasks/${daily._id}`);
|
||||
const updatedReward = await user.get(`/tasks/${reward._id}`);
|
||||
|
||||
expect(response.message).to.equal(t('fortifyComplete'));
|
||||
expect(updatedDaily.value).to.equal(0);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { find } from 'lodash';
|
||||
import {
|
||||
generateUser,
|
||||
generateGroup,
|
||||
generateChallenge,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { find } from 'lodash';
|
||||
|
||||
describe('POST /user/reset', () => {
|
||||
let user;
|
||||
@@ -16,7 +16,7 @@ describe('POST /user/reset', () => {
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('resets user\'s habits', async () => {
|
||||
let task = await user.post('/tasks/user', {
|
||||
const task = await user.post('/tasks/user', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
});
|
||||
@@ -34,7 +34,7 @@ describe('POST /user/reset', () => {
|
||||
});
|
||||
|
||||
it('resets user\'s dailys', async () => {
|
||||
let task = await user.post('/tasks/user', {
|
||||
const task = await user.post('/tasks/user', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
});
|
||||
@@ -52,7 +52,7 @@ describe('POST /user/reset', () => {
|
||||
});
|
||||
|
||||
it('resets user\'s todos', async () => {
|
||||
let task = await user.post('/tasks/user', {
|
||||
const task = await user.post('/tasks/user', {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
});
|
||||
@@ -70,7 +70,7 @@ describe('POST /user/reset', () => {
|
||||
});
|
||||
|
||||
it('resets user\'s rewards', async () => {
|
||||
let task = await user.post('/tasks/user', {
|
||||
const task = await user.post('/tasks/user', {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
});
|
||||
@@ -88,15 +88,15 @@ describe('POST /user/reset', () => {
|
||||
});
|
||||
|
||||
it('does not delete challenge or group tasks', async () => {
|
||||
let guild = await generateGroup(user);
|
||||
let challenge = await generateChallenge(user, guild);
|
||||
const guild = await generateGroup(user);
|
||||
const challenge = await generateChallenge(user, guild);
|
||||
await user.post(`/challenges/${challenge._id}/join`);
|
||||
await user.post(`/tasks/challenge/${challenge._id}`, {
|
||||
text: 'test challenge habit',
|
||||
type: 'habit',
|
||||
});
|
||||
|
||||
let groupTask = await user.post(`/tasks/group/${guild._id}`, {
|
||||
const groupTask = await user.post(`/tasks/group/${guild._id}`, {
|
||||
text: 'todo group',
|
||||
type: 'todo',
|
||||
});
|
||||
@@ -105,15 +105,14 @@ describe('POST /user/reset', () => {
|
||||
await user.post('/user/reset');
|
||||
await user.sync();
|
||||
|
||||
let memberTasks = await user.get('/tasks/user');
|
||||
const memberTasks = await user.get('/tasks/user');
|
||||
|
||||
let syncedGroupTask = find(memberTasks, function findAssignedTask (memberTask) {
|
||||
return memberTask.group.id === guild._id;
|
||||
});
|
||||
const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === guild._id);
|
||||
|
||||
let userChallengeTask = find(memberTasks, function findAssignedTask (memberTask) {
|
||||
return memberTask.challenge.id === challenge._id;
|
||||
});
|
||||
const userChallengeTask = find(
|
||||
memberTasks,
|
||||
memberTask => memberTask.challenge.id === challenge._id,
|
||||
);
|
||||
|
||||
expect(userChallengeTask).to.exist;
|
||||
expect(syncedGroupTask).to.exist;
|
||||
|
||||
@@ -8,7 +8,7 @@ describe('POST /user/revive', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
'user.items.gear.owned': {weaponKey: true},
|
||||
'user.items.gear.owned': { weaponKey: true },
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import content from '../../../../../website/common/script/content';
|
||||
|
||||
describe('POST /user/sell/:type/:key', () => {
|
||||
let user;
|
||||
let type = 'eggs';
|
||||
let key = 'Wolf';
|
||||
const type = 'eggs';
|
||||
const key = 'Wolf';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
@@ -20,7 +20,7 @@ describe('POST /user/sell/:type/:key', () => {
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('userItemsKeyNotFound', {type}),
|
||||
message: t('userItemsKeyNotFound', { type }),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ describe('POST /user/sleep', () => {
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('toggles sleep status', async () => {
|
||||
let res = await user.post('/user/sleep');
|
||||
const res = await user.post('/user/sleep');
|
||||
expect(res).to.eql(true);
|
||||
await user.sync();
|
||||
expect(user.preferences.sleep).to.be.true;
|
||||
|
||||
let res2 = await user.post('/user/sleep');
|
||||
const res2 = await user.post('/user/sleep');
|
||||
expect(res2).to.eql(false);
|
||||
await user.sync();
|
||||
expect(user.preferences.sleep).to.be.false;
|
||||
|
||||
@@ -5,9 +5,9 @@ import {
|
||||
|
||||
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;
|
||||
const unlockPath = 'shirt.convict,shirt.cross,shirt.fire,shirt.horizon,shirt.ocean,shirt.purple,shirt.rainbow,shirt.redblue,shirt.thunder,shirt.tropical,shirt.zombie';
|
||||
const unlockCost = 1.25;
|
||||
const usersStartingGems = 5;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
@@ -28,7 +28,7 @@ describe('POST /user/unlock', () => {
|
||||
await user.update({
|
||||
balance: usersStartingGems,
|
||||
});
|
||||
let response = await user.post(`/user/unlock?path=${unlockPath}`);
|
||||
const response = await user.post(`/user/unlock?path=${unlockPath}`);
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('unlocked'));
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { each, get } from 'lodash';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
import { each, get } from 'lodash';
|
||||
|
||||
describe('PUT /user', () => {
|
||||
let user;
|
||||
@@ -40,7 +40,7 @@ describe('PUT /user', () => {
|
||||
});
|
||||
|
||||
it('update tags', async () => {
|
||||
let userTags = user.tags;
|
||||
const userTags = user.tags;
|
||||
|
||||
await user.put('/user', {
|
||||
tags: [...user.tags, {
|
||||
@@ -98,20 +98,20 @@ describe('PUT /user', () => {
|
||||
});
|
||||
|
||||
context('Top Level Protected Operations', () => {
|
||||
let protectedOperations = {
|
||||
'gem balance': {balance: 100},
|
||||
auth: {'auth.blocked': true, 'auth.timestamps.created': new Date()},
|
||||
contributor: {'contributor.level': 9, 'contributor.admin': true, 'contributor.text': 'some text'},
|
||||
backer: {'backer.tier': 10, 'backer.npc': 'Bilbo'},
|
||||
subscriptions: {'purchased.plan.extraMonths': 500, 'purchased.plan.consecutive.trinkets': 1000},
|
||||
'customization gem purchases': {'purchased.background.tavern': true, 'purchased.skin.bear': true},
|
||||
notifications: [{type: 123}],
|
||||
webhooks: {webhooks: [{url: 'https://foobar.com'}]},
|
||||
const protectedOperations = {
|
||||
'gem balance': { balance: 100 },
|
||||
auth: { 'auth.blocked': true, 'auth.timestamps.created': new Date() },
|
||||
contributor: { 'contributor.level': 9, 'contributor.admin': true, 'contributor.text': 'some text' },
|
||||
backer: { 'backer.tier': 10, 'backer.npc': 'Bilbo' },
|
||||
subscriptions: { 'purchased.plan.extraMonths': 500, 'purchased.plan.consecutive.trinkets': 1000 },
|
||||
'customization gem purchases': { 'purchased.background.tavern': true, 'purchased.skin.bear': true },
|
||||
notifications: [{ type: 123 }],
|
||||
webhooks: { webhooks: [{ url: 'https://foobar.com' }] },
|
||||
};
|
||||
|
||||
each(protectedOperations, (data, testName) => {
|
||||
it(`does not allow updating ${testName}`, async () => {
|
||||
let errorText = t('messageUserOperationProtected', { operation: Object.keys(data)[0] });
|
||||
const errorText = t('messageUserOperationProtected', { operation: Object.keys(data)[0] });
|
||||
|
||||
await expect(user.put('/user', data)).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
@@ -123,17 +123,17 @@ describe('PUT /user', () => {
|
||||
});
|
||||
|
||||
context('Sub-Level Protected Operations', () => {
|
||||
let protectedOperations = {
|
||||
'class stat': {'stats.class': 'wizard'},
|
||||
'flags unless whitelisted': {'flags.dropsEnabled': true},
|
||||
webhooks: {'preferences.webhooks': [1, 2, 3]},
|
||||
sleep: {'preferences.sleep': true},
|
||||
'disable classes': {'preferences.disableClasses': true},
|
||||
const protectedOperations = {
|
||||
'class stat': { 'stats.class': 'wizard' },
|
||||
'flags unless whitelisted': { 'flags.dropsEnabled': true },
|
||||
webhooks: { 'preferences.webhooks': [1, 2, 3] },
|
||||
sleep: { 'preferences.sleep': true },
|
||||
'disable classes': { 'preferences.disableClasses': true },
|
||||
};
|
||||
|
||||
each(protectedOperations, (data, testName) => {
|
||||
it(`does not allow updating ${testName}`, async () => {
|
||||
let errorText = t('messageUserOperationProtected', { operation: Object.keys(data)[0] });
|
||||
const errorText = t('messageUserOperationProtected', { operation: Object.keys(data)[0] });
|
||||
|
||||
await expect(user.put('/user', data)).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
@@ -145,7 +145,7 @@ describe('PUT /user', () => {
|
||||
});
|
||||
|
||||
context('Default Appearance Preferences', () => {
|
||||
let testCases = {
|
||||
const testCases = {
|
||||
shirt: 'yellow',
|
||||
skin: 'ddc994',
|
||||
'hair.color': 'blond',
|
||||
@@ -160,14 +160,14 @@ describe('PUT /user', () => {
|
||||
update[`preferences.${type}`] = item;
|
||||
|
||||
it(`updates user with ${type} that is a default`, async () => {
|
||||
let dbUpdate = {};
|
||||
const dbUpdate = {};
|
||||
dbUpdate[`purchased.${type}.${item}`] = true;
|
||||
await user.update(dbUpdate);
|
||||
|
||||
// Sanity checks to make sure user is not already equipped with item
|
||||
expect(get(user.preferences, type)).to.not.eql(item);
|
||||
|
||||
let updatedUser = await user.put('/user', update);
|
||||
const updatedUser = await user.put('/user', update);
|
||||
|
||||
expect(get(updatedUser.preferences, type)).to.eql(item);
|
||||
});
|
||||
@@ -189,7 +189,7 @@ describe('PUT /user', () => {
|
||||
'preferences.hair.beard': 3,
|
||||
});
|
||||
|
||||
let updatedUser = await user.put('/user', {
|
||||
const updatedUser = await user.put('/user', {
|
||||
'preferences.hair.beard': 0,
|
||||
});
|
||||
|
||||
@@ -202,7 +202,7 @@ describe('PUT /user', () => {
|
||||
'preferences.hair.mustache': 2,
|
||||
});
|
||||
|
||||
let updatedUser = await user.put('/user', {
|
||||
const updatedUser = await user.put('/user', {
|
||||
'preferences.hair.mustache': 0,
|
||||
});
|
||||
|
||||
@@ -211,7 +211,7 @@ describe('PUT /user', () => {
|
||||
});
|
||||
|
||||
context('Purchasable Appearance Preferences', () => {
|
||||
let testCases = {
|
||||
const testCases = {
|
||||
background: 'volcano',
|
||||
shirt: 'convict',
|
||||
skin: 'cactus',
|
||||
@@ -229,19 +229,19 @@ describe('PUT /user', () => {
|
||||
await expect(user.put('/user', update)).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('mustPurchaseToSet', {val: item, key: `preferences.${type}`}),
|
||||
message: t('mustPurchaseToSet', { val: item, key: `preferences.${type}` }),
|
||||
});
|
||||
});
|
||||
|
||||
it(`updates user with ${type} user does own`, async () => {
|
||||
let dbUpdate = {};
|
||||
const dbUpdate = {};
|
||||
dbUpdate[`purchased.${type}.${item}`] = true;
|
||||
await user.update(dbUpdate);
|
||||
|
||||
// Sanity check to make sure user is not already equipped with item
|
||||
expect(get(user.preferences, type)).to.not.eql(item);
|
||||
|
||||
let updatedUser = await user.put('/user', update);
|
||||
const updatedUser = await user.put('/user', update);
|
||||
|
||||
expect(get(updatedUser.preferences, type)).to.eql(item);
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('DELETE social registration', () => {
|
||||
'auth.facebook.id': 'some-fb-id',
|
||||
});
|
||||
|
||||
let response = await user.del('/user/auth/social/facebook');
|
||||
const response = await user.del('/user/auth/social/facebook');
|
||||
expect(response).to.eql({});
|
||||
await user.sync();
|
||||
expect(user.auth.facebook).to.be.undefined;
|
||||
@@ -51,7 +51,7 @@ describe('DELETE social registration', () => {
|
||||
'auth.local': { ok: true },
|
||||
});
|
||||
|
||||
let response = await user.del('/user/auth/social/facebook');
|
||||
const response = await user.del('/user/auth/social/facebook');
|
||||
expect(response).to.eql({});
|
||||
await user.sync();
|
||||
expect(user.auth.facebook).to.be.undefined;
|
||||
@@ -76,7 +76,7 @@ describe('DELETE social registration', () => {
|
||||
'auth.google.id': 'some-google-id',
|
||||
});
|
||||
|
||||
let response = await user.del('/user/auth/social/google');
|
||||
const response = await user.del('/user/auth/social/google');
|
||||
expect(response).to.eql({});
|
||||
await user.sync();
|
||||
expect(user.auth.google).to.be.undefined;
|
||||
@@ -89,7 +89,7 @@ describe('DELETE social registration', () => {
|
||||
'auth.local': { ok: true },
|
||||
});
|
||||
|
||||
let response = await user.del('/user/auth/social/google');
|
||||
const response = await user.del('/user/auth/social/google');
|
||||
expect(response).to.eql({});
|
||||
await user.sync();
|
||||
expect(user.auth.goodl).to.be.undefined;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import {
|
||||
encrypt,
|
||||
} from '../../../../../../website/server/libs/encryption';
|
||||
import moment from 'moment';
|
||||
import superagent from 'superagent';
|
||||
import nconf from 'nconf';
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../../../../helpers/api-integration/v3';
|
||||
import superagent from 'superagent';
|
||||
import nconf from 'nconf';
|
||||
import {
|
||||
encrypt,
|
||||
} from '../../../../../../website/server/libs/encryption';
|
||||
|
||||
const API_TEST_SERVER_PORT = nconf.get('PORT');
|
||||
|
||||
// @TODO skipped because on travis the client isn't available and the redirect fails
|
||||
xdescribe('GET /user/auth/local/reset-password-set-new-one', () => {
|
||||
let endpoint = `http://localhost:${API_TEST_SERVER_PORT}/static/user/auth/local/reset-password-set-new-one`;
|
||||
const endpoint = `http://localhost:${API_TEST_SERVER_PORT}/static/user/auth/local/reset-password-set-new-one`;
|
||||
|
||||
// Tests to validate the validatePasswordResetCodeAndFindUser function
|
||||
|
||||
@@ -27,9 +27,9 @@ xdescribe('GET /user/auth/local/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the code cannot be decrypted', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = JSON.stringify({ // not encrypted
|
||||
const code = JSON.stringify({ // not encrypted
|
||||
userId: user._id,
|
||||
expiresAt: new Date(),
|
||||
});
|
||||
@@ -38,11 +38,11 @@ xdescribe('GET /user/auth/local/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the code is expired', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().subtract({minutes: 1}),
|
||||
expiresAt: moment().subtract({ minutes: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': code,
|
||||
@@ -53,9 +53,9 @@ xdescribe('GET /user/auth/local/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the user does not exist', async () => {
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: Date.now().toString(),
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
|
||||
const res = await superagent.get(`${endpoint}?code=${code}`);
|
||||
@@ -63,11 +63,11 @@ xdescribe('GET /user/auth/local/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the user has no local auth', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
auth: 'not an object with valid fields',
|
||||
@@ -78,11 +78,11 @@ xdescribe('GET /user/auth/local/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the code doesn\'t match the one saved at user.auth.passwordResetCode', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': 'invalid',
|
||||
@@ -95,19 +95,18 @@ xdescribe('GET /user/auth/local/reset-password-set-new-one', () => {
|
||||
//
|
||||
|
||||
it('returns the password reset page if the password reset code is valid', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': code,
|
||||
});
|
||||
|
||||
let res = await superagent.get(`${endpoint}?code=${code}`);
|
||||
const res = await superagent.get(`${endpoint}?code=${code}`);
|
||||
expect(res.req.path.indexOf('hasError=false') !== -1).to.equal(true);
|
||||
expect(res.req.path.indexOf('code=') !== -1).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import moment from 'moment';
|
||||
import {
|
||||
encrypt,
|
||||
} from '../../../../../../website/server/libs/encryption';
|
||||
@@ -7,7 +8,6 @@ import {
|
||||
sha1MakeSalt,
|
||||
sha1Encrypt as sha1EncryptPassword,
|
||||
} from '../../../../../../website/server/libs/password';
|
||||
import moment from 'moment';
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
@@ -36,9 +36,9 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the code cannot be decrypted', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = JSON.stringify({ // not encrypted
|
||||
const code = JSON.stringify({ // not encrypted
|
||||
userId: user._id,
|
||||
expiresAt: new Date(),
|
||||
});
|
||||
@@ -53,11 +53,11 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the code is expired', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().subtract({minutes: 1}),
|
||||
expiresAt: moment().subtract({ minutes: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': code,
|
||||
@@ -73,9 +73,9 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the user does not exist', async () => {
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: Date.now().toString(),
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
|
||||
await expect(api.post(`${endpoint}`, {
|
||||
@@ -88,11 +88,11 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the user has no local auth', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
|
||||
await expect(api.post(`${endpoint}`, {
|
||||
@@ -105,11 +105,11 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders an error page if the code doesn\'t match the one saved at user.auth.passwordResetCode', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': 'invalid',
|
||||
@@ -127,11 +127,11 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
//
|
||||
|
||||
it('renders the error page if the new password is missing', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': code,
|
||||
@@ -147,11 +147,11 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders the error page if the password confirmation is missing', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': code,
|
||||
@@ -168,11 +168,11 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders the error page if the password confirmation does not match', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': code,
|
||||
@@ -190,17 +190,17 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
});
|
||||
|
||||
it('renders the success page and save the user', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': code,
|
||||
});
|
||||
|
||||
let res = await api.post(`${endpoint}`, {
|
||||
const res = await api.post(`${endpoint}`, {
|
||||
newPassword: 'my new password',
|
||||
confirmPassword: 'my new password',
|
||||
code,
|
||||
@@ -212,16 +212,16 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
expect(user.auth.local.passwordResetCode).to.equal(undefined);
|
||||
expect(user.auth.local.passwordHashMethod).to.equal('bcrypt');
|
||||
expect(user.auth.local.salt).to.be.undefined;
|
||||
let isPassValid = await compare(user, 'my new password');
|
||||
const isPassValid = await compare(user, 'my new password');
|
||||
expect(isPassValid).to.equal(true);
|
||||
});
|
||||
|
||||
it('renders the success page and convert the password from sha1 to bcrypt', async () => {
|
||||
let user = await generateUser();
|
||||
const user = await generateUser();
|
||||
|
||||
let textPassword = 'mySecretPassword';
|
||||
let salt = sha1MakeSalt();
|
||||
let sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
const textPassword = 'mySecretPassword';
|
||||
const salt = sha1MakeSalt();
|
||||
const sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
|
||||
await user.update({
|
||||
'auth.local.hashed_password': sha1HashedPassword,
|
||||
@@ -234,15 +234,15 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
expect(user.auth.local.salt).to.equal(salt);
|
||||
expect(user.auth.local.hashed_password).to.equal(sha1HashedPassword);
|
||||
|
||||
let code = encrypt(JSON.stringify({
|
||||
const code = encrypt(JSON.stringify({
|
||||
userId: user._id,
|
||||
expiresAt: moment().add({days: 1}),
|
||||
expiresAt: moment().add({ days: 1 }),
|
||||
}));
|
||||
await user.update({
|
||||
'auth.local.passwordResetCode': code,
|
||||
});
|
||||
|
||||
let res = await api.post(`${endpoint}`, {
|
||||
const res = await api.post(`${endpoint}`, {
|
||||
newPassword: 'my new password',
|
||||
confirmPassword: 'my new password',
|
||||
code,
|
||||
@@ -256,7 +256,7 @@ describe('POST /user/auth/reset-password-set-new-one', () => {
|
||||
expect(user.auth.local.salt).to.be.undefined;
|
||||
expect(user.auth.local.hashed_password).not.to.equal(sha1HashedPassword);
|
||||
|
||||
let isValidPassword = await bcryptCompare('my new password', user.auth.local.hashed_password);
|
||||
const isValidPassword = await bcryptCompare('my new password', user.auth.local.hashed_password);
|
||||
expect(isValidPassword).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import nconf from 'nconf';
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
@@ -9,20 +10,19 @@ import {
|
||||
sha1Encrypt as sha1EncryptPassword,
|
||||
} from '../../../../../../website/server/libs/password';
|
||||
|
||||
import nconf from 'nconf';
|
||||
|
||||
describe('POST /user/auth/local/login', () => {
|
||||
let api;
|
||||
let user;
|
||||
let endpoint = '/user/auth/local/login';
|
||||
let password = 'password';
|
||||
const endpoint = '/user/auth/local/login';
|
||||
const password = 'password';
|
||||
beforeEach(async () => {
|
||||
api = requester();
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('success with username', async () => {
|
||||
let response = await api.post(endpoint, {
|
||||
const response = await api.post(endpoint, {
|
||||
username: user.auth.local.username,
|
||||
password,
|
||||
});
|
||||
@@ -30,7 +30,7 @@ describe('POST /user/auth/local/login', () => {
|
||||
});
|
||||
|
||||
it('success with email', async () => {
|
||||
let response = await api.post(endpoint, {
|
||||
const response = await api.post(endpoint, {
|
||||
username: user.auth.local.email,
|
||||
password,
|
||||
});
|
||||
@@ -81,9 +81,9 @@ describe('POST /user/auth/local/login', () => {
|
||||
});
|
||||
|
||||
it('converts user with SHA1 encrypted password to bcrypt encryption', async () => {
|
||||
let textPassword = 'mySecretPassword';
|
||||
let salt = sha1MakeSalt();
|
||||
let sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
const textPassword = 'mySecretPassword';
|
||||
const salt = sha1MakeSalt();
|
||||
const sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
|
||||
await user.update({
|
||||
'auth.local.hashed_password': sha1HashedPassword,
|
||||
@@ -107,7 +107,7 @@ describe('POST /user/auth/local/login', () => {
|
||||
expect(user.auth.local.salt).to.be.undefined;
|
||||
expect(user.auth.local.hashed_password).not.to.equal(sha1HashedPassword);
|
||||
|
||||
let isValidPassword = await bcryptCompare(textPassword, user.auth.local.hashed_password);
|
||||
const isValidPassword = await bcryptCompare(textPassword, user.auth.local.hashed_password);
|
||||
expect(isValidPassword).to.equal(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { each } from 'lodash';
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
@@ -6,8 +8,6 @@ import {
|
||||
getProperty,
|
||||
} from '../../../../../helpers/api-integration/v3';
|
||||
import { ApiUser } from '../../../../../helpers/api-integration/api-classes';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { each } from 'lodash';
|
||||
import { encrypt } from '../../../../../../website/server/libs/encryption';
|
||||
|
||||
function generateRandomUserName () {
|
||||
@@ -23,11 +23,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('registers a new user', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -42,11 +42,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('registers a new user and sets verifiedUsername to true', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -60,11 +60,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
|
||||
xit('remove spaces from username', async () => {
|
||||
// TODO can probably delete this test now
|
||||
let username = ' usernamewithspaces ';
|
||||
let email = 'test@example.com';
|
||||
let password = 'password';
|
||||
const username = ' usernamewithspaces ';
|
||||
const email = 'test@example.com';
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -125,24 +125,24 @@ describe('POST /user/auth/local/register', () => {
|
||||
|
||||
context('provides default tags and tasks', async () => {
|
||||
it('for a generic API consumer', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
});
|
||||
|
||||
let requests = new ApiUser(user);
|
||||
const requests = new ApiUser(user);
|
||||
|
||||
let habits = await requests.get('/tasks/user?type=habits');
|
||||
let dailys = await requests.get('/tasks/user?type=dailys');
|
||||
let todos = await requests.get('/tasks/user?type=todos');
|
||||
let rewards = await requests.get('/tasks/user?type=rewards');
|
||||
let tags = await requests.get('/tags');
|
||||
const habits = await requests.get('/tasks/user?type=habits');
|
||||
const dailys = await requests.get('/tasks/user?type=dailys');
|
||||
const todos = await requests.get('/tasks/user?type=todos');
|
||||
const rewards = await requests.get('/tasks/user?type=rewards');
|
||||
const tags = await requests.get('/tags');
|
||||
|
||||
expect(habits).to.have.a.lengthOf(0);
|
||||
expect(dailys).to.have.a.lengthOf(0);
|
||||
@@ -162,26 +162,26 @@ describe('POST /user/auth/local/register', () => {
|
||||
xit('for Web', async () => {
|
||||
api = requester(
|
||||
null,
|
||||
{'x-client': 'habitica-web'},
|
||||
{ 'x-client': 'habitica-web' },
|
||||
);
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
});
|
||||
|
||||
let requests = new ApiUser(user);
|
||||
const requests = new ApiUser(user);
|
||||
|
||||
let habits = await requests.get('/tasks/user?type=habits');
|
||||
let dailys = await requests.get('/tasks/user?type=dailys');
|
||||
let todos = await requests.get('/tasks/user?type=todos');
|
||||
let rewards = await requests.get('/tasks/user?type=rewards');
|
||||
let tags = await requests.get('/tags');
|
||||
const habits = await requests.get('/tasks/user?type=habits');
|
||||
const dailys = await requests.get('/tasks/user?type=dailys');
|
||||
const todos = await requests.get('/tasks/user?type=todos');
|
||||
const rewards = await requests.get('/tasks/user?type=rewards');
|
||||
const tags = await requests.get('/tags');
|
||||
|
||||
expect(habits).to.have.a.lengthOf(3);
|
||||
expect(habits[0].text).to.eql(t('defaultHabit1Text'));
|
||||
@@ -216,26 +216,26 @@ describe('POST /user/auth/local/register', () => {
|
||||
it('for Android', async () => {
|
||||
api = requester(
|
||||
null,
|
||||
{'x-client': 'habitica-android'},
|
||||
{ 'x-client': 'habitica-android' },
|
||||
);
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
});
|
||||
|
||||
let requests = new ApiUser(user);
|
||||
const requests = new ApiUser(user);
|
||||
|
||||
let habits = await requests.get('/tasks/user?type=habits');
|
||||
let dailys = await requests.get('/tasks/user?type=dailys');
|
||||
let todos = await requests.get('/tasks/user?type=todos');
|
||||
let rewards = await requests.get('/tasks/user?type=rewards');
|
||||
let tags = await requests.get('/tags');
|
||||
const habits = await requests.get('/tasks/user?type=habits');
|
||||
const dailys = await requests.get('/tasks/user?type=dailys');
|
||||
const todos = await requests.get('/tasks/user?type=todos');
|
||||
const rewards = await requests.get('/tasks/user?type=rewards');
|
||||
const tags = await requests.get('/tags');
|
||||
|
||||
expect(habits).to.have.a.lengthOf(0);
|
||||
expect(dailys).to.have.a.lengthOf(0);
|
||||
@@ -247,26 +247,26 @@ describe('POST /user/auth/local/register', () => {
|
||||
it('for iOS', async () => {
|
||||
api = requester(
|
||||
null,
|
||||
{'x-client': 'habitica-ios'},
|
||||
{ 'x-client': 'habitica-ios' },
|
||||
);
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
});
|
||||
|
||||
let requests = new ApiUser(user);
|
||||
const requests = new ApiUser(user);
|
||||
|
||||
let habits = await requests.get('/tasks/user?type=habits');
|
||||
let dailys = await requests.get('/tasks/user?type=dailys');
|
||||
let todos = await requests.get('/tasks/user?type=todos');
|
||||
let rewards = await requests.get('/tasks/user?type=rewards');
|
||||
let tags = await requests.get('/tags');
|
||||
const habits = await requests.get('/tasks/user?type=habits');
|
||||
const dailys = await requests.get('/tasks/user?type=dailys');
|
||||
const todos = await requests.get('/tasks/user?type=todos');
|
||||
const rewards = await requests.get('/tasks/user?type=rewards');
|
||||
const tags = await requests.get('/tags');
|
||||
|
||||
expect(habits).to.have.a.lengthOf(0);
|
||||
expect(dailys).to.have.a.lengthOf(0);
|
||||
@@ -277,11 +277,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
xit('enrolls new users in an A/B test', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -292,11 +292,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('includes items awarded by default when creating a new user', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -309,10 +309,10 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('requires password and confirmPassword to match', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let password = 'password';
|
||||
let confirmPassword = 'not password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const password = 'password';
|
||||
const confirmPassword = 'not password';
|
||||
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
@@ -327,9 +327,9 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('requires a username', async () => {
|
||||
let email = `${generateRandomUserName()}@example.com`;
|
||||
let password = 'password';
|
||||
let confirmPassword = 'password';
|
||||
const email = `${generateRandomUserName()}@example.com`;
|
||||
const password = 'password';
|
||||
const confirmPassword = 'password';
|
||||
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
email,
|
||||
@@ -343,8 +343,8 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('requires an email', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const password = 'password';
|
||||
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
@@ -358,9 +358,9 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('requires a valid email', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = 'notanemail@sdf';
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = 'notanemail@sdf';
|
||||
const password = 'password';
|
||||
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
@@ -375,11 +375,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('sanitizes email params to a lowercase string before creating the user', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = 'ISANEmAiL@ExAmPle.coM';
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = 'ISANEmAiL@ExAmPle.coM';
|
||||
const password = 'password';
|
||||
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -390,9 +390,9 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('fails on a habitica.com email', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@habitica.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@habitica.com`;
|
||||
const password = 'password';
|
||||
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
@@ -407,9 +407,9 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('fails on a habitrpg.com email', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@habitrpg.com`;
|
||||
let password = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@habitrpg.com`;
|
||||
const password = 'password';
|
||||
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
@@ -424,9 +424,9 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('requires a password', async () => {
|
||||
let username = generateRandomUserName();
|
||||
let email = `${username}@example.com`;
|
||||
let confirmPassword = 'password';
|
||||
const username = generateRandomUserName();
|
||||
const email = `${username}@example.com`;
|
||||
const confirmPassword = 'password';
|
||||
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
@@ -442,9 +442,9 @@ describe('POST /user/auth/local/register', () => {
|
||||
|
||||
context('attach to facebook user', () => {
|
||||
let user;
|
||||
let email = 'some@email.net';
|
||||
let username = 'some-username';
|
||||
let password = 'some-password';
|
||||
const email = 'some@email.net';
|
||||
const username = 'some-username';
|
||||
const password = 'some-password';
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
@@ -475,7 +475,8 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
context('login is already taken', () => {
|
||||
let username, email, api;
|
||||
let username; let email; let
|
||||
api;
|
||||
|
||||
beforeEach(async () => {
|
||||
api = requester();
|
||||
@@ -490,8 +491,8 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('rejects if username is already taken', async () => {
|
||||
let uniqueEmail = `${generateRandomUserName()}@exampe.com`;
|
||||
let password = 'password';
|
||||
const uniqueEmail = `${generateRandomUserName()}@exampe.com`;
|
||||
const password = 'password';
|
||||
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username,
|
||||
@@ -506,8 +507,8 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('rejects if email is already taken', async () => {
|
||||
let uniqueUsername = generateRandomUserName();
|
||||
let password = 'password';
|
||||
const uniqueUsername = generateRandomUserName();
|
||||
const password = 'password';
|
||||
|
||||
await expect(api.post('/user/auth/local/register', {
|
||||
username: uniqueUsername,
|
||||
@@ -523,7 +524,8 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
context('req.query.groupInvite', () => {
|
||||
let api, username, email, password;
|
||||
let api; let username; let email; let
|
||||
password;
|
||||
|
||||
beforeEach(() => {
|
||||
api = requester();
|
||||
@@ -533,7 +535,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('does not crash the signup process when it\'s invalid', async () => {
|
||||
let user = await api.post('/user/auth/local/register?groupInvite=aaaaInvalid', {
|
||||
const user = await api.post('/user/auth/local/register?groupInvite=aaaaInvalid', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -544,17 +546,17 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('supports invite using req.query.groupInvite', async () => {
|
||||
let { group, groupLeader } = await createAndPopulateGroup({
|
||||
const { group, groupLeader } = await createAndPopulateGroup({
|
||||
groupDetails: { type: 'party', privacy: 'private' },
|
||||
});
|
||||
|
||||
let invite = encrypt(JSON.stringify({
|
||||
const invite = encrypt(JSON.stringify({
|
||||
id: group._id,
|
||||
inviter: groupLeader._id,
|
||||
sentAt: Date.now(), // so we can let it expire
|
||||
}));
|
||||
|
||||
let user = await api.post(`/user/auth/local/register?groupInvite=${invite}`, {
|
||||
const user = await api.post(`/user/auth/local/register?groupInvite=${invite}`, {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -567,11 +569,11 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('awards achievement to inviter', async () => {
|
||||
let { group, groupLeader } = await createAndPopulateGroup({
|
||||
const { group, groupLeader } = await createAndPopulateGroup({
|
||||
groupDetails: { type: 'party', privacy: 'private' },
|
||||
});
|
||||
|
||||
let invite = encrypt(JSON.stringify({
|
||||
const invite = encrypt(JSON.stringify({
|
||||
id: group._id,
|
||||
inviter: groupLeader._id,
|
||||
sentAt: Date.now(),
|
||||
@@ -589,17 +591,17 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('user not added to a party on expired invite', async () => {
|
||||
let { group, groupLeader } = await createAndPopulateGroup({
|
||||
const { group, groupLeader } = await createAndPopulateGroup({
|
||||
groupDetails: { type: 'party', privacy: 'private' },
|
||||
});
|
||||
|
||||
let invite = encrypt(JSON.stringify({
|
||||
const invite = encrypt(JSON.stringify({
|
||||
id: group._id,
|
||||
inviter: groupLeader._id,
|
||||
sentAt: Date.now() - 6.912e8, // 8 days old
|
||||
}));
|
||||
|
||||
let user = await api.post(`/user/auth/local/register?groupInvite=${invite}`, {
|
||||
const user = await api.post(`/user/auth/local/register?groupInvite=${invite}`, {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -610,17 +612,17 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('adds a user to a guild on an invite of type other than party', async () => {
|
||||
let { group, groupLeader } = await createAndPopulateGroup({
|
||||
const { group, groupLeader } = await createAndPopulateGroup({
|
||||
groupDetails: { type: 'guild', privacy: 'private' },
|
||||
});
|
||||
|
||||
let invite = encrypt(JSON.stringify({
|
||||
const invite = encrypt(JSON.stringify({
|
||||
id: group._id,
|
||||
inviter: groupLeader._id,
|
||||
sentAt: Date.now(),
|
||||
}));
|
||||
|
||||
let user = await api.post(`/user/auth/local/register?groupInvite=${invite}`, {
|
||||
const user = await api.post(`/user/auth/local/register?groupInvite=${invite}`, {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -636,7 +638,8 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
context('successful login via api', () => {
|
||||
let api, username, email, password;
|
||||
let api; let username; let email; let
|
||||
password;
|
||||
|
||||
beforeEach(() => {
|
||||
api = requester();
|
||||
@@ -646,7 +649,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('sets all site tour values to -2 (already seen)', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -655,13 +658,13 @@ describe('POST /user/auth/local/register', () => {
|
||||
|
||||
expect(user.flags.tour).to.not.be.empty;
|
||||
|
||||
each(user.flags.tour, (value) => {
|
||||
each(user.flags.tour, value => {
|
||||
expect(value).to.eql(-2);
|
||||
});
|
||||
});
|
||||
|
||||
it('populates user with default todos, not no other task types', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -675,7 +678,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('populates user with default tags', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -687,17 +690,18 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
context('successful login with habitica-web header', () => {
|
||||
let api, username, email, password;
|
||||
let api; let username; let email; let
|
||||
password;
|
||||
|
||||
beforeEach(() => {
|
||||
api = requester({}, {'x-client': 'habitica-web'});
|
||||
api = requester({}, { 'x-client': 'habitica-web' });
|
||||
username = generateRandomUserName();
|
||||
email = `${username}@example.com`;
|
||||
password = 'password';
|
||||
});
|
||||
|
||||
it('sets all common tutorial flags to true', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -706,13 +710,13 @@ describe('POST /user/auth/local/register', () => {
|
||||
|
||||
expect(user.flags.tour).to.not.be.empty;
|
||||
|
||||
each(user.flags.tutorial.common, (value) => {
|
||||
each(user.flags.tutorial.common, value => {
|
||||
expect(value).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('populates user with default todos, habits, and rewards', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -726,7 +730,7 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('populates user with default tags', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
@@ -737,17 +741,17 @@ describe('POST /user/auth/local/register', () => {
|
||||
});
|
||||
|
||||
it('adds the correct tags to the correct tasks', async () => {
|
||||
let user = await api.post('/user/auth/local/register', {
|
||||
const user = await api.post('/user/auth/local/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirmPassword: password,
|
||||
});
|
||||
|
||||
let requests = new ApiUser(user);
|
||||
const requests = new ApiUser(user);
|
||||
|
||||
let habits = await requests.get('/tasks/user?type=habits');
|
||||
let todos = await requests.get('/tasks/user?type=todos');
|
||||
const habits = await requests.get('/tasks/user?type=habits');
|
||||
const todos = await requests.get('/tasks/user?type=todos');
|
||||
|
||||
expect(habits).to.have.a.lengthOf(0);
|
||||
expect(todos).to.have.a.lengthOf(0);
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import passport from 'passport';
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
getProperty,
|
||||
} from '../../../../../helpers/api-integration/v3';
|
||||
import passport from 'passport';
|
||||
|
||||
describe('POST /user/auth/social', () => {
|
||||
let api;
|
||||
let user;
|
||||
let endpoint = '/user/auth/social';
|
||||
let randomAccessToken = '123456';
|
||||
let facebookId = 'facebookId';
|
||||
let googleId = 'googleId';
|
||||
const endpoint = '/user/auth/social';
|
||||
const randomAccessToken = '123456';
|
||||
const facebookId = 'facebookId';
|
||||
const googleId = 'googleId';
|
||||
let network = 'NoNetwork';
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -22,7 +22,7 @@ describe('POST /user/auth/social', () => {
|
||||
|
||||
it('fails if network is not supported', async () => {
|
||||
await expect(api.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
@@ -33,14 +33,14 @@ describe('POST /user/auth/social', () => {
|
||||
|
||||
describe('facebook', () => {
|
||||
before(async () => {
|
||||
let expectedResult = {id: facebookId, displayName: 'a facebook user'};
|
||||
const expectedResult = { id: facebookId, displayName: 'a facebook user' };
|
||||
sandbox.stub(passport._strategies.facebook, 'userProfile').yields(null, expectedResult);
|
||||
network = 'facebook';
|
||||
});
|
||||
|
||||
it('registers a new user', async () => {
|
||||
const response = await api.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
@@ -54,13 +54,13 @@ describe('POST /user/auth/social', () => {
|
||||
});
|
||||
|
||||
it('logs an existing user in', async () => {
|
||||
let registerResponse = await api.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
const registerResponse = await api.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
let response = await api.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
const response = await api.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
@@ -70,8 +70,8 @@ describe('POST /user/auth/social', () => {
|
||||
});
|
||||
|
||||
it('add social auth to an existing user', async () => {
|
||||
let response = await user.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
const response = await user.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
@@ -82,7 +82,7 @@ describe('POST /user/auth/social', () => {
|
||||
|
||||
xit('enrolls a new user in an A/B test', async () => {
|
||||
await api.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
@@ -92,14 +92,14 @@ describe('POST /user/auth/social', () => {
|
||||
|
||||
describe('google', () => {
|
||||
before(async () => {
|
||||
let expectedResult = {id: googleId, displayName: 'a google user'};
|
||||
const expectedResult = { id: googleId, displayName: 'a google user' };
|
||||
sandbox.stub(passport._strategies.google, 'userProfile').yields(null, expectedResult);
|
||||
network = 'google';
|
||||
});
|
||||
|
||||
it('registers a new user', async () => {
|
||||
let response = await api.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
const response = await api.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
@@ -110,13 +110,13 @@ describe('POST /user/auth/social', () => {
|
||||
});
|
||||
|
||||
it('logs an existing user in', async () => {
|
||||
let registerResponse = await api.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
const registerResponse = await api.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
let response = await api.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
const response = await api.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
@@ -126,8 +126,8 @@ describe('POST /user/auth/social', () => {
|
||||
});
|
||||
|
||||
it('add social auth to an existing user', async () => {
|
||||
let response = await user.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
const response = await user.post(endpoint, {
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
@@ -138,7 +138,7 @@ describe('POST /user/auth/social', () => {
|
||||
|
||||
xit('enrolls a new user in an A/B test', async () => {
|
||||
await api.post(endpoint, {
|
||||
authResponse: {access_token: randomAccessToken}, // eslint-disable-line camelcase
|
||||
authResponse: { access_token: randomAccessToken }, // eslint-disable-line camelcase
|
||||
network,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import moment from 'moment';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../../helpers/api-integration/v3';
|
||||
import moment from 'moment';
|
||||
import {
|
||||
decrypt,
|
||||
} from '../../../../../../website/server/libs/encryption';
|
||||
|
||||
describe('POST /user/reset-password', async () => {
|
||||
let endpoint = '/user/reset-password';
|
||||
const endpoint = '/user/reset-password';
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -16,8 +16,8 @@ describe('POST /user/reset-password', async () => {
|
||||
});
|
||||
|
||||
it('resets password', async () => {
|
||||
let previousPassword = user.auth.local.hashed_password;
|
||||
let response = await user.post(endpoint, {
|
||||
const previousPassword = user.auth.local.hashed_password;
|
||||
const response = await user.post(endpoint, {
|
||||
email: user.auth.local.email,
|
||||
});
|
||||
expect(response).to.eql({ data: {}, message: t('passwordReset') });
|
||||
@@ -26,7 +26,7 @@ describe('POST /user/reset-password', async () => {
|
||||
});
|
||||
|
||||
it('same message on error as on success', async () => {
|
||||
let response = await user.post(endpoint, {
|
||||
const response = await user.post(endpoint, {
|
||||
email: 'nonExistent@email.com',
|
||||
});
|
||||
expect(response).to.eql({ data: {}, message: t('passwordReset') });
|
||||
@@ -50,8 +50,8 @@ describe('POST /user/reset-password', async () => {
|
||||
await user.sync();
|
||||
|
||||
expect(user.auth.local.passwordResetCode).to.be.a.string;
|
||||
let decryptedCode = JSON.parse(decrypt(user.auth.local.passwordResetCode));
|
||||
const decryptedCode = JSON.parse(decrypt(user.auth.local.passwordResetCode));
|
||||
expect(decryptedCode.userId).to.equal(user._id);
|
||||
expect(moment(decryptedCode.expiresAt).isAfter(moment().add({hours: 23}))).to.equal(true);
|
||||
expect(moment(decryptedCode.expiresAt).isAfter(moment().add({ hours: 23 }))).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import nconf from 'nconf';
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
@@ -8,13 +9,12 @@ import {
|
||||
sha1Encrypt as sha1EncryptPassword,
|
||||
} from '../../../../../../website/server/libs/password';
|
||||
|
||||
import nconf from 'nconf';
|
||||
|
||||
const ENDPOINT = '/user/auth/update-email';
|
||||
|
||||
describe('PUT /user/auth/update-email', () => {
|
||||
let newEmail = 'SOmE-nEw-emAIl_2@example.net';
|
||||
let oldPassword = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
|
||||
const newEmail = 'SOmE-nEw-emAIl_2@example.net';
|
||||
const oldPassword = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
|
||||
|
||||
context('Local Authenticaion User', async () => {
|
||||
let user;
|
||||
@@ -53,8 +53,8 @@ describe('PUT /user/auth/update-email', () => {
|
||||
});
|
||||
|
||||
it('changes email if new email and existing password are provided', async () => {
|
||||
let lowerCaseNewEmail = newEmail.toLowerCase();
|
||||
let response = await user.put(ENDPOINT, {
|
||||
const lowerCaseNewEmail = newEmail.toLowerCase();
|
||||
const response = await user.put(ENDPOINT, {
|
||||
newEmail,
|
||||
password: oldPassword,
|
||||
});
|
||||
@@ -76,10 +76,10 @@ describe('PUT /user/auth/update-email', () => {
|
||||
});
|
||||
|
||||
it('converts user with SHA1 encrypted password to bcrypt encryption', async () => {
|
||||
let textPassword = 'mySecretPassword';
|
||||
let salt = sha1MakeSalt();
|
||||
let sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
let myNewEmail = 'my-new-random-email@example.net';
|
||||
const textPassword = 'mySecretPassword';
|
||||
const salt = sha1MakeSalt();
|
||||
const sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
const myNewEmail = 'my-new-random-email@example.net';
|
||||
|
||||
await user.update({
|
||||
'auth.local.hashed_password': sha1HashedPassword,
|
||||
@@ -93,7 +93,7 @@ describe('PUT /user/auth/update-email', () => {
|
||||
expect(user.auth.local.hashed_password).to.equal(sha1HashedPassword);
|
||||
|
||||
// update email
|
||||
let response = await user.put(ENDPOINT, {
|
||||
const response = await user.put(ENDPOINT, {
|
||||
newEmail: myNewEmail,
|
||||
password: textPassword,
|
||||
});
|
||||
@@ -106,7 +106,7 @@ describe('PUT /user/auth/update-email', () => {
|
||||
expect(user.auth.local.salt).to.be.undefined;
|
||||
expect(user.auth.local.hashed_password).not.to.equal(sha1HashedPassword);
|
||||
|
||||
let isValidPassword = await bcryptCompare(textPassword, user.auth.local.hashed_password);
|
||||
const isValidPassword = await bcryptCompare(textPassword, user.auth.local.hashed_password);
|
||||
expect(isValidPassword).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,17 +12,17 @@ const ENDPOINT = '/user/auth/update-password';
|
||||
|
||||
describe('PUT /user/auth/update-password', async () => {
|
||||
let user;
|
||||
let password = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
|
||||
let wrongPassword = 'wrong-password';
|
||||
let newPassword = 'new-password';
|
||||
const password = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
|
||||
const wrongPassword = 'wrong-password';
|
||||
const newPassword = 'new-password';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('successfully changes the password', async () => {
|
||||
let previousHashedPassword = user.auth.local.hashed_password;
|
||||
let response = await user.put(ENDPOINT, {
|
||||
const previousHashedPassword = user.auth.local.hashed_password;
|
||||
const response = await user.put(ENDPOINT, {
|
||||
password,
|
||||
newPassword,
|
||||
confirmPassword: newPassword,
|
||||
@@ -57,7 +57,7 @@ describe('PUT /user/auth/update-password', async () => {
|
||||
});
|
||||
|
||||
it('returns an error when password is missing', async () => {
|
||||
let body = {
|
||||
const body = {
|
||||
newPassword,
|
||||
confirmPassword: newPassword,
|
||||
};
|
||||
@@ -70,7 +70,7 @@ describe('PUT /user/auth/update-password', async () => {
|
||||
});
|
||||
|
||||
it('returns an error when newPassword is missing', async () => {
|
||||
let body = {
|
||||
const body = {
|
||||
password,
|
||||
confirmPassword: newPassword,
|
||||
};
|
||||
@@ -83,7 +83,7 @@ describe('PUT /user/auth/update-password', async () => {
|
||||
});
|
||||
|
||||
it('returns an error when confirmPassword is missing', async () => {
|
||||
let body = {
|
||||
const body = {
|
||||
password,
|
||||
newPassword,
|
||||
};
|
||||
@@ -96,9 +96,9 @@ describe('PUT /user/auth/update-password', async () => {
|
||||
});
|
||||
|
||||
it('converts user with SHA1 encrypted password to bcrypt encryption', async () => {
|
||||
let textPassword = 'mySecretPassword';
|
||||
let salt = sha1MakeSalt();
|
||||
let sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
const textPassword = 'mySecretPassword';
|
||||
const salt = sha1MakeSalt();
|
||||
const sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
|
||||
await user.update({
|
||||
'auth.local.hashed_password': sha1HashedPassword,
|
||||
@@ -123,7 +123,7 @@ describe('PUT /user/auth/update-password', async () => {
|
||||
expect(user.auth.local.salt).to.be.undefined;
|
||||
expect(user.auth.local.hashed_password).not.to.equal(sha1HashedPassword);
|
||||
|
||||
let isValidPassword = await bcryptCompare(newPassword, user.auth.local.hashed_password);
|
||||
const isValidPassword = await bcryptCompare(newPassword, user.auth.local.hashed_password);
|
||||
expect(isValidPassword).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,15 +12,15 @@ const ENDPOINT = '/user/auth/update-username';
|
||||
|
||||
describe('PUT /user/auth/update-username', async () => {
|
||||
let user;
|
||||
let password = 'password'; // from habitrpg/test/helpers/api-integration/v4/object-generators.js
|
||||
const password = 'password'; // from habitrpg/test/helpers/api-integration/v4/object-generators.js
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('successfully changes username with password', async () => {
|
||||
let newUsername = 'new-username';
|
||||
let response = await user.put(ENDPOINT, {
|
||||
const newUsername = 'new-username';
|
||||
const response = await user.put(ENDPOINT, {
|
||||
username: newUsername,
|
||||
password,
|
||||
});
|
||||
@@ -30,8 +30,8 @@ describe('PUT /user/auth/update-username', async () => {
|
||||
});
|
||||
|
||||
it('successfully changes username without password', async () => {
|
||||
let newUsername = 'new-username-nopw';
|
||||
let response = await user.put(ENDPOINT, {
|
||||
const newUsername = 'new-username-nopw';
|
||||
const response = await user.put(ENDPOINT, {
|
||||
username: newUsername,
|
||||
});
|
||||
expect(response).to.eql({ username: newUsername });
|
||||
@@ -40,8 +40,8 @@ describe('PUT /user/auth/update-username', async () => {
|
||||
});
|
||||
|
||||
it('successfully changes username containing number and underscore', async () => {
|
||||
let newUsername = 'new_username9';
|
||||
let response = await user.put(ENDPOINT, {
|
||||
const newUsername = 'new_username9';
|
||||
const response = await user.put(ENDPOINT, {
|
||||
username: newUsername,
|
||||
});
|
||||
expect(response).to.eql({ username: newUsername });
|
||||
@@ -52,8 +52,8 @@ describe('PUT /user/auth/update-username', async () => {
|
||||
it('sets verifiedUsername when changing username', async () => {
|
||||
user.flags.verifiedUsername = false;
|
||||
await user.sync();
|
||||
let newUsername = 'new-username-verify';
|
||||
let response = await user.put(ENDPOINT, {
|
||||
const newUsername = 'new-username-verify';
|
||||
const response = await user.put(ENDPOINT, {
|
||||
username: newUsername,
|
||||
});
|
||||
expect(response).to.eql({ username: newUsername });
|
||||
@@ -62,10 +62,10 @@ describe('PUT /user/auth/update-username', async () => {
|
||||
});
|
||||
|
||||
it('converts user with SHA1 encrypted password to bcrypt encryption', async () => {
|
||||
let myNewUsername = 'my-new-username';
|
||||
let textPassword = 'mySecretPassword';
|
||||
let salt = sha1MakeSalt();
|
||||
let sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
const myNewUsername = 'my-new-username';
|
||||
const textPassword = 'mySecretPassword';
|
||||
const salt = sha1MakeSalt();
|
||||
const sha1HashedPassword = sha1EncryptPassword(textPassword, salt);
|
||||
|
||||
await user.update({
|
||||
'auth.local.hashed_password': sha1HashedPassword,
|
||||
@@ -79,7 +79,7 @@ describe('PUT /user/auth/update-username', async () => {
|
||||
expect(user.auth.local.hashed_password).to.equal(sha1HashedPassword);
|
||||
|
||||
// update email
|
||||
let response = await user.put(ENDPOINT, {
|
||||
const response = await user.put(ENDPOINT, {
|
||||
username: myNewUsername,
|
||||
password: textPassword,
|
||||
});
|
||||
@@ -92,14 +92,14 @@ describe('PUT /user/auth/update-username', async () => {
|
||||
expect(user.auth.local.salt).to.be.undefined;
|
||||
expect(user.auth.local.hashed_password).not.to.equal(sha1HashedPassword);
|
||||
|
||||
let isValidPassword = await bcryptCompare(textPassword, user.auth.local.hashed_password);
|
||||
const isValidPassword = await bcryptCompare(textPassword, user.auth.local.hashed_password);
|
||||
expect(isValidPassword).to.equal(true);
|
||||
});
|
||||
|
||||
context('errors', async () => {
|
||||
it('prevents username update if new username is already taken', async () => {
|
||||
let existingUsername = 'existing-username';
|
||||
await generateUser({'auth.local.username': existingUsername, 'auth.local.lowerCaseUsername': existingUsername });
|
||||
const existingUsername = 'existing-username';
|
||||
await generateUser({ 'auth.local.username': existingUsername, 'auth.local.lowerCaseUsername': existingUsername });
|
||||
|
||||
await expect(user.put(ENDPOINT, {
|
||||
username: existingUsername,
|
||||
@@ -112,7 +112,7 @@ describe('PUT /user/auth/update-username', async () => {
|
||||
});
|
||||
|
||||
it('errors if password is wrong', async () => {
|
||||
let newUsername = 'new-username';
|
||||
const newUsername = 'new-username';
|
||||
await expect(user.put(ENDPOINT, {
|
||||
username: newUsername,
|
||||
password: 'wrong-password',
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import shared from '../../../../../../website/common/script';
|
||||
import apiError from '../../../../../../website/server/libs/apiError';
|
||||
|
||||
let content = shared.content;
|
||||
const { content } = shared;
|
||||
|
||||
describe('POST /user/buy/:key', () => {
|
||||
let user;
|
||||
@@ -25,7 +25,7 @@ describe('POST /user/buy/:key', () => {
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: apiError('itemNotFound', {key: 'notExisting'}),
|
||||
message: apiError('itemNotFound', { key: 'notExisting' }),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,13 +35,13 @@ describe('POST /user/buy/:key', () => {
|
||||
'stats.hp': 40,
|
||||
});
|
||||
|
||||
let potion = content.potion;
|
||||
let res = await user.post('/user/buy/potion');
|
||||
const { potion } = content;
|
||||
const res = await user.post('/user/buy/potion');
|
||||
await user.sync();
|
||||
|
||||
expect(user.stats.hp).to.equal(50);
|
||||
expect(res.data).to.eql(user.stats);
|
||||
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
|
||||
expect(res.message).to.equal(t('messageBought', { itemText: potion.text() }));
|
||||
});
|
||||
|
||||
it('returns an error if user tries to buy a potion with full health', async () => {
|
||||
@@ -59,7 +59,7 @@ describe('POST /user/buy/:key', () => {
|
||||
});
|
||||
|
||||
it('buys a piece of gear', async () => {
|
||||
let key = 'armor_warrior_1';
|
||||
const key = 'armor_warrior_1';
|
||||
|
||||
await user.post(`/user/buy/${key}`);
|
||||
await user.sync();
|
||||
@@ -68,11 +68,11 @@ describe('POST /user/buy/:key', () => {
|
||||
});
|
||||
|
||||
it('buys a special spell', async () => {
|
||||
let key = 'spookySparkles';
|
||||
let item = content.special[key];
|
||||
const key = 'spookySparkles';
|
||||
const item = content.special[key];
|
||||
|
||||
await user.update({'stats.gp': 250});
|
||||
let res = await user.post(`/user/buy/${key}`);
|
||||
await user.update({ 'stats.gp': 250 });
|
||||
const res = await user.post(`/user/buy/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(res.data).to.eql({
|
||||
@@ -90,12 +90,12 @@ describe('POST /user/buy/:key', () => {
|
||||
'stats.hp': 20,
|
||||
});
|
||||
|
||||
let potion = content.potion;
|
||||
let res = await user.post('/user/buy/potion', {quantity: 2});
|
||||
const { potion } = content;
|
||||
const res = await user.post('/user/buy/potion', { quantity: 2 });
|
||||
await user.sync();
|
||||
|
||||
expect(user.stats.hp).to.equal(50);
|
||||
expect(res.data).to.eql(user.stats);
|
||||
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
|
||||
expect(res.message).to.equal(t('messageBought', { itemText: potion.text() }));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,12 +21,12 @@ describe('POST /user/buy-gear/:key', () => {
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: apiError('itemNotFound', {key: 'notExisting'}),
|
||||
message: apiError('itemNotFound', { key: 'notExisting' }),
|
||||
});
|
||||
});
|
||||
|
||||
it('buys the first level weapon gear', async () => {
|
||||
let key = 'weapon_warrior_0';
|
||||
const key = 'weapon_warrior_0';
|
||||
|
||||
await user.post(`/user/buy-gear/${key}`);
|
||||
await user.sync();
|
||||
@@ -35,7 +35,7 @@ describe('POST /user/buy-gear/:key', () => {
|
||||
});
|
||||
|
||||
it('buys the first level armor gear', async () => {
|
||||
let key = 'armor_warrior_1';
|
||||
const key = 'armor_warrior_1';
|
||||
|
||||
await user.post(`/user/buy-gear/${key}`);
|
||||
await user.sync();
|
||||
@@ -44,7 +44,7 @@ describe('POST /user/buy-gear/:key', () => {
|
||||
});
|
||||
|
||||
it('tries to buy subsequent, level gear', async () => {
|
||||
let key = 'armor_warrior_2';
|
||||
const key = 'armor_warrior_2';
|
||||
|
||||
return expect(user.post(`/user/buy-gear/${key}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
@@ -55,7 +55,7 @@ describe('POST /user/buy-gear/:key', () => {
|
||||
});
|
||||
|
||||
it('returns an error if tries to buy gear from a different class', async () => {
|
||||
let key = 'armor_rogue_1';
|
||||
const key = 'armor_rogue_1';
|
||||
|
||||
return expect(user.post(`/user/buy-gear/${key}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
} from '../../../../../helpers/api-integration/v3';
|
||||
import shared from '../../../../../../website/common/script';
|
||||
|
||||
let content = shared.content;
|
||||
const { content } = shared;
|
||||
|
||||
describe('POST /user/buy-health-potion', () => {
|
||||
let user;
|
||||
@@ -31,12 +31,12 @@ describe('POST /user/buy-health-potion', () => {
|
||||
'stats.gp': 400,
|
||||
});
|
||||
|
||||
let potion = content.potion;
|
||||
let res = await user.post('/user/buy-health-potion');
|
||||
const { potion } = content;
|
||||
const res = await user.post('/user/buy-health-potion');
|
||||
await user.sync();
|
||||
|
||||
expect(user.stats.hp).to.equal(50);
|
||||
expect(res.data).to.eql(user.stats);
|
||||
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
|
||||
expect(res.message).to.equal(t('messageBought', { itemText: potion.text() }));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,9 +24,9 @@ describe('POST /user/buy-mystery-set/:key', () => {
|
||||
});
|
||||
|
||||
it('buys a mystery set', async () => {
|
||||
let key = 301404;
|
||||
const key = 301404;
|
||||
|
||||
let res = await user.post(`/user/buy-mystery-set/${key}`);
|
||||
const res = await user.post(`/user/buy-mystery-set/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(res.data).to.eql({
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
import shared from '../../../../../../website/common/script';
|
||||
import apiError from '../../../../../../website/server/libs/apiError';
|
||||
|
||||
let content = shared.content;
|
||||
const { content } = shared;
|
||||
|
||||
describe('POST /user/buy-quest/:key', () => {
|
||||
let user;
|
||||
@@ -21,16 +21,16 @@ describe('POST /user/buy-quest/:key', () => {
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: apiError('questNotFound', {key: 'notExisting'}),
|
||||
message: apiError('questNotFound', { key: 'notExisting' }),
|
||||
});
|
||||
});
|
||||
|
||||
it('buys a quest', async () => {
|
||||
let key = 'dilatoryDistress1';
|
||||
let item = content.quests[key];
|
||||
const key = 'dilatoryDistress1';
|
||||
const item = content.quests[key];
|
||||
|
||||
await user.update({'stats.gp': 250});
|
||||
let res = await user.post(`/user/buy-quest/${key}`);
|
||||
await user.update({ 'stats.gp': 250 });
|
||||
const res = await user.post(`/user/buy-quest/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(res.data).to.eql(user.items.quests);
|
||||
@@ -40,13 +40,13 @@ describe('POST /user/buy-quest/:key', () => {
|
||||
});
|
||||
|
||||
it('returns an error if quest prerequisites are not met', async () => {
|
||||
let key = 'dilatoryDistress2';
|
||||
const key = 'dilatoryDistress2';
|
||||
|
||||
await expect(user.post(`/user/buy-quest/${key}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('mustComplete', {quest: 'dilatoryDistress1'}),
|
||||
message: t('mustComplete', { quest: 'dilatoryDistress1' }),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,8 +57,8 @@ describe('POST /user/buy-quest/:key', () => {
|
||||
|
||||
const achievementName = `achievements.quests.${prerequisite}`;
|
||||
|
||||
await user.update({[achievementName]: true, 'stats.gp': 9999});
|
||||
let res = await user.post(`/user/buy-quest/${key}`);
|
||||
await user.update({ [achievementName]: true, 'stats.gp': 9999 });
|
||||
const res = await user.post(`/user/buy-quest/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(res.data).to.eql(user.items.quests);
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
import shared from '../../../../../../website/common/script';
|
||||
import apiError from '../../../../../../website/server/libs/apiError';
|
||||
|
||||
let content = shared.content;
|
||||
const { content } = shared;
|
||||
|
||||
describe('POST /user/buy-special-spell/:key', () => {
|
||||
let user;
|
||||
@@ -21,16 +21,16 @@ describe('POST /user/buy-special-spell/:key', () => {
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: apiError('spellNotFound', {spellId: 'notExisting'}),
|
||||
message: apiError('spellNotFound', { spellId: 'notExisting' }),
|
||||
});
|
||||
});
|
||||
|
||||
it('buys a special spell', async () => {
|
||||
let key = 'thankyou';
|
||||
let item = content.special[key];
|
||||
const key = 'thankyou';
|
||||
const item = content.special[key];
|
||||
|
||||
await user.update({'stats.gp': 250});
|
||||
let res = await user.post(`/user/buy-special-spell/${key}`);
|
||||
await user.update({ 'stats.gp': 250 });
|
||||
const res = await user.post(`/user/buy-special-spell/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(res.data).to.eql({
|
||||
@@ -43,7 +43,7 @@ describe('POST /user/buy-special-spell/:key', () => {
|
||||
});
|
||||
|
||||
it('returns an error if user does not have enough gold', async () => {
|
||||
let key = 'thankyou';
|
||||
const key = 'thankyou';
|
||||
|
||||
await user.update({
|
||||
'stats.gp': 5,
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('POST /user/allocate', () => {
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: apiError('invalidAttribute', {attr: 'invalid'}),
|
||||
message: apiError('invalidAttribute', { attr: 'invalid' }),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('POST /user/allocate', () => {
|
||||
});
|
||||
|
||||
it('returns an error if the user hasn\'t selected class', async () => {
|
||||
await user.update({'flags.classSelected': false});
|
||||
await user.update({ 'flags.classSelected': false });
|
||||
await expect(user.post('/user/allocate'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
@@ -46,8 +46,8 @@ describe('POST /user/allocate', () => {
|
||||
});
|
||||
|
||||
it('allocates attribute points', async () => {
|
||||
await user.update({'stats.points': 1});
|
||||
let res = await user.post('/user/allocate?stat=con');
|
||||
await user.update({ 'stats.points': 1 });
|
||||
const res = await user.post('/user/allocate?stat=con');
|
||||
await user.sync();
|
||||
expect(user.stats.con).to.equal(1);
|
||||
expect(user.stats.points).to.equal(0);
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('POST /user/allocate-bulk', () => {
|
||||
});
|
||||
|
||||
it('returns an error if user has not selected class', async () => {
|
||||
await user.update({'flags.classSelected': false});
|
||||
await user.update({ 'flags.classSelected': false });
|
||||
await expect(user.post('/user/allocate-bulk', statsUpdate))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
@@ -42,7 +42,7 @@ describe('POST /user/allocate-bulk', () => {
|
||||
});
|
||||
|
||||
it('allocates attribute points', async () => {
|
||||
await user.update({'stats.points': 3});
|
||||
await user.update({ 'stats.points': 3 });
|
||||
|
||||
await user.post('/user/allocate-bulk', statsUpdate);
|
||||
await user.sync();
|
||||
|
||||
@@ -6,7 +6,7 @@ describe('POST /user/allocate-now', () => {
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('auto allocates all points', async () => {
|
||||
let user = await generateUser({
|
||||
const user = await generateUser({
|
||||
'stats.points': 5,
|
||||
'stats.int': 3,
|
||||
'stats.con': 9,
|
||||
@@ -15,7 +15,7 @@ describe('POST /user/allocate-now', () => {
|
||||
'preferences.allocationMode': 'flat',
|
||||
});
|
||||
|
||||
let res = await user.post('/user/allocate-now');
|
||||
const res = await user.post('/user/allocate-now');
|
||||
await user.sync();
|
||||
|
||||
expect(res).to.eql(user.stats);
|
||||
|
||||
Reference in New Issue
Block a user