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)},