2015-05-10 20:01:41 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
app = require("../../website/src/server")
|
2015-05-11 01:39:11 +00:00
|
|
|
rewire = require('rewire')
|
|
|
|
|
sinon = require('sinon')
|
2015-05-10 20:01:41 +00:00
|
|
|
|
|
|
|
|
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 20:01:41 +00:00
|
|
|
|
2015-05-10 21:36:10 +00:00
|
|
|
User.findOne
|
|
|
|
|
_id: global.user._id
|
|
|
|
|
, (err, _user) ->
|
|
|
|
|
expect(_user.pushDevices.length).to.be 1
|
|
|
|
|
expect(_user.pushDevices[0].regId).to.be "123123"
|
2015-05-10 20:01:41 +00:00
|
|
|
|
2015-05-10 21:36:10 +00:00
|
|
|
done()
|
2015-05-10 22:09:40 +00:00
|
|
|
|
|
|
|
|
describe "Events that send push notifications", ->
|
|
|
|
|
|
2015-05-11 01:39:11 +00:00
|
|
|
pushSpy = sinon.spy()
|
|
|
|
|
|
2015-05-10 22:09:40 +00:00
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
context "Gifts", ->
|
2015-05-11 01:39:11 +00:00
|
|
|
recipient = null
|
|
|
|
|
members = rewire("../../website/src/controllers/members")
|
|
|
|
|
members.__set__('pushNotify', pushSpy)
|
|
|
|
|
members.sendMessage = -> true
|
|
|
|
|
|
|
|
|
|
before (done) ->
|
|
|
|
|
registerNewUser (err, _user) ->
|
|
|
|
|
recipient = _user
|
|
|
|
|
user.balance = 4
|
|
|
|
|
members.__set__ 'fetchMember', (id) -> return (cb) -> cb(null, recipient)
|
|
|
|
|
done()
|
|
|
|
|
, false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "sends a push notification when gifted gems", (done) ->
|
|
|
|
|
req = {
|
|
|
|
|
params: { uuid: "uuid" },
|
|
|
|
|
body: {
|
|
|
|
|
type: 'gems',
|
|
|
|
|
gems: { amount: 1 }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
res = { locals: { user: user } }
|
|
|
|
|
|
|
|
|
|
members.sendGift req, res
|
|
|
|
|
|
|
|
|
|
expect(pushSpy.calledOnce).to.be.ok
|
2015-05-10 22:09:40 +00:00
|
|
|
|
2015-05-11 01:39:11 +00:00
|
|
|
done()
|
2015-05-10 22:09:40 +00:00
|
|
|
|
|
|
|
|
it "sends a push notification when gifted a subscription"
|