Refactor push notifications test; Prevent push notification from being sent when buying gems for yourself as a gift

This commit is contained in:
Blade Barringer
2015-05-12 20:18:06 -05:00
parent 9a84503aed
commit 8a4abc632f
2 changed files with 51 additions and 27 deletions
+47 -25
View File
@@ -24,6 +24,11 @@ describe "Push-Notifications", ->
done()
describe "Events that send push notifications", ->
pushSpy = { sendNotify: sinon.spy() }
afterEach (done) ->
pushSpy.sendNotify.reset()
done()
context "Challenges", ->
@@ -73,8 +78,7 @@ describe "Push-Notifications", ->
members.sendGift req, res
setTimeout ->
# Allow sendGift to finish
setTimeout -> # Allow sendGift to finish
expect(pushSpy.sendNotify).to.have.been.calledOnce
expect(pushSpy.sendNotify).to.have.been.calledWith(
recipient,
@@ -84,37 +88,55 @@ describe "Push-Notifications", ->
done()
, 100
context "sending gems as a purchased gift", ->
membersMock = { sendMessage: -> true }
pushSpy = { sendNotify: sinon.spy() }
describe "Purchases", ->
payments = rewire("../../website/src/controllers/payments")
payments.__set__('pushNotify', pushSpy)
membersMock = { sendMessage: -> true }
payments.__set__('members', membersMock)
it "sends a push notification", (done) ->
data = {
user: user,
gift: {
member: recipient,
gems: { amount: 1 }
context "buying gems as a purchased gift", ->
it "sends a push notification", (done) ->
data = {
user: user,
gift: {
member: recipient,
gems: { amount: 1 }
}
}
}
payments.buyGems data
payments.buyGems data
setTimeout ->
# Allow buyGems 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
)
setTimeout -> # Allow buyGems 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
done()
, 100
context "sending a subscription as a purchased gift", ->
it "does not send a push notification if buying gems for self", (done) ->
data = {
user: user,
gift: {
member: user
gems: { amount: 1 }
}
}
it "sends a push notification"
payments.buyGems data
setTimeout -> # Allow buyGems to finish
expect(pushSpy.sendNotify).to.not.have.been.called
done()
, 100
context "sending a subscription as a purchased gift", ->
it "sends a push notification"
+4 -2
View File
@@ -136,7 +136,9 @@ exports.buyGems = function(data, cb) {
]);
}
pushNotify.sendNotify(data.gift.member, shared.i18n.t('giftedGems'), gemAmount + ' Gems - 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('giftedGems'), gemAmount + ' Gems - by '+byUsername);
}
}
async.parallel([
function(cb2){data.user.save(cb2)},
@@ -164,4 +166,4 @@ exports.paypalCheckoutSuccess = paypal.executePayment;
exports.paypalIPN = paypal.ipn;
exports.iapAndroidVerify = iap.androidVerify;
exports.iapIosVerify = iap.iosVerify;
exports.iapIosVerify = iap.iosVerify;