mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Fixed a MailChimp test. Fixed payment and subscription handlers to deny anonymous users. Hid the subscribe button from anonymous users.
This commit is contained in:
parent
e3abb9ceb3
commit
0edf4e0ca1
6 changed files with 23 additions and 4 deletions
|
@ -13,7 +13,7 @@ block content
|
||||||
if subscribed
|
if subscribed
|
||||||
button.end-subscription-button.btn.btn-lg.btn-warning(data-i18n="subscribe.unsubscribe") Unsubscribe
|
button.end-subscription-button.btn.btn-lg.btn-warning(data-i18n="subscribe.unsubscribe") Unsubscribe
|
||||||
.payment-status(data-i18n="account.status_subscribed")
|
.payment-status(data-i18n="account.status_subscribed")
|
||||||
else
|
else if !me.isAnonymous()
|
||||||
button.start-subscription-button.btn.btn-lg.btn-success(data-i18n="subscribe.subscribe") Subscribe
|
button.start-subscription-button.btn.btn-lg.btn-success(data-i18n="subscribe.subscribe") Subscribe
|
||||||
if active
|
if active
|
||||||
.payment-status(data-i18n="account.status_unsubscribed_active")
|
.payment-status(data-i18n="account.status_unsubscribed_active")
|
||||||
|
|
|
@ -56,6 +56,9 @@ PaymentHandler = class PaymentHandler extends Handler
|
||||||
payment
|
payment
|
||||||
|
|
||||||
post: (req, res) ->
|
post: (req, res) ->
|
||||||
|
if (not req.user) or req.user.isAnonymous()
|
||||||
|
return @sendForbiddenError(res)
|
||||||
|
|
||||||
appleReceipt = req.body.apple?.rawReceipt
|
appleReceipt = req.body.apple?.rawReceipt
|
||||||
appleTransactionID = req.body.apple?.transactionID
|
appleTransactionID = req.body.apple?.transactionID
|
||||||
appleLocalPrice = req.body.apple?.localPrice
|
appleLocalPrice = req.body.apple?.localPrice
|
||||||
|
|
|
@ -16,6 +16,9 @@ class SubscriptionHandler extends Handler
|
||||||
console.warn "Subscription Error: #{req.user.get('slug')} (#{req.user._id}): '#{msg}'"
|
console.warn "Subscription Error: #{req.user.get('slug')} (#{req.user._id}): '#{msg}'"
|
||||||
|
|
||||||
subscribeUser: (req, user, done) ->
|
subscribeUser: (req, user, done) ->
|
||||||
|
if (not req.user) or req.user.isAnonymous()
|
||||||
|
return done({res: 'You must be signed in to subscribe.', code: 403})
|
||||||
|
|
||||||
stripeToken = req.body.stripe?.token
|
stripeToken = req.body.stripe?.token
|
||||||
extantCustomerID = user.get('stripe')?.customerID
|
extantCustomerID = user.get('stripe')?.customerID
|
||||||
if not (stripeToken or extantCustomerID)
|
if not (stripeToken or extantCustomerID)
|
||||||
|
|
|
@ -31,6 +31,12 @@ describe '/db/payment', ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'posting Apple IAPs', ->
|
describe 'posting Apple IAPs', ->
|
||||||
|
|
||||||
|
it 'denies anonymous users trying to pay', (done) ->
|
||||||
|
request.get getURL('/auth/whoami'), ->
|
||||||
|
request.post {uri: paymentURL, json: firstApplePayment}, (err, res, body) ->
|
||||||
|
expect(res.statusCode).toBe 403
|
||||||
|
done()
|
||||||
|
|
||||||
it 'creates a payment object and credits gems to the user', (done) ->
|
it 'creates a payment object and credits gems to the user', (done) ->
|
||||||
loginJoe ->
|
loginJoe ->
|
||||||
|
|
|
@ -91,6 +91,14 @@ describe '/db/user, editing stripe property', ->
|
||||||
throw err if err
|
throw err if err
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it 'denies anonymous users trying to subscribe', (done) ->
|
||||||
|
request.get getURL('/auth/whoami'), (err, res, body) ->
|
||||||
|
body = JSON.parse(body)
|
||||||
|
body.stripe = { planID: 'basic', token: '12345' }
|
||||||
|
request.put {uri: userURL, json: body}, (err, res, body) ->
|
||||||
|
expect(res.statusCode).toBe 403
|
||||||
|
done()
|
||||||
|
|
||||||
#- shared data between tests
|
#- shared data between tests
|
||||||
joeData = null
|
joeData = null
|
||||||
firstSubscriptionID = null
|
firstSubscriptionID = null
|
||||||
|
@ -202,7 +210,6 @@ describe '/db/user, editing stripe property', ->
|
||||||
joeData.email = 'newEmail@gmail.com'
|
joeData.email = 'newEmail@gmail.com'
|
||||||
request.put {uri: userURL, json: joeData }, (err, res, body) ->
|
request.put {uri: userURL, json: joeData }, (err, res, body) ->
|
||||||
f = -> stripe.customers.retrieve joeData.stripe.customerID, (err, customer) ->
|
f = -> stripe.customers.retrieve joeData.stripe.customerID, (err, customer) ->
|
||||||
console.log 'customer?', customer
|
|
||||||
expect(customer.email).toBe('newEmail@gmail.com')
|
expect(customer.email).toBe('newEmail@gmail.com')
|
||||||
done()
|
done()
|
||||||
setTimeout(f, 500) # bit of a race condition here, response returns before stripe has been updated
|
setTimeout(f, 500) # bit of a race condition here, response returns before stripe has been updated
|
||||||
|
|
|
@ -28,7 +28,7 @@ describe 'Server user object', ->
|
||||||
expect(JSON.stringify(user.get('emailSubscriptions'))).toBe(JSON.stringify(['tester', 'level_creator']))
|
expect(JSON.stringify(user.get('emailSubscriptions'))).toBe(JSON.stringify(['tester', 'level_creator']))
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'User.updateMailChimp', ->
|
describe 'User.updateServiceSettings', ->
|
||||||
makeMC = (callback) ->
|
makeMC = (callback) ->
|
||||||
GLOBAL.mc =
|
GLOBAL.mc =
|
||||||
lists:
|
lists:
|
||||||
|
@ -40,7 +40,7 @@ describe 'User.updateMailChimp', ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
user = new User({emailSubscriptions: ['announcement'], email: 'tester@gmail.com'})
|
user = new User({emailSubscriptions: ['announcement'], email: 'tester@gmail.com'})
|
||||||
User.updateMailChimp(user)
|
User.updateServiceSettings(user)
|
||||||
|
|
||||||
describe 'POST /db/user', ->
|
describe 'POST /db/user', ->
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue