From 8b672dea0d142881933421ffdcf32e118d931884 Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Thu, 31 May 2018 16:01:01 -0500 Subject: [PATCH] Add unit tests --- .../SubscriptionControllerTests.coffee | 68 ++++++++++++++----- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/services/web/test/unit/coffee/Subscription/SubscriptionControllerTests.coffee b/services/web/test/unit/coffee/Subscription/SubscriptionControllerTests.coffee index 04888e2dd7..1592215040 100644 --- a/services/web/test/unit/coffee/Subscription/SubscriptionControllerTests.coffee +++ b/services/web/test/unit/coffee/Subscription/SubscriptionControllerTests.coffee @@ -87,35 +87,69 @@ describe "SubscriptionController", -> @stubbedCurrencyCode = "GBP" describe "plansPage", -> - beforeEach (done) -> + beforeEach -> @req.ip = "1234.3123.3131.333 313.133.445.666 653.5345.5345.534" @GeoIpLookup.getCurrencyCode.callsArgWith(1, null, @stubbedCurrencyCode) - @res.callback = done - @SubscriptionController.plansPage(@req, @res) - @UserGetter.getUser = sinon.stub().callsArgWith(2, null, @user) - it "should set the recommended currency from the geoiplookup", (done)-> - @res.renderedVariables.recomendedCurrency.should.equal(@stubbedCurrencyCode) - @GeoIpLookup.getCurrencyCode.calledWith(@req.ip).should.equal true - done() + describe 'when user is logged in', (done) -> + beforeEach (done) -> + @res.callback = done + @SubscriptionController.plansPage(@req, @res) + it 'should fetch the current user', (done) -> + @UserGetter.getUser.callCount.should.equal 1 + done() - it 'should fetch the current user', (done) -> - @UserGetter.getUser.callCount.should.equal 1 - done() + it 'should decide not to AB test the plans when signed up before 2016-10-27', (done) -> + @res.renderedVariables.shouldABTestPlans.should.equal false + done() - it 'should decide not to AB test the plans', (done) -> - @res.renderedVariables.shouldABTestPlans.should.equal false - done() + describe 'not dependant on logged in state', (done) -> + # these could have been put in 'when user is not logged in' too + it "should set the recommended currency from the geoiplookup", (done)-> + @res.renderedVariables.recomendedCurrency.should.equal(@stubbedCurrencyCode) + @GeoIpLookup.getCurrencyCode.calledWith(@req.ip).should.equal true + done() + it 'should include data for features table', (done) -> + # this is part of AB test. If default wins test, then remove this test + @res.renderedVariables.planFeatures.length.should.not.equal 0 + done() describe 'when user is not logged in', (done) -> + beforeEach (done) -> + @UserGetter = + getUser: sinon.stub().callsArgWith(2, null, null) + @res.callback = done + @SubscriptionController.plansPage(@req, @res) + @AuthenticationController = + getLoggedInUser: sinon.stub().callsArgWith(1, null, null) + getLoggedInUserId: sinon.stub().returns(null) + getSessionUser: sinon.stub().returns(null) + isUserLoggedIn: sinon.stub().returns(false) - beforeEach -> - @AuthenticationController.getLoggedInUserId.returns(null) + @SubscriptionController = SandboxedModule.require modulePath, requires: + '../Authentication/AuthenticationController': @AuthenticationController + './SubscriptionHandler': @SubscriptionHandler + "./PlansLocator": @PlansLocator + './SubscriptionViewModelBuilder': @SubscriptionViewModelBuilder + "./LimitationsManager": @LimitationsManager + "../../infrastructure/GeoIpLookup":@GeoIpLookup + "logger-sharelatex": + log:-> + warn:-> + "settings-sharelatex": @settings + "./SubscriptionDomainHandler":@SubscriptionDomainHandler + "../User/UserGetter": @UserGetter + "./RecurlyWrapper": @RecurlyWrapper = {} + "./FeaturesUpdater": @FeaturesUpdater = {} it 'should not fetch the current user', (done) -> @UserGetter.getUser.callCount.should.equal 0 done() + it 'should decide to AB test', (done) -> + @res.renderedVariables.shouldABTestPlans.should.equal true + done() + describe "paymentPage", -> beforeEach -> @req.headers = {} @@ -460,4 +494,4 @@ describe "SubscriptionController", -> @SubscriptionHandler.updateSubscription.calledWith(@user, "collaborator-annual", "COLLABORATORCODEHERE").should.equal true done() - @SubscriptionController.processUpgradeToAnnualPlan @req, @res + @SubscriptionController.processUpgradeToAnnualPlan @req, @res \ No newline at end of file