Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +46,9 @@ function ChangePaymentFormController(
.then(function (res) {
return savePaymentMethod(res.id);
})
.then(function () {
return fetchWhitelists();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does fetching whitelist affect payment method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When they put in a payment method the whitelist object needs to be refreshed because the whitelist object contains a boolean flag "hasPaymentMethod"

})
.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.
Expand All @@ -60,6 +65,9 @@ function ChangePaymentFormController(
} else {
CPFC.error = messageConversion[err.type];
}
if (!CPFC.error) {
errs.handler(err);
}
})
.finally(function () {
loading('savePayment', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('ChangePaymentFormController'.bold.underline.blue, function () {
var savePaymentMethodStub;
var mockCurrentOrg;
var mockFetchPlan;
var mockFetchWhitelists;

beforeEach(function () {
mockCurrentOrg = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -89,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(savePaymentMethodStub);
sinon.assert.calledWith(savePaymentMethodStub, 123);
sinon.assert.calledOnce(fetchPaymentMethodStub.cache.clear);
Expand Down