Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

billing: Add ignored_inputs paramater to create_ajax_request.

Vishnu KS51ef5d62ad36
diff --git a/frontend_tests/node_tests/billing.js b/frontend_tests/node_tests/billing.js
index dfc5587bc45..d253998b545 100644
--- a/frontend_tests/node_tests/billing.js
+++ b/frontend_tests/node_tests/billing.js
@@ -34,10 +34,11 @@ run_test("initialize", (override) => {
});
let create_ajax_request_called = false;
- function card_change_ajax(url, form_name, stripe_token, redirect_to, method) {
+ function card_change_ajax(url, form_name, stripe_token, ignored_inputs, redirect_to, method) {
assert.equal(url, "/json/billing/sources/change");
assert.equal(form_name, "cardchange");
assert.equal(stripe_token, "stripe_token");
+ assert.deepEqual(ignored_inputs, undefined);
assert.equal(redirect_to, undefined);
assert.equal(method, undefined);
create_ajax_request_called = true;
@@ -88,10 +89,11 @@ run_test("initialize", (override) => {
});
create_ajax_request_called = false;
- function plan_change_ajax(url, form_name, stripe_token, redirect_to, method) {
+ function plan_change_ajax(url, form_name, stripe_token, ignored_inputs, redirect_to, method) {
assert.equal(url, "/json/billing/plan");
assert.equal(form_name, "planchange");
assert.equal(stripe_token, undefined);
+ assert.deepEqual(ignored_inputs, undefined);
assert.equal(redirect_to, undefined);
assert.equal(method, "PATCH");
create_ajax_request_called = true;
diff --git a/frontend_tests/node_tests/billing_helpers.js b/frontend_tests/node_tests/billing_helpers.js
index 897793a4a07..1cc0b75b7ca 100644
--- a/frontend_tests/node_tests/billing_helpers.js
+++ b/frontend_tests/node_tests/billing_helpers.js
@@ -127,16 +127,17 @@ run_test("create_ajax_request", (override) => {
assert.equal(type, "PATCH");
assert.equal(url, "/json/billing/upgrade");
- assert.equal(Object.keys(data).length, 8);
+ assert.equal(Object.keys(data).length, 7);
assert.equal(data.stripe_token, "stripe_token_id");
assert.equal(data.seat_count, "{{ seat_count }}");
assert.equal(data.signed_seat_count, "{{ signed_seat_count }}");
assert.equal(data.salt, "{{ salt }}");
assert.equal(data.billing_modality, "charge_automatically");
assert.equal(data.schedule, "monthly");
- assert.equal(data.license_management, "automatic");
assert.equal(data.licenses, "");
+ assert(!("license_management" in data));
+
history.pushState = (state_object, title, path) => {
state.pushState += 1;
assert.equal(state_object, "");
@@ -179,6 +180,7 @@ run_test("create_ajax_request", (override) => {
"/json/billing/upgrade",
"autopay",
{id: "stripe_token_id"},
+ ["license_management"],
undefined,
"PATCH",
);
diff --git a/frontend_tests/node_tests/upgrade.js b/frontend_tests/node_tests/upgrade.js
index 33118677a30..350648b7ba2 100644
--- a/frontend_tests/node_tests/upgrade.js
+++ b/frontend_tests/node_tests/upgrade.js
@@ -36,28 +36,34 @@ run_test("initialize", (override) => {
});
let create_ajax_request_form_call_count = 0;
- helpers.__Rewire__("create_ajax_request", (url, form_name, stripe_token, redirect_to) => {
- create_ajax_request_form_call_count += 1;
- switch (form_name) {
- case "autopay":
- assert.equal(url, "/json/billing/upgrade");
- assert.equal(stripe_token, "stripe_add_card_token");
- assert.equal(redirect_to, undefined);
- break;
- case "invoice":
- assert.equal(url, "/json/billing/upgrade");
- assert.equal(stripe_token, undefined);
- assert.equal(redirect_to, undefined);
- break;
- case "sponsorship":
- assert.equal(url, "/json/billing/sponsorship");
- assert.equal(stripe_token, undefined);
- assert.equal(redirect_to, "/");
- break;
- default:
- throw new Error("Unhandled case");
- }
- });
+ helpers.__Rewire__(
+ "create_ajax_request",
+ (url, form_name, stripe_token, ignored_inputs, redirect_to) => {
+ create_ajax_request_form_call_count += 1;
+ switch (form_name) {
+ case "autopay":
+ assert.equal(url, "/json/billing/upgrade");
+ assert.equal(stripe_token, "stripe_add_card_token");
+ assert.equal(ignored_inputs, undefined);
+ assert.equal(redirect_to, undefined);
+ break;
+ case "invoice":
+ assert.equal(url, "/json/billing/upgrade");
+ assert.equal(stripe_token, undefined);
+ assert.equal(ignored_inputs, undefined);
+ assert.equal(redirect_to, undefined);
+ break;
+ case "sponsorship":
+ assert.equal(url, "/json/billing/sponsorship");
+ assert.equal(stripe_token, undefined);
+ assert.equal(ignored_inputs, undefined);
+ assert.equal(redirect_to, "/");
+ break;
+ default:
+ throw new Error("Unhandled case");
+ }
+ },
+ );
const open_func = (config_opts) => {
assert.equal(config_opts.name, "Zulip");
diff --git a/static/js/billing/billing.js b/static/js/billing/billing.js
index 00f22bec32a..72c00a9d4d2 100644
--- a/static/js/billing/billing.js
+++ b/static/js/billing/billing.js
@@ -35,6 +35,7 @@ export function initialize() {
"planchange",
undefined,
undefined,
+ undefined,
"PATCH",
);
e.preventDefault();
diff --git a/static/js/billing/helpers.js b/static/js/billing/helpers.js
index 1946b566122..9c15cf6a217 100644
--- a/static/js/billing/helpers.js
+++ b/static/js/billing/helpers.js
@@ -7,6 +7,7 @@ export function create_ajax_request(
url,
form_name,
stripe_token = null,
+ ignored_inputs = [],
redirect_to = "/billing",
type = "POST",
) {
@@ -36,6 +37,9 @@ export function create_ajax_request(
}
for (const item of form.serializeArray()) {
+ if (ignored_inputs.includes(item.name)) {
+ continue;
+ }
data[item.name] = item.value;
}
diff --git a/static/js/billing/upgrade.js b/static/js/billing/upgrade.js
index b37d1c4918c..c43e97771b5 100644
--- a/static/js/billing/upgrade.js
+++ b/static/js/billing/upgrade.js
@@ -49,7 +49,13 @@ export const initialize = () => {
return;
}
e.preventDefault();
- helpers.create_ajax_request("/json/billing/sponsorship", "sponsorship", undefined, "/");
+ helpers.create_ajax_request(
+ "/json/billing/sponsorship",
+ "sponsorship",
+ undefined,
+ undefined,
+ "/",
+ );
});
const prices = {};