tried to add a test for purchased gem gift

This commit is contained in:
Negue
2015-05-12 21:36:22 +02:00
parent b635c62d16
commit adef6bef7b

View File

@@ -4,6 +4,8 @@ app = require("../../website/src/server")
rewire = require('rewire')
sinon = require('sinon')
pushSpy = null
describe "Push-Notifications", ->
before (done) ->
registerNewUser(done, true)
@@ -41,11 +43,11 @@ describe "Push-Notifications", ->
it "sends a push notification when invited to a quest"
context "sending gems from balance", ->
recipient = null
describe "Gifts", ->
members = rewire("../../website/src/controllers/members")
members.sendMessage = -> true
members.__set__('pushNotify', pushSpy)
recipient = null
before (done) ->
registerNewUser (err, _user) ->
@@ -53,10 +55,15 @@ describe "Push-Notifications", ->
user.balance = 4
user.save = -> return true
recipient.save = -> return true
members.__set__ 'fetchMember', (id) -> return (cb) -> cb(null, recipient)
members.__set__ 'fetchMember', (id) ->
return (cb) -> cb(null, recipient)
done()
, false
context "sending gems from balance", ->
pushSpy = { sendNotify: sinon.spy() }
members.__set__('pushNotify', pushSpy)
it "sends a push notification", (done) ->
req = {
params: { uuid: "uuid" },
@@ -81,8 +88,35 @@ describe "Push-Notifications", ->
, 100
context "sending gems as a purchased gift", ->
pushSpy = { sendNotify: sinon.spy() }
it "sends a push notification"
payments = rewire("../../website/src/controllers/payments")
payments.__set__('pushNotify', pushSpy)
payments.__set__('members', members)
it "sends a push notification", (done) ->
data = {
user: user,
gift: {
member: recipient,
gems: { amount: 1 }
}
}
payments.buyGems data, (d) ->
d()
setTimeout ->
# Allow sendGift 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
context "sending a subscription as a purchased gift", ->