Merge branch 'develop' into TheHollidayInn-groups-api-tests

This commit is contained in:
Blade Barringer
2015-06-09 18:19:35 -05:00
579 changed files with 12329 additions and 9362 deletions
+49 -1
View File
@@ -1,4 +1,7 @@
'use strict'
#@TODO: Have to mock most things to get to the parts that
#call pushNotify. Consider refactoring group controller
#so things are easier to test
app = require("../../website/src/server")
rewire = require('rewire')
@@ -78,7 +81,6 @@ describe "Push-Notifications", ->
recipient = null
groups = rewire("../../website/src/controllers/groups")
groups.__set__('questStart', -> true)
groups.__set__('pushNotify', pushSpy)
before (done) ->
@@ -150,6 +152,7 @@ describe "Push-Notifications", ->
group = { _id: 'party-id', name: 'party-name', type: 'party', members: [user._id, recipient._id], invites: [], quest: {}}
user.items.quests.hedgehog = 5
group.save = (cb) -> cb(null, group)
group.markModified = -> true
req = {
body: { uuids: [recipient._id] }
query: { key: 'hedgehog' }
@@ -171,6 +174,51 @@ describe "Push-Notifications", ->
done()
, 100
it "sends a push notification to participating members when quest starts", (done) ->
group = { _id: 'party-id', name: 'party-name', type: 'party', members: [user._id, recipient._id], invites: []}
group.quest = {
key: 'hedgehog'
progress: { hp: 100 }
members: {}
}
group.quest.members[recipient._id] = true
group.save = (cb) -> cb(null, group)
group.markModified = -> true
req = {
body: { uuids: [recipient._id] }
query: { }
# force: true
}
res = {
locals: { group: group, user: user }
json: -> return true
}
userMock = {
findOne: (arg, arg2, cb) ->
cb(null, recipient)
update: (arg, arg2, cb) ->
cb(null, user)
}
groups.__set__('User', userMock)
groups.__set__('populateQuery',
(arg, arg2, arg3) ->
return {
exec: -> group.members
}
)
groups.questAccept req, res
setTimeout -> # Allow questAccept to finish
expect(pushSpy.sendNotify).to.have.been.calledTwice
expect(pushSpy.sendNotify).to.have.been.calledWith(
recipient,
'HabitRPG',
'Your Quest has Begun: The Hedgebeast'
)
done()
, 100
describe "Gifts", ->
recipient = null
+21
View File
@@ -97,6 +97,27 @@ describe "Todos", ->
expect(todo.value).to.equal 0
done()
it "Does not create a todo with an id that already exists", (done) ->
original_todo = {
type: "todo"
text: "original todo"
id: "custom-id"
}
duplicate_id_todo = {
type: "todo"
text: "not original todo"
id: "custom-id"
}
request.post(baseURL + "/user/tasks").send(
original_todo
).end (res) ->
request.post(baseURL + "/user/tasks").send(
duplicate_id_todo
).end (res) ->
expectCode res, 409
expect(res.body.err).to.eql('A task with that ID already exists.')
done()
describe "Updating todos", ->
it "Does not update id of todo", (done) ->
request.put(baseURL + "/user/tasks/" + todo.id).send(