habitica/test/api/pushNotifications.coffee

90 lines
2.4 KiB
CoffeeScript
Raw Normal View History

'use strict'
app = require("../../website/src/server")
rewire = require('rewire')
sinon = require('sinon')
describe "Push-Notifications", ->
2015-05-10 21:36:10 +00:00
before (done) ->
registerNewUser(done, true)
describe "POST /user/pushDevice", ->
it "Registers a DeviceID", (done) ->
request.post(baseURL + "/user/pushDevice").send(
{ regId: "123123", type: "android"}
).end (res) ->
expectCode res, 200
2015-05-10 21:36:10 +00:00
User.findOne
_id: global.user._id
, (err, _user) ->
expect(_user.pushDevices.length).to.equal 1
expect(_user.pushDevices[0].regId).to.equal "123123"
2015-05-10 21:36:10 +00:00
done()
describe "Events that send push notifications", ->
2015-05-11 03:13:53 +00:00
pushSpy = { sendNotify: sinon.spy() }
context "Challenges", ->
it "sends a push notification when you win a challenge"
it "does not send a push notification when you lose a challenge"
context "Groups", ->
it "sends a push notification when invited to a guild"
it "sends a push notification when invited to a party"
it "sends a push notification when invited to a quest"
2015-05-12 14:04:07 +00:00
context "sending gems from balance", ->
recipient = null
members = rewire("../../website/src/controllers/members")
members.sendMessage = -> true
2015-05-11 03:13:53 +00:00
members.__set__('pushNotify', pushSpy)
before (done) ->
registerNewUser (err, _user) ->
recipient = _user
user.balance = 4
2015-05-11 03:13:53 +00:00
user.save = -> return true
recipient.save = -> return true
members.__set__ 'fetchMember', (id) -> return (cb) -> cb(null, recipient)
done()
, false
2015-05-12 14:04:07 +00:00
it "sends a push notification", (done) ->
2015-05-11 03:13:53 +00:00
req = {
params: { uuid: "uuid" },
2015-05-11 03:13:53 +00:00
body: {
type: 'gems',
gems: { amount: 1 }
2015-05-11 03:13:53 +00:00
}
}
res = { locals: { user: user } }
members.sendGift req, res
setTimeout ->
# Allow sendGift to finish
expect(pushSpy.sendNotify).to.have.been.calledOnce
expect(pushSpy.sendNotify).to.have.been.calledWith(
recipient,
'Gifted Gems',
'1 Gems - by ' + user.profile.name
)
done()
, 100
2015-05-12 14:04:07 +00:00
context "sending gems as a purchased gift", ->
it "sends a push notification"
context "sending a subscription as a purchased gift", ->
it "sends a push notification"