mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
wip get and create tasks plus initial user syncing
This commit is contained in:
@@ -1,42 +1,31 @@
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../../../helpers/api-integration.helper';
|
||||
import Q from 'q';
|
||||
|
||||
describe('GET /tasks', () => {
|
||||
let user;
|
||||
|
||||
before(() => {
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
before(async () => {
|
||||
return generateUser().then((generatedUser) => {
|
||||
user = generatedUser;
|
||||
});
|
||||
});
|
||||
|
||||
it('returns all user\'s tasks', () => {
|
||||
let length;
|
||||
return Q.all([
|
||||
user.post('/tasks', {text: 'test habit', type: 'habit'}),
|
||||
])
|
||||
.then((createdTasks) => {
|
||||
length = createdTasks.length;
|
||||
return user.get('/tasks');
|
||||
})
|
||||
.then((tasks) => {
|
||||
expect(tasks.length).to.equal(length + 1); // + 1 because 1 is a default task
|
||||
});
|
||||
it('returns all user\'s tasks', async () => {
|
||||
let createdTasks = await user.post('/tasks', [{text: 'test habit', type: 'habit'}, {text: 'test todo', type: 'todo'}]);
|
||||
let tasks = await user.get('/tasks/user');
|
||||
expect(tasks.length).to.equal(createdTasks.length + 1); // + 1 because 1 is a default task
|
||||
});
|
||||
|
||||
it('returns only a type of user\'s tasks if req.query.type is specified', () => {
|
||||
let habitId;
|
||||
user.post('/tasks', {text: 'test habit', type: 'habit'})
|
||||
.then((task) => {
|
||||
habitId = task._id;
|
||||
return user.get('/tasks?type=habit');
|
||||
})
|
||||
.then((tasks) => {
|
||||
expect(tasks.length).to.equal(1);
|
||||
expect(tasks[0]._id).to.equal(habitId);
|
||||
});
|
||||
it('returns only a type of user\'s tasks if req.query.type is specified', async () => {
|
||||
let createdTasks = await user.post('/tasks', [{text: 'test habit', type: 'habit'}, {text: 'test todo', type: 'todo'}]);
|
||||
let tasks = await user.get('/tasks/user?type=habit');
|
||||
expect(tasks.length).to.equal(1);
|
||||
expect(tasks[0]._id).to.equal(createdTasks[0]._id);
|
||||
});
|
||||
|
||||
// TODO complete after task scoring is done
|
||||
|
||||
Reference in New Issue
Block a user