lint: Fix linting errors in api v2 tests
This commit is contained in:
@@ -3,7 +3,6 @@ import {
|
||||
createAndPopulateGroup,
|
||||
generateGroup,
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../helpers/api-integration.helper';
|
||||
import { find } from 'lodash';
|
||||
|
||||
@@ -15,7 +14,7 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
it('deletes the user', async () => {
|
||||
return expect(user.del('/user').then((fetchedUser) => {
|
||||
return expect(user.del('/user').then(() => {
|
||||
return checkExistence('users', user._id);
|
||||
})).to.eventually.eql(false);
|
||||
});
|
||||
@@ -30,16 +29,16 @@ describe('DELETE /user', () => {
|
||||
beforeEach(async () => {
|
||||
return generateGroup(user, {
|
||||
type: 'party',
|
||||
privacy: 'private'
|
||||
privacy: 'private',
|
||||
}).then((group) => {
|
||||
party = group;
|
||||
});
|
||||
});
|
||||
|
||||
it('deletes party when user is the only member', async () => {
|
||||
return expect(user.del('/user').then((result) => {
|
||||
return checkExistence('groups', party._id);
|
||||
})).to.eventually.eql(false);
|
||||
return expect(user.del('/user').then(() => {
|
||||
return checkExistence('groups', party._id);
|
||||
})).to.eventually.eql(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,16 +48,16 @@ describe('DELETE /user', () => {
|
||||
beforeEach(async () => {
|
||||
return generateGroup(user, {
|
||||
type: 'guild',
|
||||
privacy: 'private'
|
||||
privacy: 'private',
|
||||
}).then((group) => {
|
||||
guild = group;
|
||||
});
|
||||
});
|
||||
|
||||
it('deletes guild when user is the only member', async () => {
|
||||
return expect(user.del('/user').then((result) => {
|
||||
return checkExistence('groups', guild._id);
|
||||
})).to.eventually.eql(false);
|
||||
return expect(user.del('/user').then(() => {
|
||||
return checkExistence('groups', guild._id);
|
||||
})).to.eventually.eql(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -80,7 +79,7 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
it('chooses new group leader for any group user was the leader of', async () => {
|
||||
return oldLeader.del('/user').then((res) => {
|
||||
return oldLeader.del('/user').then(() => {
|
||||
return newLeader.get(`/groups/${group._id}`);
|
||||
}).then((guild) => {
|
||||
expect(guild.leader).to.exist;
|
||||
@@ -95,8 +94,8 @@ describe('DELETE /user', () => {
|
||||
beforeEach(async () => {
|
||||
return generateUser({
|
||||
balance: 10,
|
||||
}).then((user) => {
|
||||
userToDelete = user;
|
||||
}).then((_user) => {
|
||||
userToDelete = _user;
|
||||
|
||||
return generateGroup(userToDelete, {
|
||||
type: 'guild',
|
||||
@@ -121,7 +120,7 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
it('removes user from all groups user was a part of', async () => {
|
||||
return userToDelete.del('/user').then((res) => {
|
||||
return userToDelete.del('/user').then(() => {
|
||||
return otherUser.get(`/groups/${group1._id}`);
|
||||
}).then((fetchedGroup1) => {
|
||||
expect(fetchedGroup1.members).to.be.empty;
|
||||
@@ -137,7 +136,6 @@ describe('DELETE /user', () => {
|
||||
expect(userInGroup).to.not.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
context('pending invitation to group', () => {
|
||||
@@ -159,7 +157,7 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
|
||||
it('removes invitations from groups', async () => {
|
||||
return userToDelete.del('/user').then((res) => {
|
||||
return userToDelete.del('/user').then(() => {
|
||||
return otherUser.get(`/groups/${group._id}`);
|
||||
}).then((fetchedGroup) => {
|
||||
expect(fetchedGroup.invites).to.have.a.lengthOf(1);
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('GET /user/tags/id', () => {
|
||||
});
|
||||
|
||||
it('gets a user\'s tag by id', async () => {
|
||||
return expect(user.get('/user/tags/' + user.tags[0].id))
|
||||
return expect(user.get(`/user/tags/${user.tags[0].id}`))
|
||||
.to.eventually.eql(user.tags[0]);
|
||||
});
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ describe('PUT /user', () => {
|
||||
context('allowed operations', () => {
|
||||
it('updates the user', async () => {
|
||||
let updatedUser = await user.put('/user', {
|
||||
'profile.name' : 'Frodo',
|
||||
'profile.name': 'Frodo',
|
||||
'preferences.costume': true,
|
||||
'stats.hp': 14,
|
||||
});
|
||||
@@ -29,19 +29,19 @@ 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},
|
||||
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},
|
||||
'tasks': {todos: [], habits: [], dailys: [], rewards: []},
|
||||
tasks: {todos: [], habits: [], dailys: [], rewards: []},
|
||||
};
|
||||
|
||||
each(protectedOperations, (data, testName) => {
|
||||
it(`does not allow updating ${testName}`, async () => {
|
||||
let errorText = [];
|
||||
each(data, (value, operation) => {
|
||||
errorText.push(t('messageUserOperationProtected', { operation: operation }));
|
||||
errorText.push(t('messageUserOperationProtected', { operation }));
|
||||
});
|
||||
|
||||
await expect(user.put('/user', data)).to.eventually.be.rejected.and.eql({
|
||||
@@ -61,7 +61,7 @@ describe('PUT /user', () => {
|
||||
it(`does not allow updating ${testName}`, async () => {
|
||||
let errorText = [];
|
||||
each(data, (value, operation) => {
|
||||
errorText.push(t('messageUserOperationProtected', { operation: operation }));
|
||||
errorText.push(t('messageUserOperationProtected', { operation }));
|
||||
});
|
||||
|
||||
await expect(user.put('/user', data)).to.eventually.be.rejected.and.eql({
|
||||
|
||||
@@ -4,80 +4,77 @@ import {
|
||||
import { each } from 'lodash';
|
||||
|
||||
describe('GET /user/anonymized', () => {
|
||||
let user;
|
||||
let user, anonymizedUser;
|
||||
|
||||
before(async () => {
|
||||
return generateUser({
|
||||
'inbox.messages' : {
|
||||
'the-message-id' : {
|
||||
sort : 214,
|
||||
user : 'Some user',
|
||||
backer : {},
|
||||
contributor : {
|
||||
text : 'Blacksmith',
|
||||
level : 2,
|
||||
contributions : 'Made some contributions',
|
||||
admin : false
|
||||
user = await generateUser({
|
||||
'inbox.messages': {
|
||||
'the-message-id': {
|
||||
sort: 214,
|
||||
user: 'Some user',
|
||||
backer: {},
|
||||
contributor: {
|
||||
text: 'Blacksmith',
|
||||
level: 2,
|
||||
contributions: 'Made some contributions',
|
||||
admin: false,
|
||||
},
|
||||
uuid : 'some-users-uuid',
|
||||
flagCount : 0,
|
||||
flags : {},
|
||||
likes : {},
|
||||
timestamp : 1444154258699.0000000000000000,
|
||||
text : 'Lorem ipsum',
|
||||
id : 'the-messages-id',
|
||||
sent : true
|
||||
}
|
||||
}
|
||||
}).then((usr) => {
|
||||
user = usr;
|
||||
return user.post('/user/tasks', {
|
||||
text: 'some private text',
|
||||
notes: 'some private notes',
|
||||
checklist: [
|
||||
{text: 'a private checklist'},
|
||||
{text: 'another private checklist'},
|
||||
],
|
||||
type: 'daily',
|
||||
});
|
||||
}).then((result) => {
|
||||
return user.get('/user/anonymized');
|
||||
}).then((anonymizedUser) => {
|
||||
user = anonymizedUser;
|
||||
uuid: 'some-users-uuid',
|
||||
flagCount: 0,
|
||||
flags: {},
|
||||
likes: {},
|
||||
timestamp: 1444154258699.0000000000000000,
|
||||
text: 'Lorem ipsum',
|
||||
id: 'the-messages-id',
|
||||
sent: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await user.post('/user/tasks', {
|
||||
text: 'some private text',
|
||||
notes: 'some private notes',
|
||||
checklist: [
|
||||
{text: 'a private checklist'},
|
||||
{text: 'another private checklist'},
|
||||
],
|
||||
type: 'daily',
|
||||
});
|
||||
|
||||
anonymizedUser = await user.get('/user/anonymized');
|
||||
});
|
||||
|
||||
it('retains user id', async () => {
|
||||
expect(user._id).to.exist;
|
||||
expect(anonymizedUser._id).to.eql(user._id);
|
||||
});
|
||||
|
||||
it('removes credentials and financial information', async () => {
|
||||
expect(user.apiToken).to.not.exist;
|
||||
expect(user.auth.local).to.not.exist;
|
||||
expect(user.auth.facebook).to.not.exist;
|
||||
expect(user.purchased.plan).to.not.exist;
|
||||
expect(anonymizedUser.apiToken).to.not.exist;
|
||||
expect(anonymizedUser.auth.local).to.not.exist;
|
||||
expect(anonymizedUser.auth.facebook).to.not.exist;
|
||||
expect(anonymizedUser.purchased.plan).to.not.exist;
|
||||
});
|
||||
|
||||
it('removes profile information', async () => {
|
||||
expect(user.profile).to.not.exist;
|
||||
expect(user.contributor).to.not.exist;
|
||||
expect(user.achievements.challenges).to.not.exist;
|
||||
expect(anonymizedUser.profile).to.not.exist;
|
||||
expect(anonymizedUser.contributor).to.not.exist;
|
||||
expect(anonymizedUser.achievements.challenges).to.not.exist;
|
||||
});
|
||||
|
||||
it('removes social information', async () => {
|
||||
expect(user.newMessages).to.not.exist;
|
||||
expect(user.invitations).to.not.exist;
|
||||
expect(user.items.special.nyeReceived).to.not.exist;
|
||||
expect(user.items.special.valentineReceived).to.not.exist;
|
||||
expect(anonymizedUser.newMessages).to.not.exist;
|
||||
expect(anonymizedUser.invitations).to.not.exist;
|
||||
expect(anonymizedUser.items.special.nyeReceived).to.not.exist;
|
||||
expect(anonymizedUser.items.special.valentineReceived).to.not.exist;
|
||||
|
||||
each(user.inbox.messages, (msg) => {
|
||||
each(anonymizedUser.inbox.messages, (msg) => {
|
||||
expect(msg.text).to.eql('inbox message text');
|
||||
});
|
||||
});
|
||||
|
||||
it('anonymizes task info', async () => {
|
||||
each(['habits', 'todos', 'dailys', 'rewards'], (tasks) => {
|
||||
each(user[tasks], (task) => {
|
||||
each(anonymizedUser[tasks], (task) => {
|
||||
expect(task.text).to.eql('task text');
|
||||
expect(task.notes).to.eql('task notes');
|
||||
|
||||
@@ -89,13 +86,13 @@ describe('GET /user/anonymized', () => {
|
||||
});
|
||||
|
||||
it('anonymizes tags', async () => {
|
||||
each(user.tags, (tag) => {
|
||||
each(anonymizedUser.tags, (tag) => {
|
||||
expect(tag.name).to.eql('tag');
|
||||
expect(tag.challenge).to.eql('challenge');
|
||||
});
|
||||
});
|
||||
|
||||
it('removes webhooks', async () => {
|
||||
expect(user.webhooks).to.not.exist;
|
||||
expect(anonymizedUser.webhooks).to.not.exist;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,24 +14,20 @@ describe('POST /user/batch-update', () => {
|
||||
|
||||
context('allowed operations', () => {
|
||||
it('makes batch operations', async () => {
|
||||
let task;
|
||||
let task = (await user.get('/user/tasks'))[0];
|
||||
|
||||
return user.get('/user/tasks').then((tasks) => {
|
||||
task = tasks[0];
|
||||
let updatedUser = await user.post('/user/batch-update', [
|
||||
{op: 'update', body: {'stats.hp': 30}},
|
||||
{op: 'update', body: {'profile.name': 'Samwise'}},
|
||||
{op: 'score', params: { direction: 'up', id: task.id }},
|
||||
]);
|
||||
|
||||
return user.post('/user/batch-update', [
|
||||
{op: 'update', body: {'stats.hp': 30}},
|
||||
{op: 'update', body: {'profile.name': 'Samwise'}},
|
||||
{op: 'score', params: { direction: 'up', id: task.id }},
|
||||
]);
|
||||
}).then((updatedUser) => {
|
||||
expect(updatedUser.stats.hp).to.eql(30);
|
||||
expect(updatedUser.profile.name).to.eql('Samwise');
|
||||
expect(updatedUser.stats.hp).to.eql(30);
|
||||
expect(updatedUser.profile.name).to.eql('Samwise');
|
||||
|
||||
return user.get(`/user/tasks/${task.id}`);
|
||||
}).then((task) => {
|
||||
expect(task.value).to.be.greaterThan(0);
|
||||
});
|
||||
let fetchedTask = await user.get(`/user/tasks/${task.id}`);
|
||||
|
||||
expect(fetchedTask.value).to.be.greaterThan(task.value);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -42,7 +38,6 @@ describe('POST /user/batch-update', () => {
|
||||
};
|
||||
|
||||
each(protectedOperations, (operation, description) => {
|
||||
|
||||
it(`it sends back a 500 error for ${description} operation`, async () => {
|
||||
return expect(user.post('/user/batch-update', [
|
||||
{ op: operation },
|
||||
|
||||
@@ -12,13 +12,12 @@ describe('DELETE /user/tasks/:id', () => {
|
||||
});
|
||||
|
||||
it('deletes a task', async () => {
|
||||
return expect(user.del(`/user/tasks/${task.id}`)
|
||||
.then((res) => {
|
||||
return user.get(`/user/tasks/${task.id}`);
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: t('messageTaskNotFound'),
|
||||
});
|
||||
await user.del(`/user/tasks/${task.id}`);
|
||||
|
||||
await expect(user.get(`/user/tasks/${task.id}`)).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
text: t('messageTaskNotFound'),
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if the task does not exist', async () => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration.helper';
|
||||
|
||||
describe('GET /user/tasks/', () => {
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
} from '../../../../helpers/api-integration.helper';
|
||||
|
||||
describe('POST /user/tasks', () => {
|
||||
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration.helper';
|
||||
|
||||
describe('PUT /user/tasks/:id', () => {
|
||||
@@ -34,13 +33,13 @@ describe('PUT /user/tasks/:id', () => {
|
||||
text: 'new text',
|
||||
notes: 'new notes',
|
||||
value: 10000,
|
||||
priority: .5,
|
||||
priority: 0.5,
|
||||
attribute: 'str',
|
||||
}).then((updatedTask) => {
|
||||
expect(updatedTask.text).to.eql('new text');
|
||||
expect(updatedTask.notes).to.eql('new notes');
|
||||
expect(updatedTask.value).to.eql(10000);
|
||||
expect(updatedTask.priority).to.eql(.5);
|
||||
expect(updatedTask.priority).to.eql(0.5);
|
||||
expect(updatedTask.attribute).to.eql('str');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user