habitica-self-host/test/api-legacy/todos.coffee

83 lines
2 KiB
CoffeeScript
Raw Normal View History

2015-05-07 13:13:43 +00:00
'use strict'
2015-05-07 22:37:07 +00:00
require("../../website/src/server")
2015-05-07 13:13:43 +00:00
2015-05-07 22:37:07 +00:00
describe "Todos", ->
2015-05-07 13:13:43 +00:00
before (done) ->
2015-05-07 22:37:07 +00:00
registerNewUser done, true
beforeEach (done) ->
User.findById user._id, (err, _user) ->
user = _user
shared.wrap user
done()
it "Archives old todos", (done) ->
numTasks = _.size(user.todos)
request.post(baseURL + "/user/batch-update?_v=999").send([
{
op: "addTask"
body:
type: "todo"
}
{
op: "addTask"
body:
type: "todo"
}
{
op: "addTask"
body:
type: "todo"
}
2015-10-21 01:17:10 +00:00
]).end (err, res) ->
2015-05-07 22:37:07 +00:00
expectCode res, 200
# Expect number of todos to be 3 greater than the number the user started with
2015-05-11 13:13:23 +00:00
expect(_.size(res.body.todos)).to.equal numTasks + 3
2015-05-07 22:37:07 +00:00
# Assign new number to numTasks variable
numTasks += 3
request.post(baseURL + "/user/batch-update?_v=998").send([
{
op: "score"
params:
direction: "up"
id: res.body.todos[0].id
}
{
op: "score"
params:
direction: "up"
id: res.body.todos[1].id
}
{
op: "score"
params:
direction: "up"
id: res.body.todos[2].id
}
2015-10-21 01:17:10 +00:00
]).end (err, res) ->
2015-05-07 22:37:07 +00:00
expectCode res, 200
2015-05-11 13:13:23 +00:00
expect(_.size(res.body.todos)).to.equal numTasks
2015-05-07 22:37:07 +00:00
request.post(baseURL + "/user/batch-update?_v=997").send([
2015-05-07 13:13:43 +00:00
{
2015-05-07 22:37:07 +00:00
op: "updateTask"
params:
id: res.body.todos[0].id
2015-05-07 13:13:43 +00:00
body:
2015-05-07 22:37:07 +00:00
dateCompleted: moment().subtract(4, "days")
2015-05-07 13:13:43 +00:00
}
{
2015-05-07 22:37:07 +00:00
op: "updateTask"
params:
id: res.body.todos[1].id
2015-05-07 13:13:43 +00:00
body:
2015-05-07 22:37:07 +00:00
dateCompleted: moment().subtract(4, "days")
2015-05-07 13:13:43 +00:00
}
2015-10-21 01:17:10 +00:00
]).end (err, res) ->
2015-05-07 22:37:07 +00:00
# Expect todos to be 2 less than the total count
2015-05-11 13:13:23 +00:00
expect(_.size(res.body.todos)).to.equal numTasks - 2
2015-05-07 22:37:07 +00:00
done()