mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
tried to add a test for purchased gem gift
This commit is contained in:
@@ -4,6 +4,8 @@ app = require("../../website/src/server")
|
|||||||
rewire = require('rewire')
|
rewire = require('rewire')
|
||||||
sinon = require('sinon')
|
sinon = require('sinon')
|
||||||
|
|
||||||
|
pushSpy = null
|
||||||
|
|
||||||
describe "Push-Notifications", ->
|
describe "Push-Notifications", ->
|
||||||
before (done) ->
|
before (done) ->
|
||||||
registerNewUser(done, true)
|
registerNewUser(done, true)
|
||||||
@@ -41,11 +43,11 @@ describe "Push-Notifications", ->
|
|||||||
|
|
||||||
it "sends a push notification when invited to a quest"
|
it "sends a push notification when invited to a quest"
|
||||||
|
|
||||||
context "sending gems from balance", ->
|
describe "Gifts", ->
|
||||||
recipient = null
|
|
||||||
members = rewire("../../website/src/controllers/members")
|
members = rewire("../../website/src/controllers/members")
|
||||||
members.sendMessage = -> true
|
members.sendMessage = -> true
|
||||||
members.__set__('pushNotify', pushSpy)
|
|
||||||
|
recipient = null
|
||||||
|
|
||||||
before (done) ->
|
before (done) ->
|
||||||
registerNewUser (err, _user) ->
|
registerNewUser (err, _user) ->
|
||||||
@@ -53,37 +55,69 @@ describe "Push-Notifications", ->
|
|||||||
user.balance = 4
|
user.balance = 4
|
||||||
user.save = -> return true
|
user.save = -> return true
|
||||||
recipient.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()
|
done()
|
||||||
, false
|
, false
|
||||||
|
|
||||||
it "sends a push notification", (done) ->
|
context "sending gems from balance", ->
|
||||||
req = {
|
pushSpy = { sendNotify: sinon.spy() }
|
||||||
params: { uuid: "uuid" },
|
members.__set__('pushNotify', pushSpy)
|
||||||
body: {
|
|
||||||
type: 'gems',
|
it "sends a push notification", (done) ->
|
||||||
gems: { amount: 1 }
|
req = {
|
||||||
|
params: { uuid: "uuid" },
|
||||||
|
body: {
|
||||||
|
type: 'gems',
|
||||||
|
gems: { amount: 1 }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
res = { locals: { user: user } }
|
||||||
res = { locals: { user: user } }
|
|
||||||
|
|
||||||
members.sendGift req, res
|
members.sendGift req, res
|
||||||
|
|
||||||
setTimeout ->
|
setTimeout ->
|
||||||
# Allow sendGift to finish
|
# Allow sendGift to finish
|
||||||
expect(pushSpy.sendNotify).to.have.been.calledOnce
|
expect(pushSpy.sendNotify).to.have.been.calledOnce
|
||||||
expect(pushSpy.sendNotify).to.have.been.calledWith(
|
expect(pushSpy.sendNotify).to.have.been.calledWith(
|
||||||
recipient,
|
recipient,
|
||||||
'Gifted Gems',
|
'Gifted Gems',
|
||||||
'1 Gems - by ' + user.profile.name
|
'1 Gems - by ' + user.profile.name
|
||||||
)
|
)
|
||||||
done()
|
done()
|
||||||
, 100
|
, 100
|
||||||
|
|
||||||
context "sending gems as a purchased gift", ->
|
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)
|
||||||
|
|
||||||
context "sending a subscription as a purchased gift", ->
|
it "sends a push notification", (done) ->
|
||||||
|
data = {
|
||||||
|
user: user,
|
||||||
|
gift: {
|
||||||
|
member: recipient,
|
||||||
|
gems: { amount: 1 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
it "sends a push notification"
|
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", ->
|
||||||
|
|
||||||
|
it "sends a push notification"
|
||||||
|
|||||||
Reference in New Issue
Block a user