fix test lint

This commit is contained in:
Matteo Pagliazzi
2019-10-08 20:45:38 +02:00
parent e37f4467f8
commit 85fb5f33aa
367 changed files with 6635 additions and 6080 deletions

View File

@@ -1,3 +1,4 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateChallenge,
@@ -6,11 +7,10 @@ import {
checkExistence,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('DELETE /challenges/:challengeId', () => {
it('returns error when challengeId is not a valid UUID', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.del('/challenges/test')).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -19,7 +19,7 @@ describe('DELETE /challenges/:challengeId', () => {
});
it('returns error when challengeId is not for a valid challenge', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.del(`/challenges/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
code: 404,
@@ -32,10 +32,10 @@ describe('DELETE /challenges/:challengeId', () => {
let groupLeader;
let group;
let challenge;
let taskText = 'A challenge task text';
const taskText = 'A challenge task text';
beforeEach(async () => {
let populatedGroup = await createAndPopulateGroup();
const populatedGroup = await createAndPopulateGroup();
groupLeader = populatedGroup.groupLeader;
group = populatedGroup.group;
@@ -44,14 +44,14 @@ describe('DELETE /challenges/:challengeId', () => {
await groupLeader.post(`/challenges/${challenge._id}/join`);
await groupLeader.post(`/tasks/challenge/${challenge._id}`, [
{type: 'habit', text: taskText},
{ type: 'habit', text: taskText },
]);
await challenge.sync();
});
it('returns an error when user doesn\'t have permissions to delete the challenge', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.del(`/challenges/${challenge._id}`)).to.eventually.be.rejected.and.eql({
code: 401,
@@ -69,7 +69,7 @@ describe('DELETE /challenges/:challengeId', () => {
});
it('refunds gems to group leader', async () => {
let oldBalance = (await groupLeader.sync()).balance;
const oldBalance = (await groupLeader.sync()).balance;
await groupLeader.del(`/challenges/${challenge._id}`);
@@ -83,10 +83,8 @@ describe('DELETE /challenges/:challengeId', () => {
await sleep(0.5);
let tasks = await groupLeader.get('/tasks/user');
let testTask = _.find(tasks, (task) => {
return task.text === taskText;
});
const tasks = await groupLeader.get('/tasks/user');
const testTask = _.find(tasks, task => task.text === taskText);
expect(testTask.challenge.broken).to.eql('CHALLENGE_DELETED');
expect(testTask.challenge.winner).to.be.null;

View File

@@ -1,14 +1,14 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
createAndPopulateGroup,
generateChallenge,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('GET /challenges/:challengeId', () => {
it('fails if challenge doesn\'t exists', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.get(`/challenges/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
@@ -25,8 +25,8 @@ describe('GET /challenges/:challengeId', () => {
beforeEach(async () => {
user = await generateUser();
let populatedGroup = await createAndPopulateGroup({
groupDetails: {type: 'guild', privacy: 'public'},
const populatedGroup = await createAndPopulateGroup({
groupDetails: { type: 'guild', privacy: 'public' },
});
groupLeader = populatedGroup.groupLeader;
@@ -38,7 +38,7 @@ describe('GET /challenges/:challengeId', () => {
it('should return challenge data', async () => {
await challenge.sync();
let chal = await user.get(`/challenges/${challenge._id}`);
const chal = await user.get(`/challenges/${challenge._id}`);
expect(chal.memberCount).to.equal(challenge.memberCount);
expect(chal.name).to.equal(challenge.name);
expect(chal._id).to.equal(challenge._id);
@@ -46,7 +46,7 @@ describe('GET /challenges/:challengeId', () => {
expect(chal.leader).to.eql({
_id: groupLeader._id,
id: groupLeader._id,
profile: {name: groupLeader.profile.name},
profile: { name: groupLeader.profile.name },
auth: {
local: {
username: groupLeader.auth.local.username,
@@ -81,8 +81,8 @@ describe('GET /challenges/:challengeId', () => {
beforeEach(async () => {
nonMember = await generateUser();
let populatedGroup = await createAndPopulateGroup({
groupDetails: {type: 'guild', privacy: 'private'},
const populatedGroup = await createAndPopulateGroup({
groupDetails: { type: 'guild', privacy: 'private' },
members: 2,
});
@@ -90,8 +90,8 @@ describe('GET /challenges/:challengeId', () => {
group = populatedGroup.group;
members = populatedGroup.members;
challengeLeader = members[0];
otherMember = members[1];
challengeLeader = members[0]; // eslint-disable-line prefer-destructuring
otherMember = members[1]; // eslint-disable-line prefer-destructuring
challenge = await generateChallenge(challengeLeader, group);
});
@@ -105,14 +105,14 @@ describe('GET /challenges/:challengeId', () => {
});
it('returns challenge data for any user in the guild', async () => {
let chal = await otherMember.get(`/challenges/${challenge._id}`);
const chal = await otherMember.get(`/challenges/${challenge._id}`);
expect(chal.name).to.equal(challenge.name);
expect(chal._id).to.equal(challenge._id);
expect(chal.leader).to.eql({
_id: challengeLeader._id,
id: challengeLeader._id,
profile: {name: challengeLeader.profile.name},
profile: { name: challengeLeader.profile.name },
auth: {
local: {
username: challengeLeader.auth.local.username,
@@ -139,14 +139,14 @@ describe('GET /challenges/:challengeId', () => {
await challengeLeader.sync();
expect(challengeLeader.guilds).to.be.empty; // check that leaving worked
let chal = await challengeLeader.get(`/challenges/${challenge._id}`);
const chal = await challengeLeader.get(`/challenges/${challenge._id}`);
expect(chal.name).to.equal(challenge.name);
expect(chal._id).to.equal(challenge._id);
expect(chal.leader).to.eql({
_id: challengeLeader._id,
id: challengeLeader._id,
profile: {name: challengeLeader.profile.name},
profile: { name: challengeLeader.profile.name },
auth: {
local: {
username: challengeLeader.auth.local.username,
@@ -171,8 +171,8 @@ describe('GET /challenges/:challengeId', () => {
beforeEach(async () => {
nonMember = await generateUser();
let populatedGroup = await createAndPopulateGroup({
groupDetails: {type: 'party', privacy: 'private'},
const populatedGroup = await createAndPopulateGroup({
groupDetails: { type: 'party', privacy: 'private' },
members: 2,
});
@@ -180,8 +180,8 @@ describe('GET /challenges/:challengeId', () => {
group = populatedGroup.group;
members = populatedGroup.members;
challengeLeader = members[0];
otherMember = members[1];
challengeLeader = members[0]; // eslint-disable-line prefer-destructuring
otherMember = members[1]; // eslint-disable-line prefer-destructuring
challenge = await generateChallenge(challengeLeader, group);
});
@@ -195,14 +195,14 @@ describe('GET /challenges/:challengeId', () => {
});
it('returns challenge data for any user in the party', async () => {
let chal = await otherMember.get(`/challenges/${challenge._id}`);
const chal = await otherMember.get(`/challenges/${challenge._id}`);
expect(chal.name).to.equal(challenge.name);
expect(chal._id).to.equal(challenge._id);
expect(chal.leader).to.eql({
_id: challengeLeader._id,
id: challengeLeader._id,
profile: {name: challengeLeader.profile.name},
profile: { name: challengeLeader.profile.name },
auth: {
local: {
username: challengeLeader.auth.local.username,
@@ -229,14 +229,14 @@ describe('GET /challenges/:challengeId', () => {
await challengeLeader.sync();
expect(challengeLeader.party._id).to.be.undefined; // check that leaving worked
let chal = await challengeLeader.get(`/challenges/${challenge._id}`);
const chal = await challengeLeader.get(`/challenges/${challenge._id}`);
expect(chal.name).to.equal(challenge.name);
expect(chal._id).to.equal(challenge._id);
expect(chal.leader).to.eql({
_id: challengeLeader._id,
id: challengeLeader._id,
profile: {name: challengeLeader.profile.name},
profile: { name: challengeLeader.profile.name },
auth: {
local: {
username: challengeLeader.auth.local.username,

View File

@@ -1,3 +1,4 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
createAndPopulateGroup,
@@ -5,7 +6,6 @@ import {
translate as t,
sleep,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('GET /challenges/:challengeId/export/csv', () => {
let groupLeader;
@@ -15,7 +15,7 @@ describe('GET /challenges/:challengeId/export/csv', () => {
let user;
beforeEach(async () => {
let populatedGroup = await createAndPopulateGroup({
const populatedGroup = await createAndPopulateGroup({
members: 3,
});
@@ -30,8 +30,8 @@ describe('GET /challenges/:challengeId/export/csv', () => {
await members[2].post(`/challenges/${challenge._id}/join`);
await groupLeader.post(`/tasks/challenge/${challenge._id}`, [
{type: 'habit', text: 'Task 1'},
{type: 'todo', text: 'Task 2'},
{ type: 'habit', text: 'Task 1' },
{ type: 'todo', text: 'Task 2' },
]);
await sleep(0.5); // Make sure tasks are synced to the users
await members[0].sync();
@@ -74,7 +74,7 @@ describe('GET /challenges/:challengeId/export/csv', () => {
});
it('should successfully return when it contains erroneous residue user data', async () => {
await members[0].update({challenges: []});
await members[0].update({ challenges: [] });
const res = await members[1].get(`/challenges/${challenge._id}/export/csv`);
const sortedMembers = _.sortBy([members[1], members[2], groupLeader], '_id');
const splitRes = res.split('\n');

View File

@@ -1,3 +1,4 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateGroup,
@@ -5,7 +6,6 @@ import {
generateChallenge,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('GET /challenges/:challengeId/members', () => {
let user;
@@ -31,9 +31,9 @@ describe('GET /challenges/:challengeId/members', () => {
});
it('fails if user isn\'t in the private group and isn\'t challenge leader', async () => {
let group = await generateGroup(user, {type: 'party', privacy: 'private'});
let challenge = await generateChallenge(user, group);
let anotherUser = await generateUser();
const group = await generateGroup(user, { type: 'party', privacy: 'private' });
const challenge = await generateChallenge(user, group);
const anotherUser = await generateUser();
await expect(anotherUser.get(`/challenges/${challenge._id}/members`)).to.eventually.be.rejected.and.eql({
code: 404,
@@ -43,23 +43,23 @@ describe('GET /challenges/:challengeId/members', () => {
});
it('works if user isn\'t in the private group but is challenge leader', async () => {
let populatedGroup = await createAndPopulateGroup({
groupDetails: {type: 'party', privacy: 'private'},
const populatedGroup = await createAndPopulateGroup({
groupDetails: { type: 'party', privacy: 'private' },
members: 1,
});
let groupLeader = populatedGroup.groupLeader;
let challengeLeader = populatedGroup.members[0];
let challenge = await generateChallenge(challengeLeader, populatedGroup.group);
const { groupLeader } = populatedGroup;
const challengeLeader = populatedGroup.members[0];
const challenge = await generateChallenge(challengeLeader, populatedGroup.group);
await groupLeader.post(`/challenges/${challenge._id}/join`);
await challengeLeader.post('/groups/party/leave');
await challengeLeader.sync();
expect(challengeLeader.party._id).to.be.undefined; // check that leaving worked
let res = await challengeLeader.get(`/challenges/${challenge._id}/members`);
const res = await challengeLeader.get(`/challenges/${challenge._id}/members`);
expect(res[0]).to.eql({
_id: groupLeader._id,
id: groupLeader._id,
profile: {name: groupLeader.profile.name},
profile: { name: groupLeader.profile.name },
auth: {
local: {
username: groupLeader.auth.local.username,
@@ -72,15 +72,15 @@ describe('GET /challenges/:challengeId/members', () => {
});
it('works with challenges belonging to public guild', async () => {
let leader = await generateUser({balance: 4});
let group = await generateGroup(leader, {type: 'guild', privacy: 'public', name: generateUUID()});
let challenge = await generateChallenge(leader, group);
const leader = await generateUser({ balance: 4 });
const group = await generateGroup(leader, { type: 'guild', privacy: 'public', name: generateUUID() });
const challenge = await generateChallenge(leader, group);
await leader.post(`/challenges/${challenge._id}/join`);
let res = await user.get(`/challenges/${challenge._id}/members`);
const res = await user.get(`/challenges/${challenge._id}/members`);
expect(res[0]).to.eql({
_id: leader._id,
id: leader._id,
profile: {name: leader.profile.name},
profile: { name: leader.profile.name },
auth: {
local: {
username: leader.auth.local.username,
@@ -95,15 +95,15 @@ describe('GET /challenges/:challengeId/members', () => {
});
it('populates only some fields', async () => {
let anotherUser = await generateUser({balance: 3});
let group = await generateGroup(anotherUser, {type: 'guild', privacy: 'public', name: generateUUID()});
let challenge = await generateChallenge(anotherUser, group);
const anotherUser = await generateUser({ balance: 3 });
const group = await generateGroup(anotherUser, { type: 'guild', privacy: 'public', name: generateUUID() });
const challenge = await generateChallenge(anotherUser, group);
await anotherUser.post(`/challenges/${challenge._id}/join`);
let res = await user.get(`/challenges/${challenge._id}/members`);
const res = await user.get(`/challenges/${challenge._id}/members`);
expect(res[0]).to.eql({
_id: anotherUser._id,
id: anotherUser._id,
profile: {name: anotherUser.profile.name},
profile: { name: anotherUser.profile.name },
auth: {
local: {
username: anotherUser.auth.local.username,
@@ -118,17 +118,17 @@ describe('GET /challenges/:challengeId/members', () => {
});
it('returns only first 30 members if req.query.includeAllMembers is not true', async () => {
let group = await generateGroup(user, {type: 'party', name: generateUUID()});
let challenge = await generateChallenge(user, group);
const group = await generateGroup(user, { type: 'party', name: generateUUID() });
const challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
let usersToGenerate = [];
for (let i = 0; i < 31; i++) {
usersToGenerate.push(generateUser({challenges: [challenge._id]}));
const usersToGenerate = [];
for (let i = 0; i < 31; i += 1) {
usersToGenerate.push(generateUser({ challenges: [challenge._id] }));
}
await Promise.all(usersToGenerate);
let res = await user.get(`/challenges/${challenge._id}/members?includeAllMembers=not-true`);
const res = await user.get(`/challenges/${challenge._id}/members?includeAllMembers=not-true`);
expect(res.length).to.equal(30);
res.forEach(member => {
expect(member).to.have.all.keys(['_id', 'auth', 'flags', 'id', 'profile']);
@@ -137,17 +137,17 @@ describe('GET /challenges/:challengeId/members', () => {
});
it('returns only first 30 members if req.query.includeAllMembers is not defined', async () => {
let group = await generateGroup(user, {type: 'party', name: generateUUID()});
let challenge = await generateChallenge(user, group);
const group = await generateGroup(user, { type: 'party', name: generateUUID() });
const challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
let usersToGenerate = [];
for (let i = 0; i < 31; i++) {
usersToGenerate.push(generateUser({challenges: [challenge._id]}));
const usersToGenerate = [];
for (let i = 0; i < 31; i += 1) {
usersToGenerate.push(generateUser({ challenges: [challenge._id] }));
}
await Promise.all(usersToGenerate);
let res = await user.get(`/challenges/${challenge._id}/members`);
const res = await user.get(`/challenges/${challenge._id}/members`);
expect(res.length).to.equal(30);
res.forEach(member => {
expect(member).to.have.all.keys(['_id', 'auth', 'flags', 'id', 'profile']);
@@ -156,17 +156,17 @@ describe('GET /challenges/:challengeId/members', () => {
});
it('returns all members if req.query.includeAllMembers is true', async () => {
let group = await generateGroup(user, {type: 'party', name: generateUUID()});
let challenge = await generateChallenge(user, group);
const group = await generateGroup(user, { type: 'party', name: generateUUID() });
const challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
let usersToGenerate = [];
for (let i = 0; i < 31; i++) {
usersToGenerate.push(generateUser({challenges: [challenge._id]}));
const usersToGenerate = [];
for (let i = 0; i < 31; i += 1) {
usersToGenerate.push(generateUser({ challenges: [challenge._id] }));
}
await Promise.all(usersToGenerate);
let res = await user.get(`/challenges/${challenge._id}/members?includeAllMembers=true`);
const res = await user.get(`/challenges/${challenge._id}/members?includeAllMembers=true`);
expect(res.length).to.equal(32);
res.forEach(member => {
expect(member).to.have.all.keys(['_id', 'auth', 'flags', 'id', 'profile']);
@@ -174,47 +174,48 @@ describe('GET /challenges/:challengeId/members', () => {
});
});
it('supports using req.query.lastId to get more members', async function () {
it('supports using req.query.lastId to get more members', async function test () {
this.timeout(30000); // @TODO: times out after 8 seconds
let group = await generateGroup(user, {type: 'party', name: generateUUID()});
let challenge = await generateChallenge(user, group);
const group = await generateGroup(user, { type: 'party', name: generateUUID() });
const challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
let usersToGenerate = [];
for (let i = 0; i < 57; i++) {
usersToGenerate.push(generateUser({challenges: [challenge._id]}));
const usersToGenerate = [];
for (let i = 0; i < 57; i += 1) {
usersToGenerate.push(generateUser({ challenges: [challenge._id] }));
}
let generatedUsers = await Promise.all(usersToGenerate); // Group has 59 members (1 is the leader)
let expectedIds = [user._id].concat(generatedUsers.map(generatedUser => generatedUser._id));
// Group has 59 members (1 is the leader)
const generatedUsers = await Promise.all(usersToGenerate);
const expectedIds = [user._id].concat(generatedUsers.map(generatedUser => generatedUser._id));
let res = await user.get(`/challenges/${challenge._id}/members`);
const res = await user.get(`/challenges/${challenge._id}/members`);
expect(res.length).to.equal(30);
let res2 = await user.get(`/challenges/${challenge._id}/members?lastId=${res[res.length - 1]._id}`);
const res2 = await user.get(`/challenges/${challenge._id}/members?lastId=${res[res.length - 1]._id}`);
expect(res2.length).to.equal(28);
let resIds = res.concat(res2).map(member => member._id);
const resIds = res.concat(res2).map(member => member._id);
expect(resIds).to.eql(expectedIds.sort());
});
it('supports using req.query.search to get search members', async () => {
let group = await generateGroup(user, {type: 'party', name: generateUUID()});
let challenge = await generateChallenge(user, group);
const group = await generateGroup(user, { type: 'party', name: generateUUID() });
const challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
let usersToGenerate = [];
for (let i = 0; i < 3; i++) {
const usersToGenerate = [];
for (let i = 0; i < 3; i += 1) {
usersToGenerate.push(generateUser({
challenges: [challenge._id],
'profile.name': `${i}profilename`,
}));
}
let generatedUsers = await Promise.all(usersToGenerate);
let profileNames = generatedUsers.map(generatedUser => generatedUser.profile.name);
const generatedUsers = await Promise.all(usersToGenerate);
const profileNames = generatedUsers.map(generatedUser => generatedUser.profile.name);
let firstProfileName = profileNames[0];
let nameToSearch = firstProfileName.substring(0, 4);
const firstProfileName = profileNames[0];
const nameToSearch = firstProfileName.substring(0, 4);
let response = await user.get(`/challenges/${challenge._id}/members?search=${nameToSearch}`);
const response = await user.get(`/challenges/${challenge._id}/members?search=${nameToSearch}`);
expect(response[0].profile.name).to.eql(firstProfileName);
});
});

View File

@@ -1,10 +1,10 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateChallenge,
generateGroup,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('GET /challenges/:challengeId/members/:memberId', () => {
let user;
@@ -30,16 +30,16 @@ describe('GET /challenges/:challengeId/members/:memberId', () => {
});
it('fails if member doesn\'t exists', async () => {
let userId = generateUUID();
const userId = generateUUID();
await expect(user.get(`/challenges/${generateUUID()}/members/${userId}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('userWithIDNotFound', {userId}),
message: t('userWithIDNotFound', { userId }),
});
});
it('fails if challenge doesn\'t exists', async () => {
let member = await generateUser();
const member = await generateUser();
await expect(user.get(`/challenges/${generateUUID()}/members/${member._id}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
@@ -48,11 +48,11 @@ describe('GET /challenges/:challengeId/members/:memberId', () => {
});
it('fails if user doesn\'t have access to the challenge', async () => {
let group = await generateGroup(user, {type: 'party', name: generateUUID()});
let challenge = await generateChallenge(user, group);
const group = await generateGroup(user, { type: 'party', name: generateUUID() });
const challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
let anotherUser = await generateUser();
let member = await generateUser();
const anotherUser = await generateUser();
const member = await generateUser();
await expect(anotherUser.get(`/challenges/${challenge._id}/members/${member._id}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
@@ -61,10 +61,10 @@ describe('GET /challenges/:challengeId/members/:memberId', () => {
});
it('fails if member is not part of the challenge', async () => {
let group = await generateGroup(user, {type: 'party', name: generateUUID()});
let challenge = await generateChallenge(user, group);
const group = await generateGroup(user, { type: 'party', name: generateUUID() });
const challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
let member = await generateUser();
const member = await generateUser();
await expect(user.get(`/challenges/${challenge._id}/members/${member._id}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
@@ -73,37 +73,37 @@ describe('GET /challenges/:challengeId/members/:memberId', () => {
});
it('works with challenges belonging to a public guild', async () => {
let groupLeader = await generateUser({balance: 4});
let group = await generateGroup(groupLeader, {type: 'guild', privacy: 'public', name: generateUUID()});
let challenge = await generateChallenge(groupLeader, group);
const groupLeader = await generateUser({ balance: 4 });
const group = await generateGroup(groupLeader, { type: 'guild', privacy: 'public', name: generateUUID() });
const challenge = await generateChallenge(groupLeader, group);
await groupLeader.post(`/challenges/${challenge._id}/join`);
let taskText = 'Test Text';
await groupLeader.post(`/tasks/challenge/${challenge._id}`, [{type: 'habit', text: taskText}]);
const taskText = 'Test Text';
await groupLeader.post(`/tasks/challenge/${challenge._id}`, [{ type: 'habit', text: taskText }]);
let memberProgress = await user.get(`/challenges/${challenge._id}/members/${groupLeader._id}`);
const memberProgress = await user.get(`/challenges/${challenge._id}/members/${groupLeader._id}`);
expect(memberProgress).to.have.all.keys(['_id', 'auth', 'flags', 'id', 'profile', 'tasks']);
expect(memberProgress.profile).to.have.all.keys(['name']);
expect(memberProgress.tasks.length).to.equal(1);
});
it('returns the member tasks for the challenges', async () => {
let group = await generateGroup(user, {type: 'party', name: generateUUID()});
let challenge = await generateChallenge(user, group);
const group = await generateGroup(user, { type: 'party', name: generateUUID() });
const challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
await user.post(`/tasks/challenge/${challenge._id}`, [{type: 'habit', text: 'Test Text'}]);
await user.post(`/tasks/challenge/${challenge._id}`, [{ type: 'habit', text: 'Test Text' }]);
let memberProgress = await user.get(`/challenges/${challenge._id}/members/${user._id}`);
let chalTasks = await user.get(`/tasks/challenge/${challenge._id}`);
const memberProgress = await user.get(`/challenges/${challenge._id}/members/${user._id}`);
const chalTasks = await user.get(`/tasks/challenge/${challenge._id}`);
expect(memberProgress.tasks.length).to.equal(chalTasks.length);
expect(memberProgress.tasks[0].challenge.id).to.equal(challenge._id);
expect(memberProgress.tasks[0].challenge.taskId).to.equal(chalTasks[0]._id);
});
it('returns the tasks without the tags and checklist', async () => {
let group = await generateGroup(user, {type: 'party', name: generateUUID()});
let challenge = await generateChallenge(user, group);
const group = await generateGroup(user, { type: 'party', name: generateUUID() });
const challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
let taskText = 'Test Text';
const taskText = 'Test Text';
await user.post(`/tasks/challenge/${challenge._id}`, [{
type: 'todo',
text: taskText,
@@ -115,7 +115,7 @@ describe('GET /challenges/:challengeId/members/:memberId', () => {
],
}]);
let memberProgress = await user.get(`/challenges/${challenge._id}/members/${user._id}`);
const memberProgress = await user.get(`/challenges/${challenge._id}/members/${user._id}`);
expect(memberProgress.tasks[0]).not.to.have.key('tags');
expect(memberProgress.tasks[0].checklist).to.eql([]);
});

View File

@@ -8,10 +8,11 @@ import { TAVERN_ID } from '../../../../../website/common/script/constants';
describe('GET challenges/groups/:groupId', () => {
context('Public Guild', () => {
let publicGuild, user, nonMember, challenge, challenge2;
let publicGuild; let user; let nonMember; let challenge; let
challenge2;
before(async () => {
let { group, groupLeader } = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'TestGuild',
type: 'guild',
@@ -31,14 +32,14 @@ describe('GET challenges/groups/:groupId', () => {
});
it('should return group challenges for non member with populated leader', async () => {
let challenges = await nonMember.get(`/challenges/groups/${publicGuild._id}`);
const challenges = await nonMember.get(`/challenges/groups/${publicGuild._id}`);
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: publicGuild.leader._id,
id: publicGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -48,12 +49,12 @@ describe('GET challenges/groups/:groupId', () => {
verifiedUsername: true,
},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: publicGuild.leader._id,
id: publicGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -66,14 +67,14 @@ describe('GET challenges/groups/:groupId', () => {
});
it('should return group challenges for member with populated leader', async () => {
let challenges = await user.get(`/challenges/groups/${publicGuild._id}`);
const challenges = await user.get(`/challenges/groups/${publicGuild._id}`);
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: publicGuild.leader._id,
id: publicGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -83,12 +84,12 @@ describe('GET challenges/groups/:groupId', () => {
verifiedUsername: true,
},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: publicGuild.leader._id,
id: publicGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -106,7 +107,7 @@ describe('GET challenges/groups/:groupId', () => {
let foundChallengeIndex = _.findIndex(challenges, { _id: challenge2._id });
expect(foundChallengeIndex).to.eql(0);
let newChallenge = await generateChallenge(user, publicGuild);
const newChallenge = await generateChallenge(user, publicGuild);
await user.post(`/challenges/${newChallenge._id}/join`);
challenges = await user.get(`/challenges/groups/${publicGuild._id}`);
@@ -117,10 +118,11 @@ describe('GET challenges/groups/:groupId', () => {
});
context('Private Guild', () => {
let privateGuild, user, nonMember, challenge, challenge2;
let privateGuild; let user; let nonMember; let challenge; let
challenge2;
before(async () => {
let { group, groupLeader } = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'TestPrivateGuild',
type: 'guild',
@@ -149,14 +151,14 @@ describe('GET challenges/groups/:groupId', () => {
});
it('should return group challenges for member with populated leader', async () => {
let challenges = await user.get(`/challenges/groups/${privateGuild._id}`);
const challenges = await user.get(`/challenges/groups/${privateGuild._id}`);
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: privateGuild.leader._id,
id: privateGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -166,12 +168,12 @@ describe('GET challenges/groups/:groupId', () => {
verifiedUsername: true,
},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: privateGuild.leader._id,
id: privateGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -185,10 +187,11 @@ describe('GET challenges/groups/:groupId', () => {
});
context('official challenge is present', () => {
let publicGuild, user, officialChallenge, challenge, challenge2;
let publicGuild; let user; let officialChallenge; let challenge; let
challenge2;
before(async () => {
let { group, groupLeader } = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'TestGuild',
type: 'guild',
@@ -218,9 +221,9 @@ describe('GET challenges/groups/:groupId', () => {
});
it('should return official challenges first', async () => {
let challenges = await user.get(`/challenges/groups/${publicGuild._id}`);
const challenges = await user.get(`/challenges/groups/${publicGuild._id}`);
let foundChallengeIndex = _.findIndex(challenges, { _id: officialChallenge._id });
const foundChallengeIndex = _.findIndex(challenges, { _id: officialChallenge._id });
expect(foundChallengeIndex).to.eql(0);
});
@@ -233,7 +236,7 @@ describe('GET challenges/groups/:groupId', () => {
foundChallengeIndex = _.findIndex(challenges, { _id: challenge2._id });
expect(foundChallengeIndex).to.eql(1);
let newChallenge = await generateChallenge(user, publicGuild);
const newChallenge = await generateChallenge(user, publicGuild);
await user.post(`/challenges/${newChallenge._id}/join`);
challenges = await user.get(`/challenges/groups/${publicGuild._id}`);
@@ -244,10 +247,11 @@ describe('GET challenges/groups/:groupId', () => {
});
context('Party', () => {
let party, user, nonMember, challenge, challenge2;
let party; let user; let nonMember; let challenge; let
challenge2;
before(async () => {
let { group, groupLeader } = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'TestParty',
type: 'party',
@@ -275,14 +279,14 @@ describe('GET challenges/groups/:groupId', () => {
});
it('should return group challenges for member with populated leader', async () => {
let challenges = await user.get(`/challenges/groups/${party._id}`);
const challenges = await user.get(`/challenges/groups/${party._id}`);
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: party.leader._id,
id: party.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -292,12 +296,12 @@ describe('GET challenges/groups/:groupId', () => {
verifiedUsername: true,
},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: party.leader._id,
id: party.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -310,14 +314,14 @@ describe('GET challenges/groups/:groupId', () => {
});
it('should return group challenges for member using ID "party"', async () => {
let challenges = await user.get('/challenges/groups/party');
const challenges = await user.get('/challenges/groups/party');
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: party.leader._id,
id: party.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -327,12 +331,12 @@ describe('GET challenges/groups/:groupId', () => {
verifiedUsername: true,
},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: party.leader._id,
id: party.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -346,28 +350,29 @@ describe('GET challenges/groups/:groupId', () => {
});
context('Tavern', () => {
let tavern, user, challenge, challenge2;
let tavern; let user; let challenge; let
challenge2;
before(async () => {
user = await generateUser();
await user.update({balance: 0.5});
await user.update({ balance: 0.5 });
tavern = await user.get(`/groups/${TAVERN_ID}`);
challenge = await generateChallenge(user, tavern, {prize: 1});
challenge = await generateChallenge(user, tavern, { prize: 1 });
await user.post(`/challenges/${challenge._id}/join`);
challenge2 = await generateChallenge(user, tavern, {prize: 1});
challenge2 = await generateChallenge(user, tavern, { prize: 1 });
await user.post(`/challenges/${challenge2._id}/join`);
});
it('should return tavern challenges with populated leader', async () => {
let challenges = await user.get(`/challenges/groups/${TAVERN_ID}`);
const challenges = await user.get(`/challenges/groups/${TAVERN_ID}`);
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: user._id,
id: user._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -377,12 +382,12 @@ describe('GET challenges/groups/:groupId', () => {
verifiedUsername: true,
},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: user._id,
id: user._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -395,14 +400,14 @@ describe('GET challenges/groups/:groupId', () => {
});
it('should return tavern challenges using ID "habitrpg', async () => {
let challenges = await user.get('/challenges/groups/habitrpg');
const challenges = await user.get('/challenges/groups/habitrpg');
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: user._id,
id: user._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -412,12 +417,12 @@ describe('GET challenges/groups/:groupId', () => {
verifiedUsername: true,
},
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: user._id,
id: user._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,

View File

@@ -6,10 +6,11 @@ import {
describe('GET challenges/user', () => {
context('no official challenges', () => {
let user, member, nonMember, challenge, challenge2, publicGuild;
let user; let member; let nonMember; let challenge; let challenge2; let
publicGuild;
before(async () => {
let { group, groupLeader, members } = await createAndPopulateGroup({
const { group, groupLeader, members } = await createAndPopulateGroup({
groupDetails: {
name: 'TestGuild',
type: 'guild',
@@ -20,7 +21,7 @@ describe('GET challenges/user', () => {
user = groupLeader;
publicGuild = group;
member = members[0];
member = members[0]; // eslint-disable-line prefer-destructuring
nonMember = await generateUser();
challenge = await generateChallenge(user, group);
@@ -32,14 +33,14 @@ describe('GET challenges/user', () => {
it('should return challenges user has joined', async () => {
await nonMember.post(`/challenges/${challenge._id}/join`);
let challenges = await nonMember.get('/challenges/user');
const challenges = await nonMember.get('/challenges/user');
let foundChallenge = _.find(challenges, { _id: challenge._id });
const foundChallenge = _.find(challenges, { _id: challenge._id });
expect(foundChallenge).to.exist;
expect(foundChallenge.leader).to.eql({
_id: publicGuild.leader._id,
id: publicGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -62,14 +63,14 @@ describe('GET challenges/user', () => {
});
it('should return challenges user has created', async () => {
let challenges = await user.get('/challenges/user');
const challenges = await user.get('/challenges/user');
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: publicGuild.leader._id,
id: publicGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -89,12 +90,12 @@ describe('GET challenges/user', () => {
summary: publicGuild.name,
leader: publicGuild.leader._id,
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: publicGuild.leader._id,
id: publicGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -117,14 +118,14 @@ describe('GET challenges/user', () => {
});
it('should return challenges in user\'s group', async () => {
let challenges = await member.get('/challenges/user');
const challenges = await member.get('/challenges/user');
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.exist;
expect(foundChallenge1.leader).to.eql({
_id: publicGuild.leader._id,
id: publicGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -144,12 +145,12 @@ describe('GET challenges/user', () => {
summary: publicGuild.name,
leader: publicGuild.leader._id,
});
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.exist;
expect(foundChallenge2.leader).to.eql({
_id: publicGuild.leader._id,
id: publicGuild.leader._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,
@@ -172,12 +173,12 @@ describe('GET challenges/user', () => {
});
it('should not return challenges in user groups if we send member true param', async () => {
let challenges = await member.get(`/challenges/user?member=${true}`);
const challenges = await member.get(`/challenges/user?member=${true}`);
let foundChallenge1 = _.find(challenges, { _id: challenge._id });
const foundChallenge1 = _.find(challenges, { _id: challenge._id });
expect(foundChallenge1).to.not.exist;
let foundChallenge2 = _.find(challenges, { _id: challenge2._id });
const foundChallenge2 = _.find(challenges, { _id: challenge2._id });
expect(foundChallenge2).to.not.exist;
});
@@ -187,7 +188,7 @@ describe('GET challenges/user', () => {
let foundChallengeIndex = _.findIndex(challenges, { _id: challenge2._id });
expect(foundChallengeIndex).to.eql(0);
let newChallenge = await generateChallenge(user, publicGuild);
const newChallenge = await generateChallenge(user, publicGuild);
await user.post(`/challenges/${newChallenge._id}/join`);
challenges = await user.get('/challenges/user');
@@ -197,7 +198,7 @@ describe('GET challenges/user', () => {
});
it('should not return challenges user doesn\'t have access to', async () => {
let { group, groupLeader } = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'TestPrivateGuild',
summary: 'summary for TestPrivateGuild',
@@ -206,17 +207,17 @@ describe('GET challenges/user', () => {
},
});
let privateChallenge = await generateChallenge(groupLeader, group);
const privateChallenge = await generateChallenge(groupLeader, group);
await groupLeader.post(`/challenges/${privateChallenge._id}/join`);
let challenges = await nonMember.get('/challenges/user');
const challenges = await nonMember.get('/challenges/user');
let foundChallenge = _.find(challenges, { _id: privateChallenge._id });
const foundChallenge = _.find(challenges, { _id: privateChallenge._id });
expect(foundChallenge).to.not.exist;
});
it('should not return challenges user doesn\'t have access to, even with query parameters', async () => {
let { group, groupLeader } = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'TestPrivateGuild',
summary: 'summary for TestPrivateGuild',
@@ -225,24 +226,27 @@ describe('GET challenges/user', () => {
},
});
let privateChallenge = await generateChallenge(groupLeader, group, {categories: [{
name: 'academics',
slug: 'academics',
}]});
const privateChallenge = await generateChallenge(groupLeader, group, {
categories: [{
name: 'academics',
slug: 'academics',
}],
});
await groupLeader.post(`/challenges/${privateChallenge._id}/join`);
let challenges = await nonMember.get('/challenges/user?categories=academics&owned=not_owned');
const challenges = await nonMember.get('/challenges/user?categories=academics&owned=not_owned');
let foundChallenge = _.find(challenges, { _id: privateChallenge._id });
const foundChallenge = _.find(challenges, { _id: privateChallenge._id });
expect(foundChallenge).to.not.exist;
});
});
context('official challenge is present', () => {
let user, officialChallenge, challenge, challenge2, publicGuild;
let user; let officialChallenge; let challenge; let challenge2; let
publicGuild;
before(async () => {
let { group, groupLeader } = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'TestGuild',
summary: 'summary for TestGuild',
@@ -273,9 +277,9 @@ describe('GET challenges/user', () => {
});
it('should return official challenges first', async () => {
let challenges = await user.get('/challenges/user');
const challenges = await user.get('/challenges/user');
let foundChallengeIndex = _.findIndex(challenges, { _id: officialChallenge._id });
const foundChallengeIndex = _.findIndex(challenges, { _id: officialChallenge._id });
expect(foundChallengeIndex).to.eql(0);
});
@@ -288,7 +292,7 @@ describe('GET challenges/user', () => {
foundChallengeIndex = _.findIndex(challenges, { _id: challenge2._id });
expect(foundChallengeIndex).to.eql(1);
let newChallenge = await generateChallenge(user, publicGuild);
const newChallenge = await generateChallenge(user, publicGuild);
await user.post(`/challenges/${newChallenge._id}/join`);
challenges = await user.get('/challenges/user');
@@ -299,14 +303,15 @@ describe('GET challenges/user', () => {
});
context('filters and paging', () => {
let user, guild, member;
let user; let guild; let
member;
const categories = [{
slug: 'newCat',
name: 'New Category',
}];
before(async () => {
let { group, groupLeader, members } = await createAndPopulateGroup({
const { group, groupLeader, members } = await createAndPopulateGroup({
groupDetails: {
name: 'TestGuild',
type: 'guild',
@@ -317,9 +322,9 @@ describe('GET challenges/user', () => {
user = groupLeader;
guild = group;
member = members[0];
member = members[0]; // eslint-disable-line prefer-destructuring
await user.update({balance: 20});
await user.update({ balance: 20 });
for (let i = 0; i < 11; i += 1) {
let challenge = await generateChallenge(user, group); // eslint-disable-line
@@ -328,7 +333,7 @@ describe('GET challenges/user', () => {
});
it('returns public guilds filtered by category', async () => {
const categoryChallenge = await generateChallenge(user, guild, {categories});
const categoryChallenge = await generateChallenge(user, guild, { categories });
await user.post(`/challenges/${categoryChallenge._id}/join`);
const challenges = await user.get(`/challenges/user?categories=${categories[0].slug}`);

View File

@@ -1,13 +1,13 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
createAndPopulateGroup,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /challenges', () => {
it('returns error when group is empty', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.post('/challenges')).to.eventually.be.rejected.and.eql({
code: 400,
@@ -17,7 +17,7 @@ describe('POST /challenges', () => {
});
it('returns error when groupId is not for a valid group', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.post('/challenges', {
group: generateUUID(),
@@ -29,7 +29,7 @@ describe('POST /challenges', () => {
});
it('returns error when creating a challenge in the tavern with no prize', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.post('/challenges', {
group: 'habitrpg',
@@ -42,8 +42,8 @@ describe('POST /challenges', () => {
});
it('returns error when creating a challenge in a public guild and you are not a member of it', async () => {
let user = await generateUser();
let { group } = await createAndPopulateGroup({
const user = await generateUser();
const { group } = await createAndPopulateGroup({
groupDetails: {
type: 'guild',
privacy: 'public',
@@ -66,7 +66,7 @@ describe('POST /challenges', () => {
let groupMember;
beforeEach(async () => {
let populatedGroup = await createAndPopulateGroup({
const populatedGroup = await createAndPopulateGroup({
members: 1,
leaderDetails: {
balance: 3,
@@ -81,7 +81,7 @@ describe('POST /challenges', () => {
groupLeader = await populatedGroup.groupLeader.sync();
group = populatedGroup.group;
groupMember = populatedGroup.members[0];
groupMember = populatedGroup.members[0]; // eslint-disable-line prefer-destructuring
});
it('returns an error when non-leader member creates a challenge in leaderOnly group', async () => {
@@ -95,14 +95,14 @@ describe('POST /challenges', () => {
});
it('allows non-leader member to create a challenge', async () => {
let populatedGroup = await createAndPopulateGroup({
const populatedGroup = await createAndPopulateGroup({
members: 1,
});
group = populatedGroup.group;
groupMember = populatedGroup.members[0];
groupMember = populatedGroup.members[0]; // eslint-disable-line prefer-destructuring
let chal = await groupMember.post('/challenges', {
const chal = await groupMember.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC Label',
@@ -110,13 +110,13 @@ describe('POST /challenges', () => {
expect(chal.leader).to.eql({
_id: groupMember._id,
profile: {name: groupMember.profile.name},
profile: { name: groupMember.profile.name },
});
});
it('doesn\'t take gems from user or group when challenge has no prize', async () => {
let oldUserBalance = groupLeader.balance;
let oldGroupBalance = group.balance;
const oldUserBalance = groupLeader.balance;
const oldGroupBalance = group.balance;
await groupLeader.post('/challenges', {
group: group._id,
@@ -143,9 +143,9 @@ describe('POST /challenges', () => {
});
it('takes prize out of group if it has sufficient funds', async () => {
let oldUserBalance = groupLeader.balance;
let oldGroupBalance = group.balance;
let prize = 4;
const oldUserBalance = groupLeader.balance;
const oldGroupBalance = group.balance;
const prize = 4;
await groupLeader.post('/challenges', {
group: group._id,
@@ -159,8 +159,8 @@ describe('POST /challenges', () => {
});
it('takes prize out of both group and user if group doesn\'t have enough', async () => {
let oldUserBalance = groupLeader.balance;
let prize = 8;
const oldUserBalance = groupLeader.balance;
const prize = 8;
await groupLeader.post('/challenges', {
group: group._id,
@@ -170,14 +170,14 @@ describe('POST /challenges', () => {
});
await expect(group.sync()).to.eventually.have.property('balance', 0);
await expect(groupLeader.sync()).to.eventually.have.property('balance', oldUserBalance - (prize / 4 - 1));
await expect(groupLeader.sync()).to.eventually.have.property('balance', oldUserBalance - (prize / 4 - 1));
});
it('takes prize out of user if group has no balance', async () => {
let oldUserBalance = groupLeader.balance;
let prize = 8;
const oldUserBalance = groupLeader.balance;
const prize = 8;
await group.update({ balance: 0});
await group.update({ balance: 0 });
await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
@@ -190,7 +190,7 @@ describe('POST /challenges', () => {
});
it('increases challenge count of group', async () => {
let oldChallengeCount = group.challengeCount;
const oldChallengeCount = group.challengeCount;
await groupLeader.post('/challenges', {
group: group._id,
@@ -208,7 +208,7 @@ describe('POST /challenges', () => {
},
});
let challenge = await groupLeader.post('/challenges', {
const challenge = await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC Label',
@@ -219,7 +219,7 @@ describe('POST /challenges', () => {
});
it('doesn\'t set challenge as official if official flag is set by non-admin', async () => {
let challenge = await groupLeader.post('/challenges', {
const challenge = await groupLeader.post('/challenges', {
group: group._id,
name: 'Test Challenge',
shortName: 'TC Label',
@@ -230,9 +230,9 @@ describe('POST /challenges', () => {
});
it('returns an error when challenge validation fails; doesn\'s save user or group', async () => {
let oldChallengeCount = group.challengeCount;
let oldUserBalance = groupLeader.balance;
let oldGroupBalance = group.balance;
const oldChallengeCount = group.challengeCount;
const oldUserBalance = groupLeader.balance;
const oldGroupBalance = group.balance;
await expect(groupLeader.post('/challenges', {
group: group._id,
@@ -252,12 +252,12 @@ describe('POST /challenges', () => {
});
it('sets all properites of the challenge as passed', async () => {
let name = 'Test Challenge';
let shortName = 'TC Label';
let description = 'Test Description';
let prize = 4;
const name = 'Test Challenge';
const shortName = 'TC Label';
const description = 'Test Description';
const prize = 4;
let challenge = await groupLeader.post('/challenges', {
const challenge = await groupLeader.post('/challenges', {
group: group._id,
name,
shortName,
@@ -267,7 +267,7 @@ describe('POST /challenges', () => {
expect(challenge.leader).to.eql({
_id: groupLeader._id,
profile: {name: groupLeader.profile.name},
profile: { name: groupLeader.profile.name },
});
expect(challenge.name).to.eql(name);
expect(challenge.shortName).to.eql(shortName);

View File

@@ -1,14 +1,14 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateChallenge,
createAndPopulateGroup,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /challenges/:challengeId/join', () => {
it('returns error when challengeId is not a valid UUID', async () => {
let user = await generateUser({ balance: 1});
const user = await generateUser({ balance: 1 });
await expect(user.post('/challenges/test/join')).to.eventually.be.rejected.and.eql({
code: 400,
@@ -18,7 +18,7 @@ describe('POST /challenges/:challengeId/join', () => {
});
it('returns error when challengeId is not for a valid challenge', async () => {
let user = await generateUser({ balance: 1});
const user = await generateUser({ balance: 1 });
await expect(user.post(`/challenges/${generateUUID()}/join`)).to.eventually.be.rejected.and.eql({
code: 404,
@@ -34,20 +34,20 @@ describe('POST /challenges/:challengeId/join', () => {
let authorizedUser;
beforeEach(async () => {
let populatedGroup = await createAndPopulateGroup({
const populatedGroup = await createAndPopulateGroup({
members: 1,
});
groupLeader = populatedGroup.groupLeader;
group = populatedGroup.group;
authorizedUser = populatedGroup.members[0];
authorizedUser = populatedGroup.members[0]; // eslint-disable-line prefer-destructuring
challenge = await generateChallenge(groupLeader, group);
await groupLeader.post(`/challenges/${challenge._id}/join`);
});
it('returns an error when user isn\'t in the private group and isn\'t challenge leader', async () => {
let unauthorizedUser = await generateUser();
const unauthorizedUser = await generateUser();
await expect(unauthorizedUser.post(`/challenges/${challenge._id}/join`)).to.eventually.be.rejected.and.eql({
code: 404,
@@ -62,12 +62,12 @@ describe('POST /challenges/:challengeId/join', () => {
await groupLeader.sync();
expect(groupLeader.guilds).to.be.empty; // check that leaving worked
let res = await groupLeader.post(`/challenges/${challenge._id}/join`);
const res = await groupLeader.post(`/challenges/${challenge._id}/join`);
expect(res.name).to.equal(challenge.name);
});
it('returns challenge data', async () => {
let res = await authorizedUser.post(`/challenges/${challenge._id}/join`);
const res = await authorizedUser.post(`/challenges/${challenge._id}/join`);
expect(res.group).to.eql({
_id: group._id,
@@ -78,7 +78,7 @@ describe('POST /challenges/:challengeId/join', () => {
expect(res.leader).to.eql({
_id: groupLeader._id,
id: groupLeader._id,
profile: {name: groupLeader.profile.name},
profile: { name: groupLeader.profile.name },
auth: {
local: {
username: groupLeader.auth.local.username,
@@ -111,7 +111,7 @@ describe('POST /challenges/:challengeId/join', () => {
it('increases memberCount of challenge', async () => {
await challenge.sync();
let oldMemberCount = challenge.memberCount;
const oldMemberCount = challenge.memberCount;
await authorizedUser.post(`/challenges/${challenge._id}/join`);
@@ -123,15 +123,13 @@ describe('POST /challenges/:challengeId/join', () => {
it('syncs challenge tasks to joining user', async () => {
const taskText = 'A challenge task text';
await groupLeader.post(`/tasks/challenge/${challenge._id}`, [
{type: 'daily', text: taskText},
{ type: 'daily', text: taskText },
]);
await authorizedUser.post(`/challenges/${challenge._id}/join`);
const tasks = await authorizedUser.get('/tasks/user');
const syncedTask = tasks.find((task) => {
return task.text === taskText;
});
const syncedTask = tasks.find(task => task.text === taskText);
expect(syncedTask.text).to.eql(taskText);
expect(syncedTask.isDue).to.exist;
@@ -139,7 +137,7 @@ describe('POST /challenges/:challengeId/join', () => {
});
it('adds challenge tag to user tags', async () => {
let userTagsLength = (await authorizedUser.get('/tags')).length;
const userTagsLength = (await authorizedUser.get('/tags')).length;
await authorizedUser.post(`/challenges/${challenge._id}/join`);

View File

@@ -1,14 +1,14 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateChallenge,
createAndPopulateGroup,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /challenges/:challengeId/leave', () => {
it('returns error when challengeId is not a valid UUID', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.post('/challenges/test/leave')).to.eventually.be.rejected.and.eql({
code: 400,
@@ -18,7 +18,7 @@ describe('POST /challenges/:challengeId/leave', () => {
});
it('returns error when challengeId is not for a valid challenge', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.post(`/challenges/${generateUUID()}/leave`)).to.eventually.be.rejected.and.eql({
code: 404,
@@ -37,15 +37,15 @@ describe('POST /challenges/:challengeId/leave', () => {
let taskText;
beforeEach(async () => {
let populatedGroup = await createAndPopulateGroup({
const populatedGroup = await createAndPopulateGroup({
members: 3,
});
groupLeader = populatedGroup.groupLeader;
group = populatedGroup.group;
leavingUser = populatedGroup.members[0];
notInChallengeUser = populatedGroup.members[1];
notInGroupLeavingUser = populatedGroup.members[2];
leavingUser = populatedGroup.members[0]; // eslint-disable-line prefer-destructuring
notInChallengeUser = populatedGroup.members[1]; // eslint-disable-line prefer-destructuring
notInGroupLeavingUser = populatedGroup.members[2]; // eslint-disable-line prefer-destructuring
challenge = await generateChallenge(groupLeader, group);
await groupLeader.post(`/challenges/${challenge._id}/join`);
@@ -53,7 +53,7 @@ describe('POST /challenges/:challengeId/leave', () => {
taskText = 'A challenge task text';
await groupLeader.post(`/tasks/challenge/${challenge._id}`, [
{type: 'habit', text: taskText},
{ type: 'habit', text: taskText },
]);
await leavingUser.post(`/challenges/${challenge._id}/join`);
@@ -87,7 +87,7 @@ describe('POST /challenges/:challengeId/leave', () => {
});
it('decreases memberCount of challenge', async () => {
let oldMemberCount = challenge.memberCount;
const oldMemberCount = challenge.memberCount;
await leavingUser.post(`/challenges/${challenge._id}/leave`);
@@ -100,10 +100,8 @@ describe('POST /challenges/:challengeId/leave', () => {
await leavingUser.post(`/challenges/${challenge._id}/leave`, {
keep: 'remove-all',
});
let tasks = await leavingUser.get('/tasks/user');
let tasksTexts = tasks.map((task) => {
return task.text;
});
const tasks = await leavingUser.get('/tasks/user');
const tasksTexts = tasks.map(task => task.text);
expect(tasksTexts).to.not.include(taskText);
});
@@ -113,10 +111,8 @@ describe('POST /challenges/:challengeId/leave', () => {
keep: 'test',
});
let tasks = await leavingUser.get('/tasks/user');
let testTask = _.find(tasks, (task) => {
return task.text === taskText;
});
const tasks = await leavingUser.get('/tasks/user');
const testTask = _.find(tasks, task => task.text === taskText);
expect(testTask).to.not.be.undefined;
});

View File

@@ -1,3 +1,4 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateChallenge,
@@ -6,11 +7,10 @@ import {
checkExistence,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /challenges/:challengeId/winner/:winnerId', () => {
it('returns error when challengeId is not a valid UUID', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.post(`/challenges/test/selectWinner/${user._id}`)).to.eventually.be.rejected.and.eql({
code: 400,
@@ -20,7 +20,7 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
});
it('returns error when winnerId is not a valid UUID', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.post(`/challenges/${generateUUID()}/selectWinner/test`)).to.eventually.be.rejected.and.eql({
code: 400,
@@ -30,7 +30,7 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
});
it('returns error when challengeId is not for a valid challenge', async () => {
let user = await generateUser();
const user = await generateUser();
await expect(user.post(`/challenges/${generateUUID()}/selectWinner/${user._id}`)).to.eventually.be.rejected.and.eql({
code: 404,
@@ -44,16 +44,16 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
let group;
let challenge;
let winningUser;
let taskText = 'A challenge task text';
const taskText = 'A challenge task text';
beforeEach(async () => {
let populatedGroup = await createAndPopulateGroup({
const populatedGroup = await createAndPopulateGroup({
members: 1,
});
groupLeader = populatedGroup.groupLeader;
group = populatedGroup.group;
winningUser = populatedGroup.members[0];
winningUser = populatedGroup.members[0]; // eslint-disable-line prefer-destructuring
challenge = await generateChallenge(groupLeader, group, {
prize: 1,
@@ -61,7 +61,7 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
await groupLeader.post(`/challenges/${challenge._id}/join`);
await groupLeader.post(`/tasks/challenge/${challenge._id}`, [
{type: 'habit', text: taskText},
{ type: 'habit', text: taskText },
]);
await winningUser.post(`/challenges/${challenge._id}/join`);
@@ -78,12 +78,12 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
});
it('returns an error when winning user isn\'t part of the challenge', async () => {
let notInChallengeUser = await generateUser();
const notInChallengeUser = await generateUser();
await expect(groupLeader.post(`/challenges/${challenge._id}/selectWinner/${notInChallengeUser._id}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('winnerNotFound', {userId: notInChallengeUser._id}),
message: t('winnerNotFound', { userId: notInChallengeUser._id }),
});
});
@@ -101,12 +101,13 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
await sleep(0.5);
await expect(winningUser.sync()).to.eventually.have.nested.property('achievements.challenges').to.include(challenge.name);
expect(winningUser.notifications.length).to.equal(2); // 2 because winningUser just joined the challenge, which now awards an achievement
// 2 because winningUser just joined the challenge, which now awards an achievement
expect(winningUser.notifications.length).to.equal(2);
expect(winningUser.notifications[1].type).to.equal('WON_CHALLENGE');
});
it('gives winner gems as reward', async () => {
let oldBalance = winningUser.balance;
const oldBalance = winningUser.balance;
await groupLeader.post(`/challenges/${challenge._id}/selectWinner/${winningUser._id}`);
@@ -116,8 +117,8 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
});
it('doesn\'t gives winner gems if group policy prevents it', async () => {
let oldBalance = winningUser.balance;
let oldLeaderBalance = (await groupLeader.sync()).balance;
const oldBalance = winningUser.balance;
const oldLeaderBalance = (await groupLeader.sync()).balance;
await winningUser.update({
'purchased.plan.customerId': 'group-plan',
@@ -136,7 +137,7 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
});
it('doesn\'t refund gems to group leader', async () => {
let oldBalance = (await groupLeader.sync()).balance;
const oldBalance = (await groupLeader.sync()).balance;
await groupLeader.post(`/challenges/${challenge._id}/selectWinner/${winningUser._id}`);
@@ -151,14 +152,10 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
await sleep(0.5);
const tasks = await winningUser.get('/tasks/user');
const testTask = _.find(tasks, (task) => {
return task.text === taskText;
});
const testTask = _.find(tasks, task => task.text === taskText);
const updatedUser = await winningUser.sync();
const challengeTag = updatedUser.tags.find(tags => {
return tags.id === challenge._id;
});
const challengeTag = updatedUser.tags.find(tags => tags.id === challenge._id);
expect(testTask.challenge.broken).to.eql('CHALLENGE_CLOSED');
expect(testTask.challenge.winner).to.eql(winningUser.profile.name);

View File

@@ -5,7 +5,7 @@ import {
describe('POST /challenges/:challengeId/clone', () => {
it('clones a challenge', async () => {
const user = await generateUser({balance: 10});
const user = await generateUser({ balance: 10 });
const group = await generateGroup(user);
const name = 'Test Challenge';
@@ -38,6 +38,7 @@ describe('POST /challenges/:challengeId/clone', () => {
expect(cloneChallengeResponse.clonedTasks[0].text).to.eql(challengeTask.text);
expect(cloneChallengeResponse.clonedTasks[0]._id).to.not.eql(challengeTask._id);
expect(cloneChallengeResponse.clonedTasks[0].challenge.id).to.eql(cloneChallengeResponse.clonedChallenge._id);
expect(cloneChallengeResponse.clonedTasks[0].challenge.id)
.to.eql(cloneChallengeResponse.clonedChallenge._id);
});
});

View File

@@ -6,10 +6,11 @@ import {
} from '../../../../helpers/api-integration/v3';
describe('PUT /challenges/:challengeId', () => {
let privateGuild, user, nonMember, challenge, member;
let privateGuild; let user; let nonMember; let challenge; let
member;
beforeEach(async () => {
let { group, groupLeader, members } = await createAndPopulateGroup({
const { group, groupLeader, members } = await createAndPopulateGroup({
groupDetails: {
name: 'TestPrivateGuild',
type: 'guild',
@@ -22,7 +23,7 @@ describe('PUT /challenges/:challengeId', () => {
user = groupLeader;
nonMember = await generateUser();
member = members[0];
member = members[0]; // eslint-disable-line prefer-destructuring
challenge = await generateChallenge(user, group);
await user.post(`/challenges/${challenge._id}/join`);
@@ -48,7 +49,7 @@ describe('PUT /challenges/:challengeId', () => {
});
it('only updates allowed fields', async () => {
let res = await user.put(`/challenges/${challenge._id}`, {
const res = await user.put(`/challenges/${challenge._id}`, {
// ignored
prize: 33,
group: 'blabla',
@@ -78,7 +79,7 @@ describe('PUT /challenges/:challengeId', () => {
expect(res.leader).to.eql({
_id: user._id,
id: user._id,
profile: {name: user.profile.name},
profile: { name: user.profile.name },
auth: {
local: {
username: user.auth.local.username,