tests(api): Use new user['HTTP_METHOD'] for v3 integration tests

This commit is contained in:
Blade Barringer
2015-12-30 08:25:06 -06:00
parent a662d4b688
commit ca1513aaa9
18 changed files with 229 additions and 261 deletions

View File

@@ -1,15 +1,13 @@
import {
generateUser,
requester,
} from '../../../../helpers/api-integration.helper';
describe('DELETE /tags/:tagId', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
@@ -17,16 +15,16 @@ describe('DELETE /tags/:tagId', () => {
let length;
let tag;
return api.post('/tags', {name: 'Tag 1'})
return user.post('/tags', {name: 'Tag 1'})
.then((createdTag) => {
tag = createdTag;
return api.get(`/tags`);
return user.get(`/tags`);
})
.then((tags) => {
length = tags.length;
return api.del(`/tags/${tag._id}`);
return user.del(`/tags/${tag._id}`);
})
.then(() => api.get(`/tags`))
.then(() => user.get(`/tags`))
.then((tags) => {
expect(tags.length).to.equal(length - 1);
expect(tags[tags.length - 1].name).to.not.equal('Tag 1');

View File

@@ -1,22 +1,20 @@
import {
generateUser,
requester,
} from '../../../../helpers/api-integration.helper';
describe('GET /tags', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('returns all user\'s tags', () => {
return api.post('/tags', {name: 'Tag 1'})
.then(() => api.post('/tags', {name: 'Tag 2'}))
.then(() => api.get('/tags'))
return user.post('/tags', {name: 'Tag 1'})
.then(() => user.post('/tags', {name: 'Tag 2'}))
.then(() => user.get('/tags'))
.then((tags) => {
expect(tags.length).to.equal(2 + 3); // + 3 because 1 is a default task
expect(tags[tags.length - 2].name).to.equal('Tag 1');

View File

@@ -1,25 +1,23 @@
import {
generateUser,
requester,
} from '../../../../helpers/api-integration.helper';
describe('GET /tags/:tagId', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('returns a tag given it\'s id', () => {
let createdTag;
return api.post('/tags', {name: 'Tag 1'})
return user.post('/tags', {name: 'Tag 1'})
.then((tag) => {
createdTag = tag;
return api.get(`/tags/${createdTag._id}`)
return user.get(`/tags/${createdTag._id}`)
})
.then((tag) => {
expect(tag).to.deep.equal(createdTag);

View File

@@ -1,29 +1,29 @@
import {
generateUser,
requester,
} from '../../../../helpers/api-integration.helper';
describe('POST /tags', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('creates a tag correctly', () => {
let createdTag;
return api.post('/tags', {
return user.post('/tags', {
name: 'Tag 1',
ignored: false,
}).then((tag) => {
createdTag = tag;
expect(tag.name).to.equal('Tag 1');
expect(tag.ignored).to.be.a('undefined');
return api.get(`/tags/${createdTag._id}`)
return user.get(`/tags/${createdTag._id}`);
})
.then((tag) => {
expect(tag).to.deep.equal(createdTag);

View File

@@ -1,24 +1,22 @@
import {
generateUser,
requester,
} from '../../../../helpers/api-integration.helper';
describe('PUT /tags/:tagId', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('updates a tag given it\'s id', () => {
let length;
return api.post('/tags', {name: 'Tag 1'})
return user.post('/tags', {name: 'Tag 1'})
.then((createdTag) => {
return api.put(`/tags/${createdTag._id}`, {
return user.put(`/tags/${createdTag._id}`, {
name: 'Tag updated',
ignored: true
});
@@ -26,7 +24,8 @@ describe('PUT /tags/:tagId', () => {
.then((updatedTag) => {
expect(updatedTag.name).to.equal('Tag updated');
expect(updatedTag.ignored).to.be.a('undefined');
return api.get(`/tags/${updatedTag._id}`);
return user.get(`/tags/${updatedTag._id}`);
})
.then((tag) => {
expect(tag.name).to.equal('Tag updated');

View File

@@ -1,16 +1,14 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../helpers/api-integration.helper';
describe('DELETE /tasks/:id', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
@@ -18,7 +16,7 @@ describe('DELETE /tasks/:id', () => {
let task;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
}).then((createdTask) => {
@@ -27,9 +25,9 @@ describe('DELETE /tasks/:id', () => {
});
it('deletes a user\'s task', () => {
return api.del('/tasks/' + task._id)
return user.del('/tasks/' + task._id)
.then(() => {
return expect(api.get('/tasks/' + task._id)).to.eventually.be.rejected.and.eql({
return expect(user.get('/tasks/' + task._id)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),
@@ -40,7 +38,7 @@ describe('DELETE /tasks/:id', () => {
context('task cannot be deleted', () => {
it('cannot delete a non-existant task', () => {
return expect(api.del('/tasks/550e8400-e29b-41d4-a716-446655440000')).to.eventually.be.rejected.and.eql({
return expect(user.del('/tasks/550e8400-e29b-41d4-a716-446655440000')).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),
@@ -49,14 +47,14 @@ describe('DELETE /tasks/:id', () => {
it('cannot delete a task owned by someone else', () => {
return generateUser()
.then((user2) => {
return requester(user2).post('/tasks', {
.then((anotherUser) => {
return anotherUser.post('/tasks', {
text: 'test habit',
type: 'habit',
})
});
})
.then((task2) => {
return expect(api.del('/tasks/' + task2._id)).to.eventually.be.rejected.and.eql({
return expect(user.del('/tasks/' + task2._id)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),

View File

@@ -1,28 +1,26 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../helpers/api-integration.helper';
import Q from 'q';
describe('GET /tasks', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('returns all user\'s tasks', () => {
let length;
return Q.all([
api.post('/tasks', {text: 'test habit', type: 'habit'}),
user.post('/tasks', {text: 'test habit', type: 'habit'}),
])
.then((createdTasks) => {
length = createdTasks.length;
return api.get('/tasks');
return user.get('/tasks');
})
.then((tasks) => {
expect(tasks.length).to.equal(length + 1); // + 1 because 1 is a default task
@@ -31,10 +29,10 @@ describe('GET /tasks', () => {
it('returns only a type of user\'s tasks if req.query.type is specified', () => {
let habitId;
api.post('/tasks', {text: 'test habit', type: 'habit'})
user.post('/tasks', {text: 'test habit', type: 'habit'})
.then((task) => {
habitId = task._id;
return api.get('/tasks?type=habit');
return user.get('/tasks?type=habit');
})
.then((tasks) => {
expect(tasks.length).to.equal(1);

View File

@@ -1,17 +1,15 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid';
describe('GET /tasks/:id', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
@@ -19,7 +17,7 @@ describe('GET /tasks/:id', () => {
let task;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
}).then((createdTask) => {
@@ -28,7 +26,7 @@ describe('GET /tasks/:id', () => {
});
it('gets specified task', () => {
return api.get('/tasks/' + task._id)
return user.get('/tasks/' + task._id)
.then((getTask) => {
expect(getTask).to.eql(task);
});
@@ -38,9 +36,9 @@ describe('GET /tasks/:id', () => {
it('can get active challenge task that user does not own'); // Yes?
});
context('task cannot accessed', () => {
context('task cannot be accessed', () => {
it('cannot get a non-existant task', () => {
return expect(api.get('/tasks/' + generateUUID())).to.eventually.be.rejected.and.eql({
return expect(user.get('/tasks/' + generateUUID())).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),
@@ -48,17 +46,18 @@ describe('GET /tasks/:id', () => {
});
it('cannot get a task owned by someone else', () => {
let api2;
let anotherUser;
return generateUser()
.then((user2) => {
api2 = requester(user2);
return api.post('/tasks', {
anotherUser = user2;
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
})
});
}).then((task) => {
return expect(api2.get('/tasks/' + task._id)).to.eventually.be.rejected.and.eql({
return expect(anotherUser.get('/tasks/' + task._id)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),

View File

@@ -1,24 +1,20 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../helpers/api-integration.helper';
import { v4 as generateRandomUserName } from 'uuid';
import { each } from 'lodash';
describe('POST /tasks', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
context('validates params', () => {
it('returns an error if req.body.type is absent', () => {
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
notType: 'habit',
})).to.eventually.be.rejected.and.eql({
code: 400,
@@ -28,7 +24,7 @@ describe('POST /tasks', () => {
});
it('returns an error if req.body.type is not valid', () => {
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habitF',
})).to.eventually.be.rejected.and.eql({
code: 400,
@@ -38,7 +34,7 @@ describe('POST /tasks', () => {
});
it('returns an error if req.body.text is absent', () => {
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habit',
})).to.eventually.be.rejected.and.eql({
code: 400,
@@ -48,7 +44,7 @@ describe('POST /tasks', () => {
});
it('automatically sets "task.userId" to user\'s uuid', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
}).then((task) => {
@@ -59,7 +55,7 @@ describe('POST /tasks', () => {
it(`ignores setting userId, history, createdAt,
updatedAt, challenge, completed, streak,
dateCompleted fields`, () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test daily',
type: 'daily',
userId: 123,
@@ -83,7 +79,7 @@ describe('POST /tasks', () => {
});
it('ignores invalid fields', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test daily',
type: 'daily',
notValid: true,
@@ -95,7 +91,7 @@ describe('POST /tasks', () => {
context('habits', () => {
it('creates a habit', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
up: false,
@@ -112,7 +108,7 @@ describe('POST /tasks', () => {
});
it('defaults to setting up and down to true', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
notes: 1976,
@@ -123,7 +119,7 @@ describe('POST /tasks', () => {
});
it('cannot create checklists', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
checklist: [
@@ -137,7 +133,7 @@ describe('POST /tasks', () => {
context('todos', () => {
it('creates a todo', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test todo',
type: 'todo',
notes: 1976,
@@ -150,7 +146,7 @@ describe('POST /tasks', () => {
});
it('can create checklists', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test todo',
type: 'todo',
checklist: [
@@ -171,7 +167,7 @@ describe('POST /tasks', () => {
it('creates a daily', () => {
let now = new Date();
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test daily',
type: 'daily',
notes: 1976,
@@ -190,7 +186,7 @@ describe('POST /tasks', () => {
});
it('defaults to a weekly frequency, with every day set', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test daily',
type: 'daily',
}).then((task) => {
@@ -209,7 +205,7 @@ describe('POST /tasks', () => {
});
it('allows repeat field to be configured', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test daily',
type: 'daily',
repeat: {
@@ -233,7 +229,7 @@ describe('POST /tasks', () => {
it('defaults startDate to today', () => {
let today = (new Date()).getDay();
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test daily',
type: 'daily',
}).then((task) => {
@@ -242,7 +238,7 @@ describe('POST /tasks', () => {
});
it('can create checklists', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test daily',
type: 'daily',
checklist: [
@@ -261,7 +257,7 @@ describe('POST /tasks', () => {
context('rewards', () => {
it('creates a reward', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test reward',
type: 'reward',
notes: 1976,
@@ -276,7 +272,7 @@ describe('POST /tasks', () => {
});
it('defaults to a 0 value', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test reward',
type: 'reward',
}).then((task) => {
@@ -285,7 +281,7 @@ describe('POST /tasks', () => {
});
it('requires value to be coerced into a number', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test reward',
type: 'reward',
value: "10",
@@ -295,7 +291,7 @@ describe('POST /tasks', () => {
});
it('cannot create checklists', () => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test reward',
type: 'reward',
checklist: [

View File

@@ -1,25 +1,23 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:id/score/:direction', () => {
let user, api;
let user;
beforeEach(() => {
return generateUser({
'stats.gp': 100,
}).then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
context('all', () => {
it('requires a task id', () => {
return expect(api.post('/tasks/123/score/up')).to.eventually.be.rejected.and.eql({
return expect(user.post('/tasks/123/score/up')).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('invalidReqParams'),
@@ -27,7 +25,7 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('requires a task direction', () => {
return expect(api.post(`/tasks/${generateUUID()}/score/tt`)).to.eventually.be.rejected.and.eql({
return expect(user.post(`/tasks/${generateUUID()}/score/tt`)).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('invalidReqParams'),
@@ -39,7 +37,7 @@ describe('POST /tasks/:id/score/:direction', () => {
let todo;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test todo',
type: 'todo',
}).then((task) => {
@@ -48,20 +46,20 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('completes todo when direction is up', () => {
return api.post(`/tasks/${todo._id}/score/up`)
.then((res) => api.get(`/tasks/${todo._id}`))
return user.post(`/tasks/${todo._id}/score/up`)
.then((res) => user.get(`/tasks/${todo._id}`))
.then((task) => expect(task.completed).to.equal(true));
});
it('moves completed todos out of user.tasksOrder.todos', () => {
return api.get('/user')
return user.get('/user')
.then(user => {
expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1)
}).then(() => api.post(`/tasks/${todo._id}/score/up`))
.then(() => api.get(`/tasks/${todo._id}`))
}).then(() => user.post(`/tasks/${todo._id}/score/up`))
.then(() => user.get(`/tasks/${todo._id}`))
.then((updatedTask) => {
expect(updatedTask.completed).to.equal(true);
return api.get('/user');
return user.get('/user');
})
.then((user) => {
expect(user.tasksOrder.todos.indexOf(todo._id)).to.equal(-1)
@@ -69,15 +67,15 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('moves un-completed todos back into user.tasksOrder.todos', () => {
return api.get('/user')
return user.get('/user')
.then(user => {
expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1)
}).then(() => api.post(`/tasks/${todo._id}/score/up`))
.then(() => api.post(`/tasks/${todo._id}/score/down`))
.then(() => api.get(`/tasks/${todo._id}`))
}).then(() => user.post(`/tasks/${todo._id}/score/up`))
.then(() => user.post(`/tasks/${todo._id}/score/down`))
.then(() => user.get(`/tasks/${todo._id}`))
.then((updatedTask) => {
expect(updatedTask.completed).to.equal(false);
return api.get('/user');
return user.get('/user');
})
.then((user) => {
let l = user.tasksOrder.todos.length;
@@ -87,8 +85,8 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('uncompletes todo when direction is down', () => {
return api.post(`/tasks/${todo._id}/score/down`)
.then((res) => api.get(`/tasks/${todo._id}`))
return user.post(`/tasks/${todo._id}/score/down`)
.then((res) => user.get(`/tasks/${todo._id}`))
.then((updatedTask) => {
expect(updatedTask.completed).to.equal(false);
});
@@ -99,48 +97,48 @@ describe('POST /tasks/:id/score/:direction', () => {
it('scores down todo even if it is already uncompleted'); // Yes?
it('increases user\'s mp when direction is up', () => {
return api.post(`/tasks/${todo._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${todo._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
});
});
it('decreases user\'s mp when direction is down', () => {
return api.post(`/tasks/${todo._id}/score/down`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${todo._id}/score/down`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
});
});
it('increases user\'s exp when direction is up', () => {
return api.post(`/tasks/${todo._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${todo._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
});
});
it('decreases user\'s exp when direction is down', () => {
return api.post(`/tasks/${todo._id}/score/down`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${todo._id}/score/down`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
});
});
it('increases user\'s gold when direction is up', () => {
return api.post(`/tasks/${todo._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${todo._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
});
});
it('decreases user\'s gold when direction is down', () => {
return api.post(`/tasks/${todo._id}/score/down`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${todo._id}/score/down`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
});
@@ -151,7 +149,7 @@ describe('POST /tasks/:id/score/:direction', () => {
let daily;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test daily',
type: 'daily',
}).then((task) => {
@@ -160,14 +158,14 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('completes daily when direction is up', () => {
return api.post(`/tasks/${daily._id}/score/up`)
.then((res) => api.get(`/tasks/${daily._id}`))
return user.post(`/tasks/${daily._id}/score/up`)
.then((res) => user.get(`/tasks/${daily._id}`))
.then((task) => expect(task.completed).to.equal(true));
});
it('uncompletes daily when direction is down', () => {
return api.post(`/tasks/${daily._id}/score/down`)
.then((res) => api.get(`/tasks/${daily._id}`))
return user.post(`/tasks/${daily._id}/score/down`)
.then((res) => user.get(`/tasks/${daily._id}`))
.then((task) => expect(task.completed).to.equal(false));
});
@@ -176,48 +174,48 @@ describe('POST /tasks/:id/score/:direction', () => {
it('scores down daily even if it is already uncompleted'); // Yes?
it('increases user\'s mp when direction is up', () => {
return api.post(`/tasks/${daily._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${daily._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
});
});
it('decreases user\'s mp when direction is down', () => {
return api.post(`/tasks/${daily._id}/score/down`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${daily._id}/score/down`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
});
});
it('increases user\'s exp when direction is up', () => {
return api.post(`/tasks/${daily._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${daily._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
});
});
it('decreases user\'s exp when direction is down', () => {
return api.post(`/tasks/${daily._id}/score/down`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${daily._id}/score/down`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
});
});
it('increases user\'s gold when direction is up', () => {
return api.post(`/tasks/${daily._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${daily._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
});
});
it('decreases user\'s gold when direction is down', () => {
return api.post(`/tasks/${daily._id}/score/down`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${daily._id}/score/down`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
});
@@ -228,26 +226,26 @@ describe('POST /tasks/:id/score/:direction', () => {
let habit, minusHabit, plusHabit, neitherHabit;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
}).then((task) => {
habit = task;
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test min habit',
type: 'habit',
up: false,
});
}).then((task) => {
minusHabit = task;
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test plus habit',
type: 'habit',
down: false,
})
}).then((task) => {
plusHabit = task;
api.post('/tasks', {
user.post('/tasks', {
text: 'test neither habit',
type: 'habit',
up: false,
@@ -263,32 +261,32 @@ describe('POST /tasks/:id/score/:direction', () => {
it('prevents minus only habit from scoring up'); // Yes?
it('increases user\'s mp when direction is up', () => {
return api.post(`/tasks/${habit._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${habit._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
});
});
it('decreases user\'s mp when direction is down', () => {
return api.post(`/tasks/${habit._id}/score/down`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${habit._id}/score/down`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
});
});
it('increases user\'s exp when direction is up', () => {
return api.post(`/tasks/${habit._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${habit._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
});
});
it('increases user\'s gold when direction is up', () => {
return api.post(`/tasks/${habit._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${habit._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
});
@@ -299,7 +297,7 @@ describe('POST /tasks/:id/score/:direction', () => {
let reward;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test reward',
type: 'reward',
value: 5,
@@ -309,32 +307,32 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('purchases reward', () => {
return api.post(`/tasks/${reward._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${reward._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(user.stats.gp).to.equal(updatedUser.stats.gp + 5);
});
});
it('does not change user\'s mp', () => {
return api.post(`/tasks/${reward._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${reward._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp).to.equal(updatedUser.stats.mp);
});
});
it('does not change user\'s exp', () => {
return api.post(`/tasks/${reward._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${reward._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(user.stats.exp).to.equal(updatedUser.stats.exp);
});
});
it('does not allow a down direction', () => {
return api.post(`/tasks/${reward._id}/score/up`)
.then((res) => api.get(`/user`))
return user.post(`/tasks/${reward._id}/score/up`)
.then((res) => user.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp).to.equal(updatedUser.stats.mp);
});

View File

@@ -1,17 +1,15 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid';
describe('PUT /tasks/:id', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
@@ -19,7 +17,7 @@ describe('PUT /tasks/:id', () => {
let task;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
}).then((createdTask) => {
@@ -30,7 +28,7 @@ describe('PUT /tasks/:id', () => {
it(`ignores setting _id, type, userId, history, createdAt,
updatedAt, challenge, completed, streak,
dateCompleted fields`, () => {
api.put('/tasks/' + task._id, {
user.put('/tasks/' + task._id, {
_id: 123,
type: 'daily',
userId: 123,
@@ -56,7 +54,7 @@ describe('PUT /tasks/:id', () => {
});
it('ignores invalid fields', () => {
api.put('/tasks/' + task._id, {
user.put('/tasks/' + task._id, {
notValid: true,
}).then((savedTask) => {
expect(savedTask.notValid).to.be.a('undefined');
@@ -68,7 +66,7 @@ describe('PUT /tasks/:id', () => {
let habit;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test habit',
type: 'habit',
notes: 1976,
@@ -78,7 +76,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a habit', () => {
return api.put(`/tasks/${habit._id}`, {
return user.put(`/tasks/${habit._id}`, {
text: 'some new text',
up: false,
down: false,
@@ -96,7 +94,7 @@ describe('PUT /tasks/:id', () => {
let todo;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test todo',
type: 'todo',
notes: 1976,
@@ -106,7 +104,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a todo', () => {
return api.put(`/tasks/${todo._id}`, {
return user.put(`/tasks/${todo._id}`, {
text: 'some new text',
notes: 'some new notes',
}).then((task) => {
@@ -116,13 +114,13 @@ describe('PUT /tasks/:id', () => {
});
it('can update checklists (replace it)', () => {
return api.put(`/tasks/${todo._id}`, {
return user.put(`/tasks/${todo._id}`, {
checklist: [
{text: 123, completed: false},
{text: 456, completed: true},
]
}).then((savedTodo) => {
return api.put(`/tasks/${todo._id}`, {
return user.put(`/tasks/${todo._id}`, {
checklist: [
{text: 789, completed: false},
]
@@ -136,10 +134,10 @@ describe('PUT /tasks/:id', () => {
it('can update tags (replace them)', () => {
let finalUUID = generateUUID();
return api.put(`/tasks/${todo._id}`, {
return user.put(`/tasks/${todo._id}`, {
tags: [generateUUID(), generateUUID()],
}).then((savedTodo) => {
return api.put(`/tasks/${todo._id}`, {
return user.put(`/tasks/${todo._id}`, {
tags: [finalUUID]
});
}).then((savedTodo2) => {
@@ -153,7 +151,7 @@ describe('PUT /tasks/:id', () => {
let daily;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test daily',
type: 'daily',
notes: 1976,
@@ -165,7 +163,7 @@ describe('PUT /tasks/:id', () => {
it('updates a daily', () => {
let now = new Date();
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
text: 'some new text',
notes: 'some new notes',
frequency: 'daily',
@@ -179,13 +177,13 @@ describe('PUT /tasks/:id', () => {
});
it('can update checklists (replace it)', () => {
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
checklist: [
{text: 123, completed: false},
{text: 456, completed: true},
]
}).then((savedDaily) => {
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
checklist: [
{text: 789, completed: false},
]
@@ -199,10 +197,10 @@ describe('PUT /tasks/:id', () => {
it('can update tags (replace them)', () => {
let finalUUID = generateUUID();
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
tags: [generateUUID(), generateUUID()],
}).then((savedDaily) => {
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
tags: [finalUUID]
});
}).then((savedDaily2) => {
@@ -212,10 +210,10 @@ describe('PUT /tasks/:id', () => {
});
it('updates repeat, even if frequency is set to daily', () => {
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
frequency: 'daily',
}).then((savedDaily) => {
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
repeat: {
m: false,
su: false
@@ -235,10 +233,10 @@ describe('PUT /tasks/:id', () => {
});
it('updates everyX, even if frequency is set to weekly', () => {
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
frequency: 'weekly',
}).then((savedDaily) => {
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
everyX: 5,
});
}).then((savedDaily2) => {
@@ -247,7 +245,7 @@ describe('PUT /tasks/:id', () => {
});
it('defaults startDate to today if none date object is passed in', () => {
return api.put(`/tasks/${daily._id}`, {
return user.put(`/tasks/${daily._id}`, {
frequency: 'weekly',
}).then((savedDaily2) => {
expect((new Date(savedDaily2.startDate)).getDay()).to.eql((new Date()).getDay());
@@ -259,7 +257,7 @@ describe('PUT /tasks/:id', () => {
let reward;
beforeEach(() => {
return api.post('/tasks', {
return user.post('/tasks', {
text: 'test reward',
type: 'reward',
notes: 1976,
@@ -270,7 +268,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a reward', () => {
return api.put(`/tasks/${reward._id}`, {
return user.put(`/tasks/${reward._id}`, {
text: 'some new text',
notes: 'some new notes',
value: 10,
@@ -282,7 +280,7 @@ describe('PUT /tasks/:id', () => {
});
it('requires value to be coerced into a number', () => {
return api.put(`/tasks/${reward._id}`, {
return user.put(`/tasks/${reward._id}`, {
value: "100",
}).then((task) => {
expect(task.value).to.eql(100);

View File

@@ -1,33 +1,31 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid';
describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('deletes a checklist item', () => {
let task;
return api.post('/tasks', {
return user.post('/tasks', {
type: 'daily',
text: 'Daily with checklist',
}).then(createdTask => {
task = createdTask;
return api.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
return user.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
}).then((savedTask) => {
return api.del(`/tasks/${task._id}/checklist/${savedTask.checklist[0]._id}`);
return user.del(`/tasks/${task._id}/checklist/${savedTask.checklist[0]._id}`);
}).then(() => {
return api.get(`/tasks/${task._id}`);
return user.get(`/tasks/${task._id}`);
}).then((savedTask) => {
expect(savedTask.checklist.length).to.equal(0);
});
@@ -35,12 +33,12 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
it('does not work with habits', () => {
let habit;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habit',
text: 'habit with checklist',
}).then(createdTask => {
habit = createdTask;
return api.del(`/tasks/${habit._id}/checklist/${generateUUID()}`);
return user.del(`/tasks/${habit._id}/checklist/${generateUUID()}`);
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -50,12 +48,12 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
it('does not work with rewards', () => {
let reward;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'reward',
text: 'reward with checklist',
}).then(createdTask => {
reward = createdTask;
return api.del(`/tasks/${reward._id}/checklist/${generateUUID()}`);
return user.del(`/tasks/${reward._id}/checklist/${generateUUID()}`);
}).then(checklistItem => {})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -64,7 +62,7 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on task not found', () => {
return expect(api.del(`/tasks/${generateUUID()}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
return expect(user.del(`/tasks/${generateUUID()}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),
@@ -72,11 +70,11 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on checklist item not found', () => {
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'daily',
text: 'daily with checklist',
}).then(createdTask => {
return api.del(`/tasks/${createdTask._id}/checklist/${generateUUID()}`);
return user.del(`/tasks/${createdTask._id}/checklist/${generateUUID()}`);
})).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',

View File

@@ -1,29 +1,28 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:taskId/checklist/', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('adds a checklist item to a task', () => {
let task;
return api.post('/tasks', {
return user.post('/tasks', {
type: 'daily',
text: 'Daily with checklist',
}).then(createdTask => {
task = createdTask;
return api.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', ignored: false, _id: 123});
return user.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', ignored: false, _id: 123});
}).then((savedTask) => {
expect(savedTask.checklist.length).to.equal(1);
expect(savedTask.checklist[0].text).to.equal('Checklist Item 1');
@@ -36,12 +35,13 @@ describe('POST /tasks/:taskId/checklist/', () => {
it('does not add a checklist to habits', () => {
let habit;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habit',
text: 'habit with checklist',
}).then(createdTask => {
habit = createdTask;
return api.post(`/tasks/${habit._id}/checklist`, {text: 'Checklist Item 1'});
return user.post(`/tasks/${habit._id}/checklist`, {text: 'Checklist Item 1'});
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -51,12 +51,12 @@ describe('POST /tasks/:taskId/checklist/', () => {
it('does not add a checklist to rewards', () => {
let reward;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'reward',
text: 'reward with checklist',
}).then(createdTask => {
reward = createdTask;
return api.post(`/tasks/${reward._id}/checklist`, {text: 'Checklist Item 1'});
return user.post(`/tasks/${reward._id}/checklist`, {text: 'Checklist Item 1'});
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -65,7 +65,7 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('fails on task not found', () => {
return expect(api.post(`/tasks/${generateUUID()}/checklist`, {
return expect(user.post(`/tasks/${generateUUID()}/checklist`, {
text: 'Checklist Item 1'
})).to.eventually.be.rejected.and.eql({
code: 404,

View File

@@ -1,31 +1,29 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('scores a checklist item', () => {
let task;
return api.post('/tasks', {
return user.post('/tasks', {
type: 'daily',
text: 'Daily with checklist',
}).then(createdTask => {
task = createdTask;
return api.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
return user.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
}).then((savedTask) => {
return api.post(`/tasks/${task._id}/checklist/${savedTask.checklist[0]._id}/score`);
return user.post(`/tasks/${task._id}/checklist/${savedTask.checklist[0]._id}/score`);
}).then((savedTask) => {
expect(savedTask.checklist.length).to.equal(1);
expect(savedTask.checklist[0].completed).to.equal(true);
@@ -34,12 +32,12 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
it('fails on habits', () => {
let habit;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habit',
text: 'habit with checklist',
}).then(createdTask => {
habit = createdTask;
return api.post(`/tasks/${habit._id}/checklist/${generateUUID()}/score`, {text: 'Checklist Item 1'});
return user.post(`/tasks/${habit._id}/checklist/${generateUUID()}/score`, {text: 'Checklist Item 1'});
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -49,12 +47,12 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
it('fails on rewards', () => {
let reward;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'reward',
text: 'reward with checklist',
}).then(createdTask => {
reward = createdTask;
return api.post(`/tasks/${reward._id}/checklist/${generateUUID()}/score`);
return user.post(`/tasks/${reward._id}/checklist/${generateUUID()}/score`);
}).then(checklistItem => {})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -63,7 +61,7 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
});
it('fails on task not found', () => {
return expect(api.post(`/tasks/${generateUUID()}/checklist/${generateUUID()}/score`)).to.eventually.be.rejected.and.eql({
return expect(user.post(`/tasks/${generateUUID()}/checklist/${generateUUID()}/score`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),
@@ -71,11 +69,11 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
});
it('fails on checklist item not found', () => {
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'daily',
text: 'daily with checklist',
}).then(createdTask => {
return api.post(`/tasks/${createdTask._id}/checklist/${generateUUID()}/score`);
return user.post(`/tasks/${createdTask._id}/checklist/${generateUUID()}/score`);
})).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',

View File

@@ -1,31 +1,29 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid';
describe('PUT /tasks/:taskId/checklist/:itemId', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('updates a checklist item', () => {
let task;
return api.post('/tasks', {
return user.post('/tasks', {
type: 'daily',
text: 'Daily with checklist',
}).then(createdTask => {
task = createdTask;
return api.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
return user.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
}).then((savedTask) => {
return api.put(`/tasks/${task._id}/checklist/${savedTask.checklist[0]._id}`, {text: 'updated', completed: true, _id: 123});
return user.put(`/tasks/${task._id}/checklist/${savedTask.checklist[0]._id}`, {text: 'updated', completed: true, _id: 123});
}).then((savedTask) => {
expect(savedTask.checklist.length).to.equal(1);
expect(savedTask.checklist[0].text).to.equal('updated');
@@ -36,12 +34,12 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
it('fails on habits', () => {
let habit;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habit',
text: 'habit with checklist',
}).then(createdTask => {
habit = createdTask;
return api.put(`/tasks/${habit._id}/checklist/${generateUUID()}`);
return user.put(`/tasks/${habit._id}/checklist/${generateUUID()}`);
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -51,12 +49,12 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
it('fails on rewards', () => {
let reward;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'reward',
text: 'reward with checklist',
}).then(createdTask => {
reward = createdTask;
return api.put(`/tasks/${reward._id}/checklist/${generateUUID()}`);
return user.put(`/tasks/${reward._id}/checklist/${generateUUID()}`);
}).then(checklistItem => {})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -65,7 +63,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on task not found', () => {
return expect(api.put(`/tasks/${generateUUID()}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
return expect(user.put(`/tasks/${generateUUID()}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),
@@ -73,11 +71,11 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on checklist item not found', () => {
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'daily',
text: 'daily with checklist',
}).then(createdTask => {
return api.put(`/tasks/${createdTask._id}/checklist/${generateUUID()}`);
return user.put(`/tasks/${createdTask._id}/checklist/${generateUUID()}`);
})).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',

View File

@@ -1,17 +1,15 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid';
describe('DELETE /tasks/:taskId/tags/:tagId', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
@@ -19,18 +17,18 @@ describe('DELETE /tasks/:taskId/tags/:tagId', () => {
let tag;
let task;
return api.post('/tasks', {
return user.post('/tasks', {
type: 'habit',
text: 'Task with tag',
}).then(createdTask => {
task = createdTask;
return api.post('/tags', {name: 'Tag 1'});
return user.post('/tags', {name: 'Tag 1'});
}).then(createdTag => {
tag = createdTag;
return api.post(`/tasks/${task._id}/tags/${tag._id}`);
return user.post(`/tasks/${task._id}/tags/${tag._id}`);
}).then(savedTask => {
return api.del(`/tasks/${task._id}/tags/${tag._id}`);
}).then(() => api.get(`/tasks/${task._id}`))
return user.del(`/tasks/${task._id}/tags/${tag._id}`);
}).then(() => user.get(`/tasks/${task._id}`))
.then(updatedTask => {
expect(updatedTask.tags.length).to.equal(0);
});
@@ -39,11 +37,11 @@ describe('DELETE /tasks/:taskId/tags/:tagId', () => {
it('only deletes existing tags', () => {
let task;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habit',
text: 'Task with tag',
}).then(createdTask => {
return api.del(`/tasks/${createdTask._id}/tags/${generateUUID()}`);
return user.del(`/tasks/${createdTask._id}/tags/${generateUUID()}`);
})).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',

View File

@@ -1,17 +1,15 @@
import {
generateUser,
requester,
translate as t,
} from '../../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:taskId/tags/:tagId', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
@@ -19,15 +17,15 @@ describe('POST /tasks/:taskId/tags/:tagId', () => {
let tag;
let task;
return api.post('/tasks', {
return user.post('/tasks', {
type: 'habit',
text: 'Task with tag',
}).then(createdTask => {
task = createdTask;
return api.post('/tags', {name: 'Tag 1'});
return user.post('/tags', {name: 'Tag 1'});
}).then(createdTag => {
tag = createdTag;
return api.post(`/tasks/${task._id}/tags/${tag._id}`);
return user.post(`/tasks/${task._id}/tags/${tag._id}`);
}).then(savedTask => {
expect(savedTask.tags[0]).to.equal(tag._id);
});
@@ -37,17 +35,17 @@ describe('POST /tasks/:taskId/tags/:tagId', () => {
let tag;
let task;
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habit',
text: 'Task with tag',
}).then(createdTask => {
task = createdTask;
return api.post('/tags', {name: 'Tag 1'});
return user.post('/tags', {name: 'Tag 1'});
}).then(createdTag => {
tag = createdTag;
return api.post(`/tasks/${task._id}/tags/${tag._id}`);
return user.post(`/tasks/${task._id}/tags/${tag._id}`);
}).then(() => {
return api.post(`/tasks/${task._id}/tags/${tag._id}`);
return user.post(`/tasks/${task._id}/tags/${tag._id}`);
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -56,11 +54,11 @@ describe('POST /tasks/:taskId/tags/:tagId', () => {
});
it('does not add a non existing tag to a task', () => {
return expect(api.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habit',
text: 'Task with tag',
}).then((task) => {
return api.post(`/tasks/${task._id}/tags/${generateUUID()}`);
return user.post(`/tasks/${task._id}/tags/${generateUUID()}`);
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',

View File

@@ -1,31 +1,29 @@
import {
generateUser,
requester,
} from '../../../../helpers/api-integration.helper';
describe('GET /user', () => {
let user, api;
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
api = requester(user);
});
});
it('returns the authenticated user', () => {
return api.get('/user')
return user.get('/user')
.then(returnedUser => {
expect(returnedUser._id).to.equal(user._id);
});
});
it('does not return private paths (and apiToken)', () => {
return api.get('/user')
return user.get('/user')
.then(returnedUser => {
expect(returnedUser.auth.local.hashed_password).to.be.a('undefined');
expect(returnedUser.auth.local.salt).to.be.a('undefined');
expect(returnedUser.apiToken).to.be.a('undefined');
expect(returnedUser.auth.local.hashed_password).to.not.exist;
expect(returnedUser.auth.local.salt).to.not.exist;
expect(returnedUser.apiToken).to.not.exist;
});
});
});