From d4a296870b837a9d22aa329feda9649a319fb786 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sun, 10 May 2015 20:39:11 -0500 Subject: [PATCH] Add test for push notification when gems are sent --- package.json | 1 + test/api/pushNotifications.coffee | 33 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ad8788efd7..252f2a144a 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,7 @@ "mongoskin": "~0.6.1", "phantomjssmith": "~0.5.4", "protractor": "~2.0.0", + "rewire": "^2.3.3", "rimraf": "^2.2.8", "shelljs": "^0.4.0", "sinon": "^1.12.2", diff --git a/test/api/pushNotifications.coffee b/test/api/pushNotifications.coffee index 67caa784f7..83f7400cbf 100644 --- a/test/api/pushNotifications.coffee +++ b/test/api/pushNotifications.coffee @@ -1,6 +1,8 @@ 'use strict' app = require("../../website/src/server") +rewire = require('rewire') +sinon = require('sinon') describe "Push-Notifications", -> before (done) -> @@ -23,6 +25,8 @@ describe "Push-Notifications", -> describe "Events that send push notifications", -> + pushSpy = sinon.spy() + context "Challenges", -> it "sends a push notification when you win a challenge" @@ -38,7 +42,34 @@ describe "Push-Notifications", -> it "sends a push notification when invited to a quest" context "Gifts", -> + recipient = null + members = rewire("../../website/src/controllers/members") + members.__set__('pushNotify', pushSpy) + members.sendMessage = -> true - it "sends a push notification when gifted gems" + 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 + + done() it "sends a push notification when gifted a subscription"