Merge branch 'develop' into hairlessbear-quest_invite_modal_on_user_sync
This commit is contained in:
@@ -0,0 +1,281 @@
|
||||
'use strict'
|
||||
|
||||
app = require('../../website/src/server')
|
||||
rewire = require('rewire')
|
||||
sinon = require('sinon')
|
||||
inApp = rewire('../../website/src/controllers/payments/iap')
|
||||
iapMock = { }
|
||||
inApp.__set__('iap', iapMock)
|
||||
|
||||
describe 'In-App Purchases', ->
|
||||
describe 'Android', ->
|
||||
req = {
|
||||
body: {
|
||||
transaction: {
|
||||
reciept: 'foo'
|
||||
signature: 'sig'
|
||||
}
|
||||
}
|
||||
}
|
||||
res = {
|
||||
locals: { user: { _id: 'user' } }
|
||||
json: sinon.spy()
|
||||
}
|
||||
next = -> true
|
||||
paymentSpy = sinon.spy()
|
||||
|
||||
before ->
|
||||
inApp.__set__('payments.buyGems', paymentSpy)
|
||||
|
||||
afterEach ->
|
||||
paymentSpy.reset()
|
||||
res.json.reset()
|
||||
|
||||
context 'successful app purchase', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb(null)
|
||||
iapMock.validate = (iapGoogle, iapBodyReciept, cb)-> return cb(null, true)
|
||||
iapMock.isValidated = (googleRes)-> return googleRes
|
||||
iapMock.GOOGLE = 'google'
|
||||
|
||||
it 'calls res.json with succesful result object', ->
|
||||
expectedResObj = {
|
||||
ok: true
|
||||
data: true
|
||||
}
|
||||
|
||||
inApp.androidVerify(req, res, next)
|
||||
|
||||
expect(res.json).to.be.calledOnce
|
||||
expect(res.json).to.be.calledWith(expectedResObj)
|
||||
|
||||
it 'calls payments.buyGems function', ->
|
||||
inApp.androidVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.be.calledOnce
|
||||
expect(paymentSpy).to.be.calledWith({user: res.locals.user, paymentMethod:'IAP GooglePlay'})
|
||||
|
||||
context 'error in setup', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb("error in setup")
|
||||
|
||||
it 'calls res.json with setup error object', ->
|
||||
expectedResObj = {
|
||||
ok: false
|
||||
data: 'IAP Error'
|
||||
}
|
||||
|
||||
inApp.androidVerify(req, res, next)
|
||||
|
||||
expect(res.json).to.be.calledOnce
|
||||
expect(res.json).to.be.calledWith(expectedResObj)
|
||||
|
||||
it 'does not calls payments.buyGems function', ->
|
||||
inApp.androidVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.not.be.called
|
||||
|
||||
context 'error in validation', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb(null)
|
||||
iapMock.validate = (iapGoogle, iapBodyReciept, cb)-> return cb('error in validation', true)
|
||||
|
||||
it 'calls res.json with validation error object', ->
|
||||
expectedResObj = {
|
||||
ok: false
|
||||
data: {
|
||||
code: 6778001
|
||||
message: 'error in validation'
|
||||
}
|
||||
}
|
||||
|
||||
inApp.androidVerify(req, res, next)
|
||||
|
||||
expect(res.json).to.be.calledOnce
|
||||
expect(res.json).to.be.calledWith(expectedResObj)
|
||||
|
||||
it 'does not calls payments.buyGems function', ->
|
||||
inApp.androidVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.not.be.called
|
||||
|
||||
context 'iap is not valid', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb(null)
|
||||
iapMock.validate = (iapGoogle, iapBodyReciept, cb)-> return cb(null, false)
|
||||
iapMock.isValidated = (googleRes)-> return googleRes
|
||||
|
||||
it 'does not call res.json', ->
|
||||
inApp.androidVerify(req, res, next)
|
||||
|
||||
expect(res.json).to.not.be.called
|
||||
|
||||
it 'does not calls payments.buyGems function', ->
|
||||
inApp.androidVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.not.be.called
|
||||
|
||||
describe 'iOS', ->
|
||||
req = { body: { transaction: { reciept: 'foo' } } }
|
||||
res = {
|
||||
locals: { user: { _id: 'user' } }
|
||||
json: sinon.spy()
|
||||
}
|
||||
next = -> true
|
||||
paymentSpy = sinon.spy()
|
||||
|
||||
before ->
|
||||
inApp.__set__('payments.buyGems', paymentSpy)
|
||||
|
||||
afterEach ->
|
||||
paymentSpy.reset()
|
||||
res.json.reset()
|
||||
|
||||
context 'successful app purchase', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb(null)
|
||||
iapMock.validate = (iapApple, iapBodyReciept, cb)-> return cb(null, true)
|
||||
iapMock.isValidated = (appleRes)-> return appleRes
|
||||
iapMock.getPurchaseData = (appleRes)->
|
||||
return [{ productId: 'com.habitrpg.ios.Habitica.20gems' }]
|
||||
iapMock.APPLE = 'apple'
|
||||
|
||||
it 'calls res.json with succesful result object', ->
|
||||
expectedResObj = {
|
||||
ok: true
|
||||
data: true
|
||||
}
|
||||
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(res.json).to.be.calledOnce
|
||||
expect(res.json).to.be.calledWith(expectedResObj)
|
||||
|
||||
it 'calls payments.buyGems function', ->
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.be.calledOnce
|
||||
expect(paymentSpy).to.be.calledWith({user: res.locals.user, paymentMethod:'IAP AppleStore'})
|
||||
|
||||
context 'error in setup', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb("error in setup")
|
||||
|
||||
it 'calls res.json with setup error object', ->
|
||||
expectedResObj = {
|
||||
ok: false
|
||||
data: 'IAP Error'
|
||||
}
|
||||
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(res.json).to.be.calledOnce
|
||||
expect(res.json).to.be.calledWith(expectedResObj)
|
||||
|
||||
it 'does not calls payments.buyGems function', ->
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.not.be.called
|
||||
|
||||
context 'error in validation', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb(null)
|
||||
iapMock.validate = (iapApple, iapBodyReciept, cb)-> return cb('error in validation', true)
|
||||
|
||||
it 'calls res.json with validation error object', ->
|
||||
expectedResObj = {
|
||||
ok: false
|
||||
data: {
|
||||
code: 6778001
|
||||
message: 'error in validation'
|
||||
}
|
||||
}
|
||||
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(res.json).to.be.calledOnce
|
||||
expect(res.json).to.be.calledWith(expectedResObj)
|
||||
|
||||
it 'does not calls payments.buyGems function', ->
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.not.be.called
|
||||
|
||||
context 'iap is not valid', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb(null)
|
||||
iapMock.validate = (iapApple, iapBodyReciept, cb)-> return cb(null, false)
|
||||
iapMock.isValidated = (appleRes)-> return appleRes
|
||||
|
||||
it 'does not call res.json', ->
|
||||
inApp.iosVerify(req, res, next)
|
||||
expectedResObj = {
|
||||
ok: false
|
||||
data: {
|
||||
code: 6778001
|
||||
message: 'Invalid receipt'
|
||||
}
|
||||
}
|
||||
expect(res.json).to.be.calledOnce
|
||||
expect(res.json).to.be.calledWith(expectedResObj)
|
||||
|
||||
it 'does not calls payments.buyGems function', ->
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.not.be.called
|
||||
|
||||
context 'iap is valid but has no purchaseDataList', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb(null)
|
||||
iapMock.validate = (iapApple, iapBodyReciept, cb)-> return cb(null, true)
|
||||
iapMock.isValidated = (appleRes)-> return appleRes
|
||||
iapMock.getPurchaseData = (appleRes)->
|
||||
return []
|
||||
iapMock.APPLE = 'apple'
|
||||
|
||||
it 'calls res.json with succesful result object', ->
|
||||
expectedResObj = {
|
||||
ok: false
|
||||
data: {
|
||||
code: 6778001
|
||||
message: 'Incorrect receipt content'
|
||||
}
|
||||
}
|
||||
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(res.json).to.be.calledOnce
|
||||
expect(res.json).to.be.calledWith(expectedResObj)
|
||||
|
||||
it 'does not calls payments.buyGems function', ->
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.not.be.called
|
||||
|
||||
context 'iap is valid, has purchaseDataList, but productId does not match', ->
|
||||
before ->
|
||||
iapMock.setup = (cb)-> return cb(null)
|
||||
iapMock.validate = (iapApple, iapBodyReciept, cb)-> return cb(null, true)
|
||||
iapMock.isValidated = (appleRes)-> return appleRes
|
||||
iapMock.getPurchaseData = (appleRes)->
|
||||
return [{ productId: 'com.another.company' }]
|
||||
iapMock.APPLE = 'apple'
|
||||
|
||||
it 'calls res.json with incorrect reciept obj', ->
|
||||
expectedResObj = {
|
||||
ok: false
|
||||
data: {
|
||||
code: 6778001
|
||||
message: 'Incorrect receipt content'
|
||||
}
|
||||
}
|
||||
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(res.json).to.be.calledOnce
|
||||
expect(res.json).to.be.calledWith(expectedResObj)
|
||||
|
||||
it 'does not calls payments.buyGems function', ->
|
||||
inApp.iosVerify(req, res, next)
|
||||
|
||||
expect(paymentSpy).to.not.be.called
|
||||
@@ -0,0 +1,114 @@
|
||||
'use strict'
|
||||
|
||||
require("../../website/src/server")
|
||||
|
||||
describe "Score", ->
|
||||
before (done) ->
|
||||
registerNewUser done, true
|
||||
|
||||
context "Todos that did not previously exist", ->
|
||||
it "creates a completed a todo when using up url", (done) ->
|
||||
request.post(baseURL + "/user/tasks/withUp/up").send(
|
||||
type: "todo"
|
||||
text: "withUp"
|
||||
).end (res) ->
|
||||
expectCode res, 200
|
||||
request.get(baseURL + "/user/tasks/withUp").end (res) ->
|
||||
upTodo = res.body
|
||||
expect(upTodo.completed).to.equal true
|
||||
done()
|
||||
|
||||
it "creates an uncompleted todo when using down url", (done) ->
|
||||
request.post(baseURL + "/user/tasks/withDown/down").send(
|
||||
type: "todo"
|
||||
text: "withDown"
|
||||
).end (res) ->
|
||||
expectCode res, 200
|
||||
request.get(baseURL + "/user/tasks/withDown").end (res) ->
|
||||
downTodo = res.body
|
||||
expect(downTodo.completed).to.equal false
|
||||
done()
|
||||
|
||||
it "creates a completed a todo overriding the complete parameter when using up url", (done) ->
|
||||
request.post(baseURL + "/user/tasks/withUpWithComplete/up").send(
|
||||
type: "todo"
|
||||
text: "withUpWithComplete"
|
||||
completed: false
|
||||
).end (res) ->
|
||||
expectCode res, 200
|
||||
request.get(baseURL + "/user/tasks/withUpWithComplete").end (res) ->
|
||||
upTodo = res.body
|
||||
expect(upTodo.completed).to.equal true
|
||||
done()
|
||||
|
||||
it "Creates an uncompleted todo overriding the completed parameter when using down url", (done) ->
|
||||
request.post(baseURL + "/user/tasks/withDownWithUncomplete/down").send(
|
||||
type: "todo"
|
||||
text: "withDownWithUncomplete"
|
||||
completed: true
|
||||
).end (res) ->
|
||||
expectCode res, 200
|
||||
request.get(baseURL + "/user/tasks/withDownWithUncomplete").end (res) ->
|
||||
downTodo = res.body
|
||||
expect(downTodo.completed).to.equal false
|
||||
done()
|
||||
|
||||
context "Todo that already exists", ->
|
||||
it "It completes a todo when using up url", (done) ->
|
||||
request.post(baseURL + "/user/tasks").send(
|
||||
type: "todo"
|
||||
text: "Sample Todo"
|
||||
).end (res) ->
|
||||
expectCode res, 200
|
||||
unCompletedTodo = res.body
|
||||
expect(unCompletedTodo.completed).to.equal false
|
||||
request.post(baseURL + "/user/tasks/"+unCompletedTodo._id+"/up").end (res) ->
|
||||
expectCode res, 200
|
||||
request.get(baseURL + "/user/tasks/"+unCompletedTodo._id).end (res) ->
|
||||
unCompletedTodo = res.body
|
||||
expect(unCompletedTodo.completed).to.equal true
|
||||
done()
|
||||
|
||||
it "It uncompletes a todo when using down url", (done) ->
|
||||
request.post(baseURL + "/user/tasks").send(
|
||||
type: "todo"
|
||||
text: "Sample Todo"
|
||||
completed: true
|
||||
).end (res) ->
|
||||
expectCode res, 200
|
||||
completedTodo = res.body
|
||||
expect(completedTodo.completed).to.equal true
|
||||
request.post(baseURL + "/user/tasks/"+completedTodo._id+"/down").end (res) ->
|
||||
expectCode res, 200
|
||||
request.get(baseURL + "/user/tasks/"+completedTodo._id).end (res) ->
|
||||
completedTodo = res.body
|
||||
expect(completedTodo.completed).to.equal false
|
||||
done()
|
||||
|
||||
it "Creates and scores up a habit when using up url", (done) ->
|
||||
upHabit = undefined
|
||||
request.post(baseURL + "/user/tasks/habitWithUp/up").send(
|
||||
type: "habit"
|
||||
text: "testTitle"
|
||||
completed: true
|
||||
).end (res) ->
|
||||
expectCode res, 200
|
||||
request.get(baseURL + "/user/tasks/habitWithUp").end (res) ->
|
||||
upHabit = res.body
|
||||
expect(upHabit.value).to.be.at.least(1)
|
||||
expect(upHabit.type).to.equal("habit")
|
||||
done()
|
||||
|
||||
it "Creates and scores down a habit when using down url", (done) ->
|
||||
downHabit = undefined
|
||||
request.post(baseURL + "/user/tasks/habitWithDown/down").send(
|
||||
type: "habit"
|
||||
text: "testTitle"
|
||||
completed: true
|
||||
).end (res) ->
|
||||
expectCode res, 200
|
||||
request.get(baseURL + "/user/tasks/habitWithDown").end (res) ->
|
||||
downHabit = res.body
|
||||
expect(downHabit.value).to.have.at.most(-1)
|
||||
expect(downHabit.type).to.equal("habit")
|
||||
done()
|
||||
@@ -160,7 +160,7 @@ describe "Todos", ->
|
||||
).end (res) ->
|
||||
expectCode res, 200
|
||||
body = res.body
|
||||
expect(body).to.be.empty
|
||||
expect(body).to.be.empty
|
||||
done()
|
||||
|
||||
it "Does not delete already deleted todo", (done) ->
|
||||
@@ -183,4 +183,3 @@ describe "Todos", ->
|
||||
body = res.body
|
||||
expect(body.err).to.equal "Task not found."
|
||||
done()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user