From 3ba3a91043f3c5e053478bc7a81a2a6ff16c92b0 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 10 Oct 2014 15:11:22 +0100 Subject: [PATCH] if its a custom account redirect to /user/subscription/custom_account --- .../Features/Subscription/LimitationsManager.coffee | 4 ++-- .../Subscription/SubscriptionController.coffee | 7 +++++-- .../Subscription/SubscriptionControllerTests.coffee | 11 +++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/services/web/app/coffee/Features/Subscription/LimitationsManager.coffee b/services/web/app/coffee/Features/Subscription/LimitationsManager.coffee index a9bca83a9b..10a4de7edf 100644 --- a/services/web/app/coffee/Features/Subscription/LimitationsManager.coffee +++ b/services/web/app/coffee/Features/Subscription/LimitationsManager.coffee @@ -30,12 +30,12 @@ module.exports = callback null, true userHasSubscriptionOrIsGroupMember: (user, callback = (err, hasSubscriptionOrIsMember)->) -> - @userHasSubscription user, (err, hasSubscription)=> + @userHasSubscription user, (err, hasSubscription, subscription)=> return callback(err) if err? @userIsMemberOfGroupSubscription user, (err, isMember)=> return callback(err) if err? logger.log user_id:user._id, isMember:isMember, hasSubscription:hasSubscription, "checking if user has subscription or is group member" - callback err, isMember or hasSubscription + callback err, isMember or hasSubscription, subscription userHasSubscription: (user, callback = (err, hasSubscription, subscription)->) -> logger.log user_id:user._id, "checking if user has subscription" diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee index 014d939f4f..1185bfe6bb 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee @@ -69,8 +69,11 @@ module.exports = SubscriptionController = userSubscriptionPage: (req, res, next) -> SecurityManager.getCurrentUser req, (error, user) => return next(error) if error? - LimitationsManager.userHasSubscriptionOrIsGroupMember user, (err, hasSubOrIsGroupMember)-> - if !hasSubOrIsGroupMember + LimitationsManager.userHasSubscriptionOrIsGroupMember user, (err, hasSubOrIsGroupMember, subscription)-> + if subscription?.customAccount + logger.log user: user, "redirecting to plans" + res.redirect "/user/subscription/custom_account" + else if !hasSubOrIsGroupMember logger.log user: user, "redirecting to plans" res.redirect "/user/subscription/plans" else diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee index 208f35004d..898378608d 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee @@ -184,6 +184,17 @@ describe "SubscriptionController sanboxed", -> it "should set the correct subscription details", -> @res.renderedVariables.subscription.should.deep.equal @activeRecurlySubscription + + describe "when its a custom subscription which is non recurly", -> + beforeEach ()-> + @LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, true, {customAccount:true}) + @SubscriptionController.userSubscriptionPage @req, @res + + it "should redirect to /user/subscription/custom_account", -> + @res.redirectedTo.should.equal("/user/subscription/custom_account") + + + describe "createSubscription", -> beforeEach (done)-> @res =