From f4d712882615ccc1e50fdd58d05ce469d67cbd49 Mon Sep 17 00:00:00 2001 From: Myztiq Date: Wed, 24 Aug 2016 11:04:25 -0700 Subject: [PATCH 1/3] We now update the whitelists model when the payment method is added so we know it's been refreshed in the UI. --- .../changePaymentForm/changePaymentFormController.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js b/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js index 25e76f8c2..2eaadf9e5 100644 --- a/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js +++ b/client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js @@ -6,11 +6,13 @@ require('app') function ChangePaymentFormController( $rootScope, currentOrg, + errs, fetchPaymentMethod, + fetchPlan, + fetchWhitelists, loading, savePaymentMethod, - stripe, - fetchPlan + stripe ) { var CPFC = this; CPFC.currentOrg = currentOrg; @@ -44,6 +46,9 @@ function ChangePaymentFormController( .then(function (res) { return savePaymentMethod(res.id); }) + .then(function () { + return fetchWhitelists(); + }) .then(function () { // Not doing an angular timeout because we don't care about the digest. // We want to wait for this form to no longer be visible before we clear it and cause error outlines to show. @@ -60,6 +65,9 @@ function ChangePaymentFormController( } else { CPFC.error = messageConversion[err.type]; } + if (!CPFC.error) { + errs.handler(err); + } }) .finally(function () { loading('savePayment', false); From 5f87684d5ab7db111b4d6a6d5dff0cb85378dd49 Mon Sep 17 00:00:00 2001 From: Myztiq Date: Wed, 24 Aug 2016 12:05:08 -0700 Subject: [PATCH 2/3] Added tests for making sure we re-fetch whitelists (to make sure to update hasPaymentMethod property) --- .../changePaymentForm/changePaymentFormController.unit.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 123ae4b71..5ed536307 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 @@ -14,6 +14,7 @@ describe('ChangePaymentFormController'.bold.underline.blue, function () { var savePaymentMethodStub; var mockCurrentOrg; var mockFetchPlan; + var mockFetchWhitelists; beforeEach(function () { mockCurrentOrg = { @@ -35,6 +36,10 @@ describe('ChangePaymentFormController'.bold.underline.blue, function () { mockFetchPlan = sinon.stub().returns($q.when({})); return mockFetchPlan; }); + $provide.factory('fetchWhitelists', function ($q) { + mockFetchWhitelists = sinon.stub().returns($q.when([])); + return mockFetchWhitelists; + }); $provide.factory('fetchPaymentMethod', function ($q) { fetchPaymentMethodStub = sinon.stub().returns($q.when({})); fetchPaymentMethodStub.cache = { @@ -89,7 +94,7 @@ describe('ChangePaymentFormController'.bold.underline.blue, function () { sinon.assert.calledWith(loadingStub, 'savePayment', true); sinon.assert.calledWith(loadingStub, 'savePayment', false); sinon.assert.calledWith(loadingStub.reset, 'savePayment'); - + sinon.assert.calledOnce(fetchPaymentMethodStub); sinon.assert.calledOnce(savePaymentMethodStub); sinon.assert.calledWith(savePaymentMethodStub, 123); sinon.assert.calledOnce(fetchPaymentMethodStub.cache.clear); From 2268ca4d82eec9411906b3ba7a448e1ff6dd0601 Mon Sep 17 00:00:00 2001 From: Myztiq Date: Wed, 24 Aug 2016 12:18:30 -0700 Subject: [PATCH 3/3] Fixed tests! --- .../changePaymentForm/changePaymentFormController.unit.js | 1 - 1 file changed, 1 deletion(-) 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 5ed536307..a6e9ece50 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 @@ -94,7 +94,6 @@ describe('ChangePaymentFormController'.bold.underline.blue, function () { sinon.assert.calledWith(loadingStub, 'savePayment', true); sinon.assert.calledWith(loadingStub, 'savePayment', false); sinon.assert.calledWith(loadingStub.reset, 'savePayment'); - sinon.assert.calledOnce(fetchPaymentMethodStub); sinon.assert.calledOnce(savePaymentMethodStub); sinon.assert.calledWith(savePaymentMethodStub, 123); sinon.assert.calledOnce(fetchPaymentMethodStub.cache.clear);