redirect to /thank-you on success and fix broken unit test from a few commits ago

This commit is contained in:
Henry Oswald 2014-12-22 16:37:09 +00:00
parent d0c9783718
commit a7eb836c79
5 changed files with 25 additions and 12 deletions

View file

@ -138,7 +138,8 @@ module.exports = SubscriptionController =
SubscriptionHandler.createSubscription user, subscriptionDetails, recurly_token_id, (err)->
if err?
logger.err err:err, user_id:user._id, "something went wrong creating subscription"
res.redirect "/user/subscription/thank-you"
return res.send 500
res.send 201
successful_subscription: (req, res)->
SecurityManager.getCurrentUser req, (error, user) =>

View file

@ -14,6 +14,7 @@ module.exports =
self = @
clientTokenId = ""
RecurlyWrapper.createSubscription user, subscriptionDetails, recurly_token_id, (error, recurlySubscription)->
console.log recurlySubscription
return callback(error) if error?
SubscriptionUpdater.syncSubscription recurlySubscription, user._id, (error) ->
return callback(error) if error?

View file

@ -82,7 +82,9 @@ define [
plan_code:"student"
$http.post("/user/subscription/create", postData)
.success ->
console.log "success"
window.location.href = "/user/subscription/thank-you"
.error ()->
console.log "something went wong"
$scope.submit = ->
if $scope.paymentMethod == 'paypal'

View file

@ -20,13 +20,13 @@ mockSubscriptions =
describe "SubscriptionController sanboxed", ->
beforeEach ->
@user = {}
@user = {email:"tom@yahoo.com"}
@activeRecurlySubscription = mockSubscriptions["subscription-123-active"]
@SecurityManager =
getCurrentUser: sinon.stub().callsArgWith(1, null, @user)
@SubscriptionHandler =
createSubscription: sinon.stub().callsArgWith(2)
createSubscription: sinon.stub().callsArgWith(3)
updateSubscription: sinon.stub().callsArgWith(3)
reactivateSubscription: sinon.stub().callsArgWith(1)
cancelSubscription: sinon.stub().callsArgWith(1)
@ -258,18 +258,22 @@ describe "SubscriptionController sanboxed", ->
describe "createSubscription", ->
beforeEach (done)->
@res =
redirect:->
send:->
done()
sinon.spy @res, "redirect"
@req.body.recurly_token = "1234"
sinon.spy @res, "send"
@subscriptionDetails =
card:"1234"
cvv:"123"
@req.body.recurly_token_id = "1234"
@req.body.subscriptionDetails = @subscriptionDetails
@SubscriptionController.createSubscription @req, @res
it "should send the user and subscriptionId to the handler", (done)->
@SubscriptionHandler.createSubscription.calledWith(@user, @req.body.recurly_token).should.equal true
@SubscriptionHandler.createSubscription.calledWith(@user, @subscriptionDetails, @req.body.recurly_token_id).should.equal true
done()
it "should redurect to the subscription page", (done)->
@res.redirect.calledWith("/user/subscription/thank-you").should.equal true
@res.send.calledWith(201).should.equal true
done()

View file

@ -42,6 +42,7 @@ describe "Subscription Handler sanboxed", ->
cancelSubscription: sinon.stub().callsArgWith(1)
reactivateSubscription: sinon.stub().callsArgWith(1)
redeemCoupon:sinon.stub().callsArgWith(2)
createSubscription: sinon.stub().callsArgWith(3, null, @activeRecurlySubscription)
@DropboxHandler =
unlinkAccount:sinon.stub().callsArgWith(1)
@ -71,10 +72,14 @@ describe "Subscription Handler sanboxed", ->
describe "createSubscription", ->
beforeEach (done) ->
@SubscriptionHandler.createSubscription(@user, @activeRecurlySubscription.uuid, done)
@subscriptionDetails =
cvv:"123"
number:"12345"
@recurly_token_id = "45555666"
@SubscriptionHandler.createSubscription(@user, @subscriptionDetails, @recurly_token_id, done)
it "should get the subscription", (done)->
@RecurlyWrapper.getSubscription.calledWith(@activeRecurlySubscription.uuid, {recurlyJsResult: true}).should.equal true
it "should create the subscription with the wrapper", (done)->
@RecurlyWrapper.createSubscription.calledWith(@user, @subscriptionDetails, @recurly_token_id).should.equal true
done()
it "should sync the subscription to the user", (done)->