From 023458b6e550a113e627de5b86a21543412f5aa1 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Wed, 13 May 2015 19:31:26 -0500 Subject: [PATCH] Add test for getting push notification when gifted a subscription --- test/api/pushNotifications.coffee | 39 ++++++++++++++++++++++- website/src/controllers/payments/index.js | 4 ++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/test/api/pushNotifications.coffee b/test/api/pushNotifications.coffee index 657feead64..25de0b13f8 100644 --- a/test/api/pushNotifications.coffee +++ b/test/api/pushNotifications.coffee @@ -139,4 +139,41 @@ describe "Push-Notifications", -> context "sending a subscription as a purchased gift", -> - it "sends a push notification" + it "sends a push notification", (done) -> + data = { + user: user, + gift: { + member: recipient + subscription: { key: 'basic_6mo' } + } + } + + payments.createSubscription data + + setTimeout -> # Allow createSubscription to finish + expect(pushSpy.sendNotify).to.have.been.calledOnce + expect(pushSpy.sendNotify).to.have.been.calledWith( + recipient, + 'Gifted Subscription', + '6 months - by ' + user.profile.name + ) + + done() + , 100 + + it "does not send a push notification if buying subscription for self", (done) -> + data = { + user: user, + gift: { + member: user + subscription: { key: 'basic_6mo' } + } + } + + payments.createSubscription data + + setTimeout -> # Allow buyGems to finish + expect(pushSpy.sendNotify).to.not.have.been.called + + done() + , 100 diff --git a/website/src/controllers/payments/index.js b/website/src/controllers/payments/index.js index 3d47055759..31d691a7fe 100644 --- a/website/src/controllers/payments/index.js +++ b/website/src/controllers/payments/index.js @@ -86,7 +86,9 @@ exports.createSubscription = function(data, cb) { ]); } - pushNotify.sendNotify(data.gift.member, shared.i18n.t('gifted-subscription'), months + " months - by "+ byUserName); + if (data.gift.member._id != data.user._id) { // Only send push notifications if sending to a user other than yourself + pushNotify.sendNotify(data.gift.member, shared.i18n.t('giftedSubscription'), months + " months - by "+ byUserName); + } } async.parallel([ function(cb2){data.user.save(cb2)},