diff --git a/client/config/routes.js b/client/config/routes.js index 5eb9752fc..6407b0383 100755 --- a/client/config/routes.js +++ b/client/config/routes.js @@ -123,6 +123,38 @@ module.exports = [ orgs: function (fetchWhitelistedOrgs) { return fetchWhitelistedOrgs(); }, + activeOrg: function ( + $stateParams, + whitelists, + moment + ) { + var lowerAccountName = $stateParams.userName.toLowerCase(); + var activeOrg = whitelists.find(function (whitelist) { + return whitelist.attrs.lowerName === lowerAccountName; + }); + // All of this should be moved to inside @runnable/api-client + activeOrg.attrs.trialEnd = moment().add(2, 'days').toISOString(); + activeOrg.attrs.activePeriodEnd = moment().subtract(1, 'days').toISOString(); + activeOrg.attrs.gracePeriodEnd = moment().add(5, 'days').toISOString(); + activeOrg.attrs.stripeCustomerId = 1234; + activeOrg.attrs.hasPaymentMethod = false; + activeOrg.isInTrial = function () { + return moment(activeOrg.attrs.trialEnd) > moment().utc(); + }; + activeOrg.isInGrace = function () { + return !activeOrg.isInTrial() && moment(activeOrg.attrs.gracePeriodEnd) > moment().utc(); + }; + activeOrg.isInActivePeriod = function () { + return moment(activeOrg.attrs.activePeriodEnd) > moment().utc(); + }; + activeOrg.isGraceExpired = function () { + return !activeOrg.isInTrial() && moment.utc(activeOrg.attrs.gracePeriodEnd) < moment().utc(); + }; + activeOrg.trialDaysRemaining = function () { + return moment(activeOrg.attrs.trialEnd).diff(moment.utc(), 'days'); + }; + return activeOrg; + }, activeAccount: function ( $q, $stateParams, @@ -131,7 +163,8 @@ module.exports = [ whitelists, $timeout, user, - eventTracking + eventTracking, + activeOrg ) { var lowerAccountName = $stateParams.userName.toLowerCase(); var userName = user.oauthName().toLowerCase(); @@ -151,10 +184,7 @@ module.exports = [ return $q.reject(new Error('User Unauthorized for Organization')); }); } - var foundWhitelist = whitelists.find(function (whitelist) { - return whitelist.attrs.lowerName === lowerAccountName; - }); - if (!foundWhitelist.attrs.allowed) { + if (!activeOrg.attrs.allowed) { // There is a bug in ui-router and a timeout is the workaround return $timeout(function () { $state.go('paused'); @@ -163,6 +193,14 @@ module.exports = [ } eventTracking.boot(user, {orgName: $stateParams.userName}); return matchedOrg; + }, + populateCurrentOrgService: function ( + activeOrg, + activeAccount, + currentOrg + ) { + currentOrg.poppa = activeOrg; + currentOrg.github = activeAccount; } } }, { diff --git a/client/controllers/controllerApp.js b/client/controllers/controllerApp.js index 6fbab1b67..db58e0f89 100755 --- a/client/controllers/controllerApp.js +++ b/client/controllers/controllerApp.js @@ -22,6 +22,7 @@ function ControllerApp( keypather, ModalService, pageName, + currentOrg, user, orgs, @@ -119,9 +120,9 @@ function ControllerApp( } }; - if ($rootScope.featureFlags.billing && (activeAccount.isInGrace() || activeAccount.isGraceExpired())) { + if ($rootScope.featureFlags.billing && (currentOrg.poppa.isInGrace() || currentOrg.poppa.isGraceExpired())) { // Determine if it's a trial end or just a normal payment due - if (activeAccount.attrs.hasPaymentMethod) { + if (currentOrg.poppa.attrs.hasPaymentMethod) { ModalService.showModal({ controller: 'ExpiredAccountController', controllerAs: 'EAC', @@ -146,13 +147,13 @@ function ControllerApp( CA.showTrialEndingNotification = function () { return $rootScope.featureFlags.billing && - activeAccount.isInTrial() && - activeAccount.trialDaysRemaining() <= 3 && - !activeAccount.attrs.hasPaymentMethod && !keypather.get($localStorage, 'hasDismissedTrialNotification.' + activeAccount.attrs.id); + currentOrg.poppa.isInTrial() && + currentOrg.poppa.trialDaysRemaining() <= 3 && + !currentOrg.poppa.attrs.hasPaymentMethod && !keypather.get($localStorage, 'hasDismissedTrialNotification.' + currentOrg.github.attrs.id); }; CA.closeTrialEndingNotification = function () { - keypather.set($localStorage, 'hasDismissedTrialNotification.' + activeAccount.attrs.id, true); + keypather.set($localStorage, 'hasDismissedTrialNotification.' + currentOrg.github.attrs.id, true); }; } diff --git a/client/directives/accountsSelect/directiveAccountsSelect.js b/client/directives/accountsSelect/directiveAccountsSelect.js index ca3fa19a6..58de1a5fa 100644 --- a/client/directives/accountsSelect/directiveAccountsSelect.js +++ b/client/directives/accountsSelect/directiveAccountsSelect.js @@ -16,7 +16,8 @@ function accountsSelect ( errs, keypather, ModalService, - promisify + promisify, + currentOrg ) { return { restrict: 'A', @@ -87,6 +88,7 @@ function accountsSelect ( $scope.$watch('data.activeAccount', function (account) { if (!account) { return; } keypather.set($scope, 'popoverAccountMenu.data.activeAccount', account); + keypather.set($scope, 'popoverAccountMenu.data.currentOrg', currentOrg); keypather.set($scope, 'popoverAccountMenu.data.orgs', $scope.data.orgs); keypather.set($scope, 'popoverAccountMenu.data.user', $scope.data.user); @@ -102,8 +104,8 @@ function accountsSelect ( if (!$rootScope.featureFlags.billing) { return ''; } - if ($scope.data.activeAccount.isInTrial() && !$scope.data.activeAccount.attrs.hasPaymentMethod) { - return $scope.data.activeAccount.trialDaysRemaining(); + if (currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod) { + return currentOrg.poppa.trialDaysRemaining(); } return ''; }; @@ -113,8 +115,8 @@ function accountsSelect ( return {}; } return { - badge: $scope.data.activeAccount.isInTrial() && !$scope.data.activeAccount.attrs.hasPaymentMethod, - 'badge-orange': $scope.data.activeAccount.isInTrial() && !$scope.data.activeAccount.attrs.hasPaymentMethod + badge: currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod, + 'badge-orange': currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod }; }; } diff --git a/client/directives/accountsSelect/popoverAccountMenu/viewPopoverAccountMenu.jade b/client/directives/accountsSelect/popoverAccountMenu/viewPopoverAccountMenu.jade index 9467bd12e..5a2a9fd0b 100644 --- a/client/directives/accountsSelect/popoverAccountMenu/viewPopoverAccountMenu.jade +++ b/client/directives/accountsSelect/popoverAccountMenu/viewPopoverAccountMenu.jade @@ -21,7 +21,7 @@ ul.list.popover-list( ng-if = "data.showIntegrations" ) - li.list-item.popover-list-item.small.disabled {{data.activeAccount.oauthName()}} Settings + li.list-item.popover-list-item.small.disabled {{data.currentOrg.github.oauthName()}} Settings //- ***************** //- $root.featureFlags.billing li.list-item.popover-list-item( @@ -34,10 +34,10 @@ ) | Billing btn.btn-xxs.btn-badge.anchor-right.orange( - ng-if = "data.activeAccount.isInTrial() && !data.activeAccount.attrs.hasPaymentMethod" - title = "{{data.activeAccount.trialDaysRemaining() + ' days left in your trial'}}" + ng-if = "data.currentOrg.poppa.isInTrial() && !data.currentOrg.poppa.attrs.hasPaymentMethod" + title = "{{data.currentOrg.poppa.trialDaysRemaining() + ' days left in your trial'}}" ) - | {{data.activeAccount.trialDaysRemaining() + ' days left'}} + | {{data.currentOrg.poppa.trialDaysRemaining() + ' days left'}} li.list-item.popover-list-item( ng-click = "actions.openSettingsModal('teamManagement')" ) diff --git a/client/directives/environment/environmentBody/serverCards/serverCardDirective.js b/client/directives/environment/environmentBody/serverCards/serverCardDirective.js index 1132b15f6..e23dba236 100644 --- a/client/directives/environment/environmentBody/serverCards/serverCardDirective.js +++ b/client/directives/environment/environmentBody/serverCards/serverCardDirective.js @@ -14,7 +14,8 @@ require('app') keypather, ModalService, parseDockerfileForCardInfoFromInstance, - promisify + promisify, + currentOrg ) { return { restrict: 'A', @@ -80,7 +81,7 @@ require('app') }; $scope.helpCards = helpCards; $scope.server = {}; - $scope.activeAccount = $rootScope.dataApp.data.activeAccount; + $scope.activeAccount = currentOrg.github; // I'm unsure if this is used. function scrollIntoView() { $document.scrollToElement(ele, 100, 200); diff --git a/client/directives/modals/modalNewContainer/newContainerModalController.js b/client/directives/modals/modalNewContainer/newContainerModalController.js index f43b6c709..221cd81e5 100644 --- a/client/directives/modals/modalNewContainer/newContainerModalController.js +++ b/client/directives/modals/modalNewContainer/newContainerModalController.js @@ -5,7 +5,6 @@ require('app') function NewContainerModalController( $q, - $rootScope, $timeout, createNewBuildAndFetchBranch, createNonRepoInstance, @@ -19,7 +18,8 @@ function NewContainerModalController( keypather, loading, ModalService, - close + close, + currentOrg ) { var NCMC = this; var helpCard = helpCards.getActiveCard(); @@ -43,7 +43,7 @@ function NewContainerModalController( loading(NCMC.name + 'Repos', true); $q.all({ instances: fetchInstancesByPod(), - repoList: fetchOwnerRepos($rootScope.dataApp.data.activeAccount.oauthName()) + repoList: fetchOwnerRepos(currentOrg.github.oauthName()) }) .then(function (data) { NCMC.instances = data.instances; @@ -169,7 +169,7 @@ function NewContainerModalController( .then(function (dockerfiles) { if (dockerfiles.length === 0) { NCMC.state.configurationMethod = 'new'; - } + } loading(NCMC.name + 'SingleRepo', false); repo.loading = false; repo.dockerfiles = dockerfiles; @@ -180,7 +180,7 @@ function NewContainerModalController( NCMC.createBuildAndGoToNewRepoModal = function (instanceName, repo, dockerfile, configurationMethod) { loading(NCMC.name + 'SingleRepo', true); - return createNewBuildAndFetchBranch($rootScope.dataApp.data.activeAccount, repo, keypather.get(dockerfile, 'path')) + return createNewBuildAndFetchBranch(currentOrg.github, repo, keypather.get(dockerfile, 'path')) .then(function (repoBuildAndBranch) { repoBuildAndBranch.instanceName = instanceName; if (configurationMethod === 'dockerfile' && dockerfile) { diff --git a/client/directives/modals/settingsModal/forms/billingForm/billingForm.jade b/client/directives/modals/settingsModal/forms/billingForm/billingForm.jade index 54366ea58..de561aa4e 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/billingForm.jade +++ b/client/directives/modals/settingsModal/forms/billingForm/billingForm.jade @@ -15,35 +15,35 @@ ng-class = "{'in': isActivePanel()}" trial-form from-modal = 'true' - ng-if = "activeAccount.isInTrial() && !activeAccount.attrs.hasPaymentMethod" + ng-if = "currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod" ) .grid-block.vertical.form-plan.fade( ng-class = "{'in': isActivePanel()}" ng-init = "state.hasDuration = false" plan-status-form ng-show = "!$root.isLoading.billingForm" - ng-if = "activeAccount.isInTrial() && !activeAccount.attrs.hasPaymentMethod" + ng-if = "currentOrg.poppa.isInTrial() && !currentOrg.poppa.attrs.hasPaymentMethod" ) .grid-block.vertical.form-plan.label.padding-sm.fade( ng-class = "{'in': isActivePanel()}" ng-include = "'showPlanForm'" - ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)" + ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)" ) .grid-block.vertical.label.padding-sm.fade( ng-class = "{'in': isActivePanel()}" show-payment-form - ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)" + ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)" ) .grid-block.vertical.label.padding-sm.fade( ng-class = "{'in': isActivePanel()}" billing-history-form - ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)" + ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)" ) .grid-block.vertical.label.padding-sm.fade( ng-class = "{'in': isActivePanel()}" ng-include = "'disableOrgForm'" - ng-if = "!activeAccount.isInTrial() || (activeAccount.isInTrial() && activeAccount.attrs.hasPaymentMethod)" + ng-if = "!currentOrg.poppa.isInTrial() || (currentOrg.poppa.isInTrial() && currentOrg.poppa.attrs.hasPaymentMethod)" ) animated-panel( name = "planStatusForm" @@ -62,12 +62,12 @@ change-payment-form save = "actions.save" cancel = "actions.cancel" - updating = "activeAccount.attrs.hasPaymentMethod" + updating = "currentOrg.poppa.attrs.hasPaymentMethod" ) animated-panel( name = "confirmationForm" ) .grid-block.vertical.form-plan.fade( ng-class = "{'in': isActivePanel()}" - ng-include = "'confirmationForm'" + confirmation-form ) diff --git a/client/directives/modals/settingsModal/forms/billingForm/billingFormDirective.js b/client/directives/modals/settingsModal/forms/billingForm/billingFormDirective.js index 5b6f6ee95..3b67bcc8f 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/billingFormDirective.js +++ b/client/directives/modals/settingsModal/forms/billingForm/billingFormDirective.js @@ -3,7 +3,7 @@ require('app').directive('billingForm', billingForm); function billingForm( - $rootScope + currentOrg ) { return { restrict: 'A', @@ -16,7 +16,7 @@ function billingForm( $scope.SEMC.showFooter = panelName === 'billingForm'; }); $scope.$broadcast('go-to-panel', $scope.SEMC.subTab || 'billingForm', 'immediate'); - $scope.activeAccount = $rootScope.dataApp.data.activeAccount; + $scope.currentOrg = currentOrg; $scope.actions = { save: function () { $scope.$broadcast('go-to-panel', 'confirmationForm'); diff --git a/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentForm.jade b/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentForm.jade index 48d514c9c..ef8272ece 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentForm.jade +++ b/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentForm.jade @@ -106,14 +106,14 @@ form.padding-md( ) .grid-block.well.padding-xxs.small.justify-center.text-center( - ng-if = "!CPFC.paymentMethod || !CPFC.activeAccount.isInTrial()" + ng-if = "!CPFC.paymentMethod || !CPFC.currentOrg.poppa.isInTrial()" payment-summary show-next = 'false' ) //- 3 users is the minimum amount p.grid-content.p.text-gray.text-center.padding-sm( - ng-if = "!CPFC.activeAccount.isInActivePeriod()" + ng-if = "!CPFC.currentOrg.poppa.isInActivePeriod()" ) We prorate your account for users added in the middle of a billing period. a.link( href = "#" @@ -121,7 +121,7 @@ form.padding-md( ) Details p.grid-content.p.text-gray.text-center.padding-sm( - ng-if = "CPFC.activeAccount.isInActivePeriod()" + ng-if = "CPFC.currentOrg.poppa.isInActivePeriod()" ) Your payment changes will be applied to your next billing date on {{getBillingDate()}}. footer.modal-footer.clearfix @@ -135,7 +135,7 @@ footer.modal-footer.clearfix button.btn.btn-md.green.float-right( ng-click = "CPFC.actions.save()" ng-disabled="paymentForm.$invalid || $root.isLoading.savePayment" - ng-if = "CPFC.updating && !(CPFC.activeAccount.isInGrace() || CPFC.activeAccount.isGraceExpired())" + ng-if = "CPFC.updating && !(CPFC.currentOrg.poppa.isInGrace() || CPFC.currentOrg.poppa.isGraceExpired())" ) .spinner-wrapper.spinner-sm.spinner-white.in( ng-include = "'spinner'" @@ -146,7 +146,7 @@ footer.modal-footer.clearfix button.btn.btn-md.green.float-right( ng-click = "CPFC.actions.save()" ng-disabled="paymentForm.$invalid || $root.isLoading.savePayment" - ng-if = "!CPFC.updating && !(CPFC.activeAccount.isInGrace() || CPFC.activeAccount.isGraceExpired())" + ng-if = "!CPFC.updating && !(CPFC.currentOrg.poppa.isInGrace() || CPFC.currentOrg.poppa.isGraceExpired())" type = "button" ) .spinner-wrapper.spinner-sm.spinner-white.in( @@ -159,7 +159,7 @@ footer.modal-footer.clearfix button.btn.btn-md.green.btn-block( ng-click = "CPFC.actions.save()" ng-disabled="paymentForm.$invalid || $root.isLoading.savePayment" - ng-if = "CPFC.activeAccount.isInGrace() || CPFC.activeAccount.isGraceExpired()" + ng-if = "!CPFC.updating && (CPFC.currentOrg.poppa.isInGrace() || CPFC.currentOrg.poppa.isGraceExpired())" type = "button" ) .spinner-wrapper.spinner-sm.spinner-white.in( diff --git a/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js b/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js index 12ddb8a8c..65a9dd64a 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js +++ b/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js @@ -6,12 +6,12 @@ require('app') function ChangePaymentFormController( stripe, loading, - $rootScope, - fetchPaymentMethod + fetchPaymentMethod, + currentOrg ) { var CPFC = this; - CPFC.activeAccount = $rootScope.dataApp.data.activeAccount; - if (CPFC.activeAccount.isInTrial()) { + CPFC.currentOrg = currentOrg; + if (currentOrg.poppa.isInTrial()) { loading('billingForm', true); fetchPaymentMethod() .then(function (paymentMethod) { diff --git a/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormDirective.js b/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormDirective.js index 67931181f..cc30c1e29 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormDirective.js +++ b/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormDirective.js @@ -35,7 +35,7 @@ function changePaymentForm( !$scope.paymentForm.$error.ccExp; }; $scope.getBillingDate = function () { - return moment($scope.CPFC.activeAccount.attrs.activePeriodEnd).format('MMM Do, YYYY'); + return moment($scope.CPFC.currentOrg.poppa.attrs.activePeriodEnd).format('MMM Do, YYYY'); }; } }; diff --git a/client/directives/modals/settingsModal/forms/billingForm/components/paymentSummary/paymentSummaryDirective.js b/client/directives/modals/settingsModal/forms/billingForm/components/paymentSummary/paymentSummaryDirective.js index e61ab7cf9..7b994effc 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/components/paymentSummary/paymentSummaryDirective.js +++ b/client/directives/modals/settingsModal/forms/billingForm/components/paymentSummary/paymentSummaryDirective.js @@ -3,12 +3,12 @@ require('app').directive('paymentSummary', paymentSummary); function paymentSummary( - fetchPlan, + $q, + currentOrg, fetchPaymentMethod, + fetchPlan, loading, - moment, - $q, - $rootScope + moment ) { return { restrict: 'A', @@ -16,8 +16,8 @@ function paymentSummary( scope: { showNext: '=' }, - link: function ($scope, element) { - $scope.activeAccount = $rootScope.dataApp.data.activeAccount; + link: function ($scope) { + $scope.currentOrg = currentOrg; $scope.planMapping = { 'starter': 'Starter', 'standard': 'Standard', @@ -44,7 +44,7 @@ function paymentSummary( }; $scope.getTrialEndDate = function () { - return moment($scope.activeAccount.attrs.trialEnd).format('MMM Do, YYYY'); + return moment(currentOrg.poppa.attrs.trialEnd).format('MMM Do, YYYY'); }; } }; diff --git a/client/directives/modals/settingsModal/forms/billingForm/components/paymentSummary/paymentSummaryView.jade b/client/directives/modals/settingsModal/forms/billingForm/components/paymentSummary/paymentSummaryView.jade index 79549b6ea..c4afcb8b0 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/components/paymentSummary/paymentSummaryView.jade +++ b/client/directives/modals/settingsModal/forms/billingForm/components/paymentSummary/paymentSummaryView.jade @@ -2,21 +2,21 @@ span( ng-if = "!paymentMethod" ) At your current usage, you’ll be charged for the {{planMapping[plan.id]}} plan at ${{calculatePlanPrice() | centsToDollars}} for {{plan.userCount}} users. strong.strong( - ng-if = "activeAccount.isInTrial()" + ng-if = "currentOrg.poppa.isInTrial()" ) You will not be charged until your trial ends. span( - ng-if = "activeAccount.isGraceExpired() || activeAccount.isInGrace() && paymentMethod" + ng-if = "currentOrg.poppa.isGraceExpired() || currentOrg.poppa.isInGrace() && paymentMethod" ) You’ll be charged strong ${{calculatePlanPrice() | centsToDollars}} | for {{plan.userCount}} users. span( - ng-if = "activeAccount.isInActivePeriod() && paymentMethod" + ng-if = "currentOrg.poppa.isInActivePeriod() && paymentMethod" ) You’ve been charged strong ${{calculatePlanPrice() | centsToDollars}} | for {{plan.userCount}} users. span( ng-if = "showNext" -) Your {{activeAccount.isInTrial() ? 'first' : 'next'}} billing date is {{getTrialEndDate()}}. +) Your {{currentOrg.poppa.isInTrial() ? 'first' : 'next'}} billing date is {{getTrialEndDate()}}. diff --git a/client/directives/modals/settingsModal/forms/billingForm/confirmationForm.jade b/client/directives/modals/settingsModal/forms/billingForm/confirmationForm/confirmationForm.jade similarity index 64% rename from client/directives/modals/settingsModal/forms/billingForm/confirmationForm.jade rename to client/directives/modals/settingsModal/forms/billingForm/confirmationForm/confirmationForm.jade index 6235b63f7..2a209c0b4 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/confirmationForm.jade +++ b/client/directives/modals/settingsModal/forms/billingForm/confirmationForm/confirmationForm.jade @@ -6,7 +6,7 @@ width = "250" ) - h3.grid-content.h3.text-center {{$root.dataApp.data.activeAccount.isInTrial() ? 'Your payment method has been added' : 'Your payment has been submitted'}}! + h3.grid-content.h3.text-center {{currentOrg.poppa.isInTrial() ? 'Your payment method has been added' : 'Your payment has been submitted'}}! p.grid-content.p.text-center.text-gray( payment-summary @@ -15,10 +15,10 @@ footer.modal-footer.clearfix button.btn.btn-md.btn-block.green( - ng-if = "$root.dataApp.data.activeAccount.isInActivePeriod()" + ng-if = "currentOrg.poppa.isInActivePeriod()" ) Go to your sandbox! button.btn.btn-md.btn-block.white( ng-click = "goToPanel('billingForm', 'back');" - ng-if = "$root.dataApp.data.activeAccount.isInTrial()" + ng-if = "currentOrg.poppa.isInTrial()" type = "button" ) Billing Overview diff --git a/client/directives/modals/settingsModal/forms/billingForm/confirmationForm/confirmationFormDirective.js b/client/directives/modals/settingsModal/forms/billingForm/confirmationForm/confirmationFormDirective.js new file mode 100644 index 000000000..1f4302baa --- /dev/null +++ b/client/directives/modals/settingsModal/forms/billingForm/confirmationForm/confirmationFormDirective.js @@ -0,0 +1,15 @@ +'use strict'; + +require('app').directive('confirmationForm', confirmationForm); + +function confirmationForm( + currentOrg +) { + return { + restrict: 'A', + templateUrl: 'confirmationForm', + link: function ($scope) { + $scope.currentOrg = currentOrg; + } + }; +} diff --git a/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusForm.jade b/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusForm.jade index 272719104..38718b9cf 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusForm.jade +++ b/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusForm.jade @@ -96,7 +96,7 @@ label.grid-block.align-center.padding-xs.well.well-plan.well-summary.disabled( ng-if = "PSFC.discounted" ng-include = "'discountView'" - ng-init = "state.hasDuration = (PSFC.activeAccount.isInActivePeriod()) ? 'true' : ''" + ng-init = "state.hasDuration = (PSFC.currentOrg.poppa.isInActivePeriod()) ? 'true' : ''" ) p.grid-content.p.text-gray.text-center.padding-sm( @@ -107,12 +107,12 @@ .grid-block.justify-center button.grid-block.shrink.btn.btn-md.green( ng-click = "goToPanel('changePaymentForm');" - ng-if = "PSFC.activeAccount.isInTrial()" + ng-if = "PSFC.currentOrg.poppa.isInTrial()" type = "button" ) Add Payment Method footer.modal-footer.clearfix( - ng-if = "!PSFC.activeAccount.isInTrial()" + ng-if = "!PSFC.currentOrg.poppa.isInTrial()" ) button.btn.btn-md.gray.btn-cancel.float-left( ng-click = "goToPanel('billingForm', 'back');" diff --git a/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusFormController.js b/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusFormController.js index 563708514..c6751664c 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusFormController.js +++ b/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusFormController.js @@ -5,8 +5,8 @@ require('app') function PlanStatusFormController( $q, - $rootScope, billingPlans, + currentOrg, fetchInstancesByPod, fetchPaymentMethod, fetchPlan, @@ -19,9 +19,9 @@ function PlanStatusFormController( PSFC.plan = undefined; PSFC.discounted = false; PSFC.plans = billingPlans; - PSFC.activeAccount = $rootScope.dataApp.data.activeAccount; + PSFC.currentOrg = currentOrg; - if (PSFC.activeAccount.isInTrial()) { + if (PSFC.currentOrg.poppa.isInTrial()) { loading('billingForm', true); fetchPaymentMethod() .then(function (paymentMethod) { diff --git a/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusFormDirective.js b/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusFormDirective.js index e874f6129..ddd910580 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusFormDirective.js +++ b/client/directives/modals/settingsModal/forms/billingForm/planStatus/planStatusFormDirective.js @@ -10,7 +10,7 @@ function planStatusForm( restrict: 'A', templateUrl: 'planStatusForm', controller: 'PlanStatusFormController as PSFC', - link: function ($scope, element) { + link: function ($scope) { /** * Get the classes for the meter * @returns {Object} - Object with keys of class names and true/false for if they should be enabled diff --git a/client/directives/modals/settingsModal/forms/billingForm/trialForm/trialForm.jade b/client/directives/modals/settingsModal/forms/billingForm/trialForm/trialForm.jade index 7a224f018..9715ab510 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/trialForm/trialForm.jade +++ b/client/directives/modals/settingsModal/forms/billingForm/trialForm/trialForm.jade @@ -16,20 +16,20 @@ circle(fill='#52306C', cx='25.75', cy='7.51', r='2.5') path(fill='#D5D5D5', stroke='#52306C', stroke-width='0.5', stroke-linecap='round', stroke-miterlimit='10', d='M13.75,6.75v-5c0-0.828-0.672-1.5-1.5-1.5c-0.828,0-1.5,0.672-1.5,1.5v5c0,0.828,0.672,1.5,1.5,1.5C13.078,8.25,13.75,7.578,13.75,6.75z') path(fill='#D5D5D5', stroke='#52306C', stroke-width='0.5', stroke-linecap='round', stroke-miterlimit='10', d='M27.25,6.75v-5c0-0.828-0.672-1.5-1.5-1.5c-0.828,0-1.5,0.672-1.5,1.5v5c0,0.828,0.672,1.5,1.5,1.5C26.578,8.25,27.25,7.578,27.25,6.75z') - h2.h2.text-center {{activeAccount.trialDaysRemaining()}} + h2.h2.text-center {{currentOrg.poppa.trialDaysRemaining()}} p.grid-content.p.text-gray( - ng-if = "activeAccount.trialDaysRemaining() > 3" + ng-if = "currentOrg.poppa.trialDaysRemaining() > 3" ) You have - strong.strong {{activeAccount.trialDaysRemaining()}} days + strong.strong {{currentOrg.poppa.trialDaysRemaining()}} days | left in your trial with unlimited configurations. p.grid-content.small.text-gray( - ng-if = "activeAccount.trialDaysRemaining() <= 3" - ) You only have {{activeAccount.trialDaysRemaining()}} days left in your trial! Add your payment info to ensure your team has uninterrupted access to their sandbox. + ng-if = "currentOrg.poppa.trialDaysRemaining() <= 3" + ) You only have {{currentOrg.poppa.trialDaysRemaining()}} days left in your trial! Add your payment info to ensure your team has uninterrupted access to their sandbox. .grid-block.btn-wrapper( - ng-if = "activeAccount.isInTrial() && activeAccount.trialDaysRemaining() <= 3 && fromNotification" + ng-if = "currentOrg.poppa.isInTrial() && currentOrg.poppa.trialDaysRemaining() <= 3 && fromNotification" ) button.grid-content.btn.btn-block.btn-sm.white( ng-click = "actions.openSettingsModal('billing')" diff --git a/client/directives/modals/settingsModal/forms/billingForm/trialForm/trialFormDirective.js b/client/directives/modals/settingsModal/forms/billingForm/trialForm/trialFormDirective.js index 32bb41982..2a2c2d73a 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/trialForm/trialFormDirective.js +++ b/client/directives/modals/settingsModal/forms/billingForm/trialForm/trialFormDirective.js @@ -6,7 +6,8 @@ function trialForm( $localStorage, $rootScope, keypather, - ModalService + ModalService, + currentOrg ) { return { restrict: 'A', @@ -16,10 +17,10 @@ function trialForm( fromModal: '=?' }, link: function ($scope) { - $scope.activeAccount = $rootScope.dataApp.data.activeAccount; + $scope.currentOrg = currentOrg; $scope.actions = { openSettingsModal: function (tabName, subTab) { - keypather.set($localStorage, 'hasDismissedTrialNotification.' + $scope.activeAccount.attrs.id, true); + keypather.set($localStorage, 'hasDismissedTrialNotification.' + currentOrg.github.attrs.id, true); subTab = subTab || ''; $rootScope.$broadcast('close-popovers'); ModalService.showModal({ diff --git a/client/directives/modals/settingsModal/settingsModalController.js b/client/directives/modals/settingsModal/settingsModalController.js index 178dd5e35..1e72b02e0 100644 --- a/client/directives/modals/settingsModal/settingsModalController.js +++ b/client/directives/modals/settingsModal/settingsModalController.js @@ -7,10 +7,10 @@ require('app') * @ngInject */ function SettingsModalController( - $rootScope, close, subTab, - tab + tab, + currentOrg ) { var SEMC = this; angular.extend(SEMC, { @@ -18,6 +18,6 @@ function SettingsModalController( currentTab: tab, subTab: subTab }); - SEMC.activeAccount = $rootScope.dataApp.data.activeAccount; + SEMC.currentOrg = currentOrg; SEMC.showFooter = true; } diff --git a/client/directives/modals/settingsModal/settingsModalView.jade b/client/directives/modals/settingsModal/settingsModalView.jade index ac00ccba3..3f151333e 100644 --- a/client/directives/modals/settingsModal/settingsModalView.jade +++ b/client/directives/modals/settingsModal/settingsModalView.jade @@ -13,11 +13,11 @@ .row.modal-tabs.tabs-all.grid-block.clearfix button.btn.btn-radio.grid-block.vertical( - ng-attr-data-badge-count = "{{SEMC.activeAccount.isInTrial() && !SEMC.activeAccount.attrs.hasPaymentMethod ? SEMC.activeAccount.trialDaysRemaining() : ''}}" + ng-attr-data-badge-count = "{{SEMC.currentOrg.poppa.isInTrial() && !SEMC.currentOrg.poppa.attrs.hasPaymentMethod ? SEMC.currentOrg.poppa.trialDaysRemaining() : ''}}" ng-class = "{\ 'active': SEMC.currentTab === 'billing',\ - 'badge': SEMC.activeAccount.isInTrial() && !SEMC.activeAccount.attrs.hasPaymentMethod,\ - 'badge-orange': SEMC.activeAccount.isInTrial() && !SEMC.activeAccount.attrs.hasPaymentMethod,\ + 'badge': SEMC.currentOrg.poppa.isInTrial() && !SEMC.currentOrg.poppa.attrs.hasPaymentMethod,\ + 'badge-orange': SEMC.currentOrg.poppa.isInTrial() && !SEMC.currentOrg.poppa.attrs.hasPaymentMethod,\ }" ng-click = "SEMC.currentTab = 'billing'" ng-show = "$root.featureFlags.billing" diff --git a/client/directives/repositorySelector/directiveRepositorySelector.js b/client/directives/repositorySelector/directiveRepositorySelector.js index 68d834194..a57fac464 100644 --- a/client/directives/repositorySelector/directiveRepositorySelector.js +++ b/client/directives/repositorySelector/directiveRepositorySelector.js @@ -15,13 +15,14 @@ require('app') * gitDataOnly (Optional, this makes it so no destination or build commands will be set, it skips view 2) */ function repositorySelector( - errs, - promisify, - fetchOwnerRepos, $rootScope, + $timeout, cardInfoTypes, + currentOrg, DirtyChecker, - $timeout + errs, + fetchOwnerRepos, + promisify ) { return { restrict: 'A', @@ -58,7 +59,7 @@ function repositorySelector( var Repo = cardInfoTypes.Repository; $scope.repoSelector.data = new Repo(); - fetchOwnerRepos($rootScope.dataApp.data.activeAccount.oauthName()) + fetchOwnerRepos(currentOrg.github.oauthName()) .then(function (repoList) { $scope.repoSelector.data.githubRepos = repoList; }) diff --git a/client/services/currentOrgService.js b/client/services/currentOrgService.js new file mode 100644 index 000000000..47d03a98d --- /dev/null +++ b/client/services/currentOrgService.js @@ -0,0 +1,11 @@ +'use strict'; + +require('app') + .factory('currentOrg', currentOrg); + +function currentOrg() { + return { + poppa: {}, + github: {} + }; +} diff --git a/client/services/serviceFetch.js b/client/services/serviceFetch.js index ecbb8660e..534073706 100644 --- a/client/services/serviceFetch.js +++ b/client/services/serviceFetch.js @@ -75,8 +75,7 @@ function fetchUser( function fetchWhitelistedOrgs( fetchUser, fetchWhitelists, - memoize, - moment + memoize ) { return memoize(function () { return fetchUser() @@ -88,35 +87,6 @@ function fetchWhitelistedOrgs( }); return new GithubOrgCollection(githubOrgs, {client: user.client}); }); - }) - .then(function (ghOrgCollection) { - ghOrgCollection.models.map(function (model) { - // All of this should be moved to inside @runnable/api-client - model.attrs.trialEnd = moment().subtract(1, 'days').toISOString(); - model.attrs.activePeriodEnd = moment().subtract(5, 'days').toISOString(); - model.attrs.gracePeriodEnd = moment().add(2, 'days').toISOString(); - model.attrs.stripeCustomerId = 1234; - model.attrs.hasPaymentMethod = false; - model.isInTrial = function () { - return moment(model.attrs.trialEnd) > moment().utc(); - }; - model.isInGrace = function () { - return !model.isInTrial() && !model.isInActivePeriod() && moment(model.attrs.gracePeriodEnd) > moment().utc(); - }; - model.isInActivePeriod = function () { - return moment(model.attrs.activePeriodEnd) > moment().utc(); - }; - model.isGraceExpired = function () { - return !model.isInTrial() && !model.isInActivePeriod() && moment.utc(model.attrs.gracePeriodEnd) < moment().utc(); - }; - model.trialDaysRemaining = function () { - return moment(model.attrs.trialEnd).diff(moment.utc(), 'days'); - }; - model.graceHoursRemaining = function () { - return moment(model.attrs.gracePeriodEnd).diff(moment.utc(), 'hours'); - }; - }); - return ghOrgCollection; }); }); } diff --git a/test/unit/controllers/controllerApp.unit.js b/test/unit/controllers/controllerApp.unit.js index 430139c1e..3e52ef5d0 100644 --- a/test/unit/controllers/controllerApp.unit.js +++ b/test/unit/controllers/controllerApp.unit.js @@ -14,6 +14,7 @@ describe('controllerApp'.bold.underline.blue, function () { var ctx = {}; var CA; var mockLocalStorage; + var mockCurrentOrg; var showModalStub; var mockFeatureFlags; function createMasterPods() { @@ -24,14 +25,26 @@ describe('controllerApp'.bold.underline.blue, function () { return ctx.masterPods; } function setup(delayStartup) { + mockCurrentOrg = { + poppa: { + trialDaysRemaining: sinon.stub(), + isInTrial: sinon.stub(), + isInGrace: sinon.stub(), + isGraceExpired: sinon.stub(), + attrs: { + hasPaymentMethod: false + } + }, + github: { + attrs: { + id: 'githubId1234' + } + } + }; ctx = {}; ctx.fetchInstancesByPodMock = new (require('../fixtures/mockFetch'))(); angular.mock.module('app'); ctx.fakeuser = new User(angular.copy(apiMocks.user)); - ctx.fakeuser.trialDaysRemaining = sinon.stub(); - ctx.fakeuser.isInTrial = sinon.stub(); - ctx.fakeuser.isInGrace = sinon.stub().returns(false); - ctx.fakeuser.isGraceExpired = sinon.stub().returns(false); ctx.fakeuser.socket = { joinOrgRoom: sinon.spy() }; @@ -76,6 +89,7 @@ describe('controllerApp'.bold.underline.blue, function () { showModal: showModalStub }); $provide.value('featureFlags', mockFeatureFlags); + $provide.value('currentOrg', mockCurrentOrg); }); angular.mock.inject(function ( _$controller_, @@ -149,18 +163,18 @@ describe('controllerApp'.bold.underline.blue, function () { describe('showTrialEndingNotification', function () { beforeEach(function () { keypather.set($rootScope, 'featureFlags.billing', true); - keypather.set(mockLocalStorage, 'hasDismissedTrialNotification.' + ctx.fakeuser.attrs.id, false); - ctx.fakeuser.isInTrial.returns(true); - ctx.fakeuser.trialDaysRemaining.returns(3); + keypather.set(mockLocalStorage, 'hasDismissedTrialNotification.' + mockCurrentOrg.github.attrs.id, false); + mockCurrentOrg.poppa.isInTrial.returns(true); + mockCurrentOrg.poppa.trialDaysRemaining.returns(3); }); it('should not show if not in trial', function () { - ctx.fakeuser.isInTrial.returns(false); + mockCurrentOrg.poppa.isInTrial.returns(false); expect(CA.showTrialEndingNotification()).to.equal(false); }); it('should not show if trial ends in more than 3 days', function () { - ctx.fakeuser.trialDaysRemaining.returns(4); + mockCurrentOrg.poppa.trialDaysRemaining.returns(4); expect(CA.showTrialEndingNotification()).to.equal(false); }); @@ -170,7 +184,7 @@ describe('controllerApp'.bold.underline.blue, function () { }); it('should not show if local storage shows its been dismissed', function () { - keypather.set(mockLocalStorage, 'hasDismissedTrialNotification.' + ctx.fakeuser.attrs.id, true); + keypather.set(mockLocalStorage, 'hasDismissedTrialNotification.' + mockCurrentOrg.github.attrs.id, true); expect(CA.showTrialEndingNotification()).to.equal(false); }); @@ -181,9 +195,9 @@ describe('controllerApp'.bold.underline.blue, function () { describe('closeTrialEndingNotification', function () { it('should set hasDismissedTrialNotification on local storage', function () { - keypather.set(mockLocalStorage, 'hasDismissedTrialNotification.' + ctx.fakeuser.attrs.id, false); + keypather.set(mockLocalStorage, 'hasDismissedTrialNotification.' + mockCurrentOrg.github.attrs.id, false); CA.closeTrialEndingNotification(); - expect(mockLocalStorage.hasDismissedTrialNotification[ctx.fakeuser.attrs.id]).to.equal(true); + expect(mockLocalStorage.hasDismissedTrialNotification[mockCurrentOrg.github.attrs.id]).to.equal(true); }); }); @@ -192,9 +206,9 @@ describe('controllerApp'.bold.underline.blue, function () { beforeEach(function () { var controllerSetupFn = setup(true); mockFeatureFlags.flags.billing = true; - ctx.fakeuser.isInGrace.returns(true); - ctx.fakeuser.isGraceExpired.returns(false); - ctx.fakeuser.attrs.hasPaymentMethod = true; + mockCurrentOrg.poppa.isInGrace.returns(true); + mockCurrentOrg.poppa.isGraceExpired.returns(false); + mockCurrentOrg.poppa.attrs.hasPaymentMethod = true; controllerSetupFn(); $rootScope.$digest(); }); @@ -213,9 +227,9 @@ describe('controllerApp'.bold.underline.blue, function () { beforeEach(function () { var controllerSetupFn = setup(true); mockFeatureFlags.flags.billing = true; - ctx.fakeuser.isInGrace.returns(true); - ctx.fakeuser.isGraceExpired.returns(false); - ctx.fakeuser.attrs.hasPaymentMethod = false; + mockCurrentOrg.poppa.isInGrace.returns(true); + mockCurrentOrg.poppa.isGraceExpired.returns(false); + mockCurrentOrg.poppa.attrs.hasPaymentMethod = false; controllerSetupFn(); $rootScope.$digest(); }); @@ -237,9 +251,9 @@ describe('controllerApp'.bold.underline.blue, function () { beforeEach(function () { var controllerSetupFn = setup(true); mockFeatureFlags.flags.billing = true; - ctx.fakeuser.isInGrace.returns(false); - ctx.fakeuser.isGraceExpired.returns(true); - ctx.fakeuser.attrs.hasPaymentMethod = true; + mockCurrentOrg.poppa.isInGrace.returns(false); + mockCurrentOrg.poppa.isGraceExpired.returns(true); + mockCurrentOrg.poppa.attrs.hasPaymentMethod = true; controllerSetupFn(); $rootScope.$digest(); }); @@ -259,9 +273,9 @@ describe('controllerApp'.bold.underline.blue, function () { beforeEach(function () { var controllerSetupFn = setup(true); mockFeatureFlags.flags.billing = true; - ctx.fakeuser.isInGrace.returns(false); - ctx.fakeuser.isGraceExpired.returns(true); - ctx.fakeuser.attrs.hasPaymentMethod = false; + mockCurrentOrg.poppa.isInGrace.returns(false); + mockCurrentOrg.poppa.isGraceExpired.returns(true); + mockCurrentOrg.poppa.attrs.hasPaymentMethod = false; controllerSetupFn(); $rootScope.$digest(); }); diff --git a/test/unit/directives/directiveAccountsSelect.unit.js b/test/unit/directives/directiveAccountsSelect.unit.js index 28f944f7c..2c669a1ec 100644 --- a/test/unit/directives/directiveAccountsSelect.unit.js +++ b/test/unit/directives/directiveAccountsSelect.unit.js @@ -1,14 +1,28 @@ 'use strict'; describe('directiveAccountsSelect'.bold.underline.blue, function() { - var $scope, $elScope; + var $elScope; var $rootScope; - var ctx; + var $scope; var $timeout; - var keypather; var apiMocks = require('../apiMocks/index'); + var ctx; + var keypather; + var mockCurrentOrg; beforeEach(function () { + mockCurrentOrg = { + poppa: { + isInTrial: sinon.stub().returns(true), + trialDaysRemaining: sinon.stub().returns(2), + isInActivePeriod: sinon.stub().returns(false), + isInGrace: sinon.stub(), + isGraceExpired: sinon.stub(), + attrs: { + hasPaymentMethod: false + } + } + }; ctx = {}; ctx.fakeuser = { attrs: angular.copy(apiMocks.user), @@ -23,14 +37,8 @@ describe('directiveAccountsSelect'.bold.underline.blue, function() { update: sinon.spy() }; }), - fetchSettings: sinon.spy(), - isInTrial: sinon.stub().returns(true), - trialDaysRemaining: sinon.stub().returns(2), - isInActivePeriod: sinon.stub().returns(false), - isInGrace: sinon.stub(), - isGraceExpired: sinon.stub() + fetchSettings: sinon.spy() }; - ctx.fakeuser.attrs.hasPaymentMethod = false; ctx.fakeOrg1 = { attrs: angular.copy(apiMocks.user), oauthName: function () { @@ -74,6 +82,7 @@ describe('directiveAccountsSelect'.bold.underline.blue, function() { userName: 'username', instanceName: 'instanceName' }); + $provide.value('currentOrg', mockCurrentOrg); }); angular.mock.inject(function( $compile, @@ -143,27 +152,27 @@ describe('directiveAccountsSelect'.bold.underline.blue, function() { describe('getBadgeCount', function () { describe('when in trial', function () { beforeEach(function () { - ctx.fakeuser.isInTrial.returns(true); - ctx.fakeuser.trialDaysRemaining = sinon.stub().returns(12); + mockCurrentOrg.poppa.isInTrial.returns(true); + mockCurrentOrg.poppa.trialDaysRemaining = sinon.stub().returns(12); }); it('should return trial remaining', function () { - ctx.fakeuser.isInTrial.reset(); - ctx.fakeuser.trialDaysRemaining.reset(); + mockCurrentOrg.poppa.isInTrial.reset(); + mockCurrentOrg.poppa.trialDaysRemaining.reset(); expect($elScope.getBadgeCount()).to.equal(12); - sinon.assert.calledOnce(ctx.fakeuser.isInTrial); - sinon.assert.calledOnce(ctx.fakeuser.trialDaysRemaining); + sinon.assert.calledOnce(mockCurrentOrg.poppa.isInTrial); + sinon.assert.calledOnce(mockCurrentOrg.poppa.trialDaysRemaining); }); it('should return nothing if payment method is set', function () { - ctx.fakeuser.attrs.hasPaymentMethod = true; + mockCurrentOrg.poppa.attrs.hasPaymentMethod = true; expect($elScope.getBadgeCount()).to.equal(''); }); }); describe('when active', function () { beforeEach(function () { - ctx.fakeuser.isInTrial.returns(false); + mockCurrentOrg.poppa.isInTrial.returns(false); }); it('should return grace remaining', function () { @@ -174,7 +183,7 @@ describe('directiveAccountsSelect'.bold.underline.blue, function() { describe('getClasses', function () { it('should return false flags when not in trial', function () { - ctx.fakeuser.isInTrial.returns(false); + mockCurrentOrg.poppa.isInTrial.returns(false); expect($elScope.getClasses()).to.deep.equal({ badge: false, 'badge-orange': false @@ -189,7 +198,7 @@ describe('directiveAccountsSelect'.bold.underline.blue, function() { }); it('should return false flags when payment is set', function () { - ctx.fakeuser.attrs.hasPaymentMethod = true; + mockCurrentOrg.poppa.attrs.hasPaymentMethod = true; expect($elScope.getClasses()).to.deep.equal({ badge: false, 'badge-orange': false diff --git a/test/unit/directives/directiveRepositorySelector.unit.js b/test/unit/directives/directiveRepositorySelector.unit.js index a592dbb5c..8a694b1e5 100644 --- a/test/unit/directives/directiveRepositorySelector.unit.js +++ b/test/unit/directives/directiveRepositorySelector.unit.js @@ -1,7 +1,6 @@ 'use strict'; describe('directiveRepositorySelector'.bold.underline.blue, function () { - var element; var $scope; var $rootScope; var keypather; @@ -10,9 +9,15 @@ describe('directiveRepositorySelector'.bold.underline.blue, function () { var currentConfig; var fetchOwnerRepoStub; + var mockCurrentOrg; var ctx; function initState(config) { + mockCurrentOrg = { + github: { + oauthName: sinon.stub().returns('myOauthName') + } + }; ctx = {}; ctx.commits = [ { @@ -64,8 +69,8 @@ describe('directiveRepositorySelector'.bold.underline.blue, function () { }) }; - angular.mock.module('app'); - angular.mock.module(function ($provide) { + angular.mock.module('app', function ($provide) { + $provide.value('currentOrg', mockCurrentOrg); $provide.factory('fetchOwnerRepos', function ($q) { runnable.reset(mocks.user); fetchOwnerRepoStub = sinon.stub().returns( @@ -100,7 +105,6 @@ describe('directiveRepositorySelector'.bold.underline.blue, function () { $q = _$q_; $timeout = _$timeout_; - keypather.set($rootScope, 'dataApp.data.activeAccount.oauthName', sinon.mock().returns('myOauthName')); $scope = $rootScope.$new(); if(!config){ @@ -131,8 +135,7 @@ describe('directiveRepositorySelector'.bold.underline.blue, function () { 'actions': 'actions', 'data': 'data' }); - element = $compile(tpl)($scope); - + $compile(tpl)($scope); $scope.$digest(); $timeout.flush(); }); @@ -144,7 +147,7 @@ describe('directiveRepositorySelector'.bold.underline.blue, function () { }); it('should load repo list and default it\'s view to repoSelect', function () { - sinon.assert.called($rootScope.dataApp.data.activeAccount.oauthName); + sinon.assert.called(mockCurrentOrg.github.oauthName); sinon.assert.calledOnce(fetchOwnerRepoStub); expect($scope.repoSelector.data.githubRepos.models).to.exist; diff --git a/test/unit/directives/modals/newContainerModalController.unit.js b/test/unit/directives/modals/newContainerModalController.unit.js index 244d8fc27..675323e30 100644 --- a/test/unit/directives/modals/newContainerModalController.unit.js +++ b/test/unit/directives/modals/newContainerModalController.unit.js @@ -7,7 +7,6 @@ describe('NewContainerModalController'.bold.underline.blue, function () { // Imported Values var $controller; - var $rootScope; var $q; var keypather; @@ -29,9 +28,9 @@ describe('NewContainerModalController'.bold.underline.blue, function () { var instances; var mockInstance; var repos; - var activeAccount; var repoBuildAndBranch; var mockSourceInstance; + var mockCurrentOrg; function initState () { helpCardsStub = { @@ -40,6 +39,12 @@ describe('NewContainerModalController'.bold.underline.blue, function () { errsStub = { handler: sinon.spy() }; + mockCurrentOrg = { + poppa: {}, + github: { + oauthName: sinon.stub().returns('myOauthName') + } + }; angular.mock.module('app'); angular.mock.module(function ($provide) { @@ -88,6 +93,7 @@ describe('NewContainerModalController'.bold.underline.blue, function () { }; }); $provide.value('close', closeStub); + $provide.value('currentOrg', mockCurrentOrg); $provide.factory('fetchOwnerRepos', function ($q) { runnable.reset(mocks.user); repos = runnable.newGithubRepos( @@ -102,19 +108,14 @@ describe('NewContainerModalController'.bold.underline.blue, function () { angular.mock.inject(function ( _$controller_, - _$rootScope_, + $rootScope, _keypather_, _$q_ ) { $controller = _$controller_; - keypather = _keypather_; - $rootScope = _$rootScope_; $q = _$q_; + keypather = _keypather_; - activeAccount = { - oauthName: sinon.mock().returns('myOauthName') - }; - keypather.set($rootScope, 'dataApp.data.activeAccount', activeAccount); $scope = $rootScope.$new(); NCMC = $controller('NewContainerModalController', { $scope: $scope @@ -186,7 +187,7 @@ describe('NewContainerModalController'.bold.underline.blue, function () { NCMC.createBuildAndGoToNewRepoModal(instanceName, repo); $scope.$digest(); sinon.assert.calledOnce(createNewBuildAndFetchBranch); - sinon.assert.calledWith(createNewBuildAndFetchBranch, activeAccount, repo); + sinon.assert.calledWith(createNewBuildAndFetchBranch, mockCurrentOrg.github, repo); sinon.assert.calledOnce(NCMC.newRepositoryContainer); sinon.assert.calledWithExactly(NCMC.newRepositoryContainer, repoBuildAndBranch); expect(repoBuildAndBranch.instanceName).to.equal(instanceName); @@ -202,7 +203,7 @@ describe('NewContainerModalController'.bold.underline.blue, function () { NCMC.createBuildAndGoToNewRepoModal(instanceName, repo, dockerfile, 'dockerfile'); $scope.$digest(); sinon.assert.calledOnce(createNewBuildAndFetchBranch); - sinon.assert.calledWith(createNewBuildAndFetchBranch, activeAccount, repo); + sinon.assert.calledWith(createNewBuildAndFetchBranch, mockCurrentOrg.github, repo); sinon.assert.calledOnce(NCMC.newMirrorRepositoryContainer); sinon.assert.calledWithExactly(NCMC.newMirrorRepositoryContainer, repoBuildAndBranch); sinon.assert.notCalled(NCMC.newRepositoryContainer); diff --git a/test/unit/directives/modals/settingsModal/forms/billingForm/billingFormDirective.unit.js b/test/unit/directives/modals/settingsModal/forms/billingForm/billingFormDirective.unit.js index b654f25a0..5e731504c 100644 --- a/test/unit/directives/modals/settingsModal/forms/billingForm/billingFormDirective.unit.js +++ b/test/unit/directives/modals/settingsModal/forms/billingForm/billingFormDirective.unit.js @@ -1,11 +1,11 @@ /*global directiveTemplate:true */ 'use strict'; var $scope; -var $rootScope; var element; describe('billingFormDirective'.bold.underline.blue, function () { var broadcastStub; + var mockCurrentOrg; beforeEach(function () { broadcastStub = sinon.stub(); window.helpers.killDirective('billingHistoryForm'); @@ -14,20 +14,22 @@ describe('billingFormDirective'.bold.underline.blue, function () { window.helpers.killDirective('planStatusForm'); window.helpers.killDirective('planSummary'); window.helpers.killDirective('showPaymentForm'); - angular.mock.module('app'); + mockCurrentOrg = { + poppa: { + isInTrial: sinon.stub().returns(true) + } + }; + angular.mock.module('app', function ($provide) { + $provide.value('currentOrg', mockCurrentOrg); + }); angular.mock.inject(function ( $compile, - _$rootScope_, - keypather + $rootScope ) { - $rootScope = _$rootScope_; $scope = $rootScope.$new(); $scope.SEMC = { showFooter: false }; - keypather.set($rootScope, 'dataApp.data.activeAccount', { - isInTrial: sinon.stub().returns(true) - }); $scope.save = sinon.stub(); var tpl = directiveTemplate.attribute('billing-form'); element = $compile(tpl)($scope); @@ -37,8 +39,8 @@ describe('billingFormDirective'.bold.underline.blue, function () { }); }); - it('should set active account on local scope', function () { - expect($scope.activeAccount).to.equal($rootScope.dataApp.data.activeAccount); + it('should set current org on local scope', function () { + expect($scope.currentOrg).to.equal(mockCurrentOrg); }); describe('on animated panel change', function () { diff --git a/test/unit/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.unit.js b/test/unit/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.unit.js index 8e08e2d68..117f7e4d6 100644 --- a/test/unit/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.unit.js +++ b/test/unit/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.unit.js @@ -4,16 +4,20 @@ var $controller; var $scope; var $q; -var $rootScope; -var keypather; describe('ChangePaymentFormController'.bold.underline.blue, function () { var CPFC; var stripeCreateTokenStub; var loadingStub; var fetchPaymentMethodStub; + var mockCurrentOrg; beforeEach(function () { + mockCurrentOrg = { + poppa: { + isInTrial: sinon.stub().returns(false) + } + }; angular.mock.module('app', function ($provide) { $provide.factory('stripe', function ($q) { stripeCreateTokenStub = sinon.stub().returns($q.when({id: 123})); @@ -30,24 +34,18 @@ describe('ChangePaymentFormController'.bold.underline.blue, function () { loadingStub = sinon.stub(); loadingStub.reset = sinon.stub(); $provide.value('loading', loadingStub); + $provide.value('currentOrg', mockCurrentOrg); }); angular.mock.inject(function ( + $rootScope, _$controller_, - _$rootScope_, - _$q_, - _keypather_ + _$q_ ) { - keypather = _keypather_; - $rootScope = _$rootScope_; $controller = _$controller_; - $scope = _$rootScope_.$new(); + $scope = $rootScope.$new(); $q = _$q_; }); - keypather.set($rootScope, 'dataApp.data.activeAccount', { - isInTrial: sinon.stub().returns(false) - }); - var laterController = $controller('ChangePaymentFormController', { $scope: $scope }, true); diff --git a/test/unit/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormDirective.unit.js b/test/unit/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormDirective.unit.js index b934b6550..867b62d30 100644 --- a/test/unit/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormDirective.unit.js +++ b/test/unit/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormDirective.unit.js @@ -6,13 +6,23 @@ var keypather; describe('changePaymentFormDirective'.bold.underline.blue, function () { var fetchPaymentMethodStub; + var mockCurrentOrg; beforeEach(function () { + mockCurrentOrg = { + poppa: { + isInTrial: sinon.stub().returns(true), + attrs: { + activePeriodEnd: '2016-08-12T21:24:06.000Z' + } + } + }; window.helpers.killDirective('planSummary'); angular.mock.module('app', function ($provide) { $provide.factory('fetchPaymentMethod', function ($q) { fetchPaymentMethodStub = sinon.stub().returns($q.when({})); return fetchPaymentMethodStub; }); + $provide.value('currentOrg', mockCurrentOrg); }); angular.mock.inject(function ( $compile, @@ -20,9 +30,6 @@ describe('changePaymentFormDirective'.bold.underline.blue, function () { _keypather_ ) { keypather = _keypather_; - keypather.set($rootScope, 'dataApp.data.activeAccount', { - isInTrial: sinon.stub().returns(true) - }); $scope = $rootScope.$new(); $scope.save = sinon.stub(); var tpl = directiveTemplate.attribute('change-payment-form', { @@ -77,7 +84,6 @@ describe('changePaymentFormDirective'.bold.underline.blue, function () { describe('getBillingDate', function () { it('should return the billing date', function () { - keypather.set($elScope, 'CPFC.activeAccount.attrs.activePeriodEnd', '2016-08-12T21:24:06.000Z'); expect($elScope.getBillingDate()).to.equal('Aug 12th, 2016'); }); }); diff --git a/test/unit/directives/modals/settingsModal/forms/billingForm/paymentSummaryDirective.unit.js b/test/unit/directives/modals/settingsModal/forms/billingForm/paymentSummaryDirective.unit.js index 967fdb6fa..7f62854c9 100644 --- a/test/unit/directives/modals/settingsModal/forms/billingForm/paymentSummaryDirective.unit.js +++ b/test/unit/directives/modals/settingsModal/forms/billingForm/paymentSummaryDirective.unit.js @@ -10,7 +10,15 @@ describe('paymentSummaryDirective'.bold.underline.blue, function () { var mockPlan; var mockPaymentMethod; var fetchPaymentMethodStub; + var mockCurrentOrg; beforeEach(function () { + mockCurrentOrg = { + poppa: { + attrs: { + trialEnd: '2016-08-12T21:24:06.000Z' + } + } + }; mockPlan = { next: { plan: { @@ -34,6 +42,7 @@ describe('paymentSummaryDirective'.bold.underline.blue, function () { }); loadingStub = sinon.stub(); $provide.value('loading', loadingStub); + $provide.value('currentOrg', mockCurrentOrg); }); angular.mock.inject(function ( $compile, @@ -69,7 +78,6 @@ describe('paymentSummaryDirective'.bold.underline.blue, function () { describe('getTrialEndDate', function () { it('should return the trial end date', function () { - keypather.set($elScope, 'activeAccount.attrs.trialEnd', '2016-08-12T21:24:06.000Z'); expect($elScope.getTrialEndDate()).to.equal('Aug 12th, 2016'); }); }); diff --git a/test/unit/directives/modals/settingsModal/forms/billingForm/planStatusForm/planStatusFormController.unit.js b/test/unit/directives/modals/settingsModal/forms/billingForm/planStatusForm/planStatusFormController.unit.js index 9866dcf37..f873a56e0 100644 --- a/test/unit/directives/modals/settingsModal/forms/billingForm/planStatusForm/planStatusFormController.unit.js +++ b/test/unit/directives/modals/settingsModal/forms/billingForm/planStatusForm/planStatusFormController.unit.js @@ -12,8 +12,14 @@ describe('PlanStatusFormController'.bold.underline.blue, function () { var mockPlan; var mockBillingPlans; var fetchPaymentMethodStub; + var mockCurrentOrg; beforeEach(function () { + mockCurrentOrg = { + poppa: { + isInTrial: sinon.stub().returns(true) + } + }; mockBillingPlans = { 'simplePlan': { id: 'billingSimplePlan', @@ -45,15 +51,12 @@ describe('PlanStatusFormController'.bold.underline.blue, function () { loadingStub.reset = sinon.stub(); $provide.value('loading', loadingStub); $provide.value('billingPlans', mockBillingPlans); + $provide.value('currentOrg', mockCurrentOrg); }); angular.mock.inject(function ( _$controller_, - $rootScope, - keypather + $rootScope ) { - keypather.set($rootScope, 'dataApp.data.activeAccount', { - isInTrial: sinon.stub().returns(true) - }); $controller = _$controller_; $scope = $rootScope.$new(); }); diff --git a/test/unit/directives/modals/settingsModal/forms/billingForm/planStatusForm/planStatusFormDirective.unit.js b/test/unit/directives/modals/settingsModal/forms/billingForm/planStatusForm/planStatusFormDirective.unit.js index ec8e061c4..fe00dd8f9 100644 --- a/test/unit/directives/modals/settingsModal/forms/billingForm/planStatusForm/planStatusFormDirective.unit.js +++ b/test/unit/directives/modals/settingsModal/forms/billingForm/planStatusForm/planStatusFormDirective.unit.js @@ -6,7 +6,13 @@ describe('planStatusFormDirective'.bold.underline.blue, function () { var loadingStub; var mockBillingPlans; var fetchPaymentMethodStub; + var mockCurrentOrg; beforeEach(function () { + mockCurrentOrg = { + poppa: { + isInTrial: sinon.stub().returns(true) + } + }; mockBillingPlans = { 'simplePlan': { id: 'billingSimplePlan', @@ -19,6 +25,7 @@ describe('planStatusFormDirective'.bold.underline.blue, function () { loadingStub = sinon.stub(); $provide.value('loading', loadingStub); $provide.value('billingPlans', mockBillingPlans); + $provide.value('currentOrg', mockCurrentOrg); $provide.factory('fetchPlan', function ($q) { return sinon.stub().returns($q.when({next: {plan: {}}})); }); @@ -32,22 +39,15 @@ describe('planStatusFormDirective'.bold.underline.blue, function () { }); angular.mock.inject(function ( $compile, - $rootScope, - keypather + $rootScope ) { $scope = $rootScope.$new(); - keypather.set($rootScope, 'dataApp.data.activeAccount', { - isInTrial: sinon.stub().returns(true), - trialEnd: 1234 - }); $scope.save = sinon.stub(); var tpl = directiveTemplate.attribute('plan-status-form'); $compile(tpl)($scope); $scope.PSFC = { configurations: 1, - activeAccount: { - isInTrial: sinon.stub().returns(true) - } + currentOrg: mockCurrentOrg }; $scope.$digest(); });