mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
finish implementing tests for POST-tasks.test.js
This commit is contained in:
@@ -37,9 +37,24 @@ describe('POST /tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if req.body.text is absent');
|
||||
it('returns an error if req.body.text is absent', () => {
|
||||
return expect(api.post('/tasks', {
|
||||
type: 'habit',
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores setting userId field');
|
||||
it('ignores setting userId field', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
userId: 123,
|
||||
}).then((task) => {
|
||||
expect(task.userId).to.equal(user._id);
|
||||
});
|
||||
});
|
||||
|
||||
it('automatically sets "task.userId" to user\'s uuid', () => {
|
||||
return api.post('/tasks', {
|
||||
@@ -52,9 +67,39 @@ describe('POST /tasks', () => {
|
||||
|
||||
it(`ignores setting userId, history, createdAt,
|
||||
updatedAt, challenge, completed, streak,
|
||||
dateCompleted fields`);
|
||||
dateCompleted fields`, () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
userId: 123,
|
||||
history: [123],
|
||||
createdAt: 'yesterday',
|
||||
updatedAt: 'tomorrow',
|
||||
challenge: 'no',
|
||||
completed: true,
|
||||
streak: 25,
|
||||
dateCompleted: 'never',
|
||||
}).then((task) => {
|
||||
expect(task.userId).to.equal(user._id);
|
||||
expect(task.history).to.eql([]);
|
||||
expect(task.createdAt).not.to.equal('yesterday');
|
||||
expect(task.updatedAt).not.to.equal('tomorrow');
|
||||
expect(task.challenge).not.to.equal('no');
|
||||
expect(task.completed).to.equal(false);
|
||||
expect(task.streak).to.equal(0);
|
||||
expect(task.streak).not.to.equal('never');
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores invalid fields');
|
||||
it('ignores invalid fields', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
notValid: true,
|
||||
}).then((task) => {
|
||||
expect(task).not.to.have.property('notValid');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('habits', () => {
|
||||
@@ -75,9 +120,28 @@ describe('POST /tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults to setting up and down to true');
|
||||
it('defaults to setting up and down to true', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
notes: 1976,
|
||||
}).then((task) => {
|
||||
expect(task.up).to.eql(true);
|
||||
expect(task.down).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot create checklists');
|
||||
it('cannot create checklists', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
checklist: [
|
||||
{_id: 123, completed: false, text: 'checklist'},
|
||||
],
|
||||
}).then((task) => {
|
||||
expect(task).not.to.have.property('checklist');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('todos', () => {
|
||||
@@ -94,7 +158,22 @@ describe('POST /tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('can create checklists');
|
||||
it('can create checklists', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
checklist: [
|
||||
{completed: false, text: 'checklist'},
|
||||
],
|
||||
}).then((task) => {
|
||||
expect(task.checklist).to.be.an('array');
|
||||
expect(task.checklist.length).to.eql(1);
|
||||
expect(task.checklist[0]).to.be.an('object');
|
||||
expect(task.checklist[0].text).to.eql('checklist');
|
||||
expect(task.checklist[0].completed).to.eql(false);
|
||||
expect(task.checklist[0]._id).to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('dailys', () => {
|
||||
@@ -119,13 +198,74 @@ describe('POST /tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults to a weekly frequency, with every day set');
|
||||
it('defaults to a weekly frequency, with every day set', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
}).then((task) => {
|
||||
expect(task.frequency).to.eql('weekly');
|
||||
expect(task.everyX).to.eql(1);
|
||||
expect(task.repeat).to.eql({
|
||||
m: true,
|
||||
t: true,
|
||||
w: true,
|
||||
th: true,
|
||||
f: true,
|
||||
s: true,
|
||||
su: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('allows repeat field to be configured');
|
||||
it('allows repeat field to be configured', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
repeat: {
|
||||
m: false,
|
||||
w: false,
|
||||
su: false,
|
||||
},
|
||||
}).then((task) => {
|
||||
expect(task.repeat).to.eql({
|
||||
m: false,
|
||||
t: true,
|
||||
w: false,
|
||||
th: true,
|
||||
f: true,
|
||||
s: true,
|
||||
su: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults startDate to today');
|
||||
it('defaults startDate to today', () => {
|
||||
let today = (new Date()).getDay();
|
||||
|
||||
it('can create checklists');
|
||||
return api.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
}).then((task) => {
|
||||
expect((new Date(task.startDate)).getDay()).to.eql(today);
|
||||
});
|
||||
});
|
||||
|
||||
it('can create checklists', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
checklist: [
|
||||
{completed: false, text: 'checklist'},
|
||||
],
|
||||
}).then((task) => {
|
||||
expect(task.checklist).to.be.an('array');
|
||||
expect(task.checklist.length).to.eql(1);
|
||||
expect(task.checklist[0]).to.be.an('object');
|
||||
expect(task.checklist[0].text).to.eql('checklist');
|
||||
expect(task.checklist[0].completed).to.eql(false);
|
||||
expect(task.checklist[0]._id).to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('rewards', () => {
|
||||
@@ -144,10 +284,35 @@ describe('POST /tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults to a 0 value');
|
||||
it('defaults to a 0 value', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
}).then((task) => {
|
||||
expect(task.value).to.eql(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('requires value to be coerced into a number');
|
||||
it('requires value to be coerced into a number', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
value: "10",
|
||||
}).then((task) => {
|
||||
expect(task.value).to.eql(10);
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot create checklists');
|
||||
it('cannot create checklists', () => {
|
||||
return api.post('/tasks', {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
checklist: [
|
||||
{_id: 123, completed: false, text: 'checklist'},
|
||||
],
|
||||
}).then((task) => {
|
||||
expect(task).not.to.have.property('checklist');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user