mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
billing: Add ignored_inputs paramater to create_ajax_request.
This commit is contained in:
@@ -34,10 +34,11 @@ run_test("initialize", (override) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let create_ajax_request_called = false;
|
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(url, "/json/billing/sources/change");
|
||||||
assert.equal(form_name, "cardchange");
|
assert.equal(form_name, "cardchange");
|
||||||
assert.equal(stripe_token, "stripe_token");
|
assert.equal(stripe_token, "stripe_token");
|
||||||
|
assert.deepEqual(ignored_inputs, undefined);
|
||||||
assert.equal(redirect_to, undefined);
|
assert.equal(redirect_to, undefined);
|
||||||
assert.equal(method, undefined);
|
assert.equal(method, undefined);
|
||||||
create_ajax_request_called = true;
|
create_ajax_request_called = true;
|
||||||
@@ -88,10 +89,11 @@ run_test("initialize", (override) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
create_ajax_request_called = false;
|
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(url, "/json/billing/plan");
|
||||||
assert.equal(form_name, "planchange");
|
assert.equal(form_name, "planchange");
|
||||||
assert.equal(stripe_token, undefined);
|
assert.equal(stripe_token, undefined);
|
||||||
|
assert.deepEqual(ignored_inputs, undefined);
|
||||||
assert.equal(redirect_to, undefined);
|
assert.equal(redirect_to, undefined);
|
||||||
assert.equal(method, "PATCH");
|
assert.equal(method, "PATCH");
|
||||||
create_ajax_request_called = true;
|
create_ajax_request_called = true;
|
||||||
|
|||||||
@@ -127,16 +127,17 @@ run_test("create_ajax_request", (override) => {
|
|||||||
assert.equal(type, "PATCH");
|
assert.equal(type, "PATCH");
|
||||||
assert.equal(url, "/json/billing/upgrade");
|
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.stripe_token, "stripe_token_id");
|
||||||
assert.equal(data.seat_count, "{{ seat_count }}");
|
assert.equal(data.seat_count, "{{ seat_count }}");
|
||||||
assert.equal(data.signed_seat_count, "{{ signed_seat_count }}");
|
assert.equal(data.signed_seat_count, "{{ signed_seat_count }}");
|
||||||
assert.equal(data.salt, "{{ salt }}");
|
assert.equal(data.salt, "{{ salt }}");
|
||||||
assert.equal(data.billing_modality, "charge_automatically");
|
assert.equal(data.billing_modality, "charge_automatically");
|
||||||
assert.equal(data.schedule, "monthly");
|
assert.equal(data.schedule, "monthly");
|
||||||
assert.equal(data.license_management, "automatic");
|
|
||||||
assert.equal(data.licenses, "");
|
assert.equal(data.licenses, "");
|
||||||
|
|
||||||
|
assert(!("license_management" in data));
|
||||||
|
|
||||||
history.pushState = (state_object, title, path) => {
|
history.pushState = (state_object, title, path) => {
|
||||||
state.pushState += 1;
|
state.pushState += 1;
|
||||||
assert.equal(state_object, "");
|
assert.equal(state_object, "");
|
||||||
@@ -179,6 +180,7 @@ run_test("create_ajax_request", (override) => {
|
|||||||
"/json/billing/upgrade",
|
"/json/billing/upgrade",
|
||||||
"autopay",
|
"autopay",
|
||||||
{id: "stripe_token_id"},
|
{id: "stripe_token_id"},
|
||||||
|
["license_management"],
|
||||||
undefined,
|
undefined,
|
||||||
"PATCH",
|
"PATCH",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -36,28 +36,34 @@ run_test("initialize", (override) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let create_ajax_request_form_call_count = 0;
|
let create_ajax_request_form_call_count = 0;
|
||||||
helpers.__Rewire__("create_ajax_request", (url, form_name, stripe_token, redirect_to) => {
|
helpers.__Rewire__(
|
||||||
create_ajax_request_form_call_count += 1;
|
"create_ajax_request",
|
||||||
switch (form_name) {
|
(url, form_name, stripe_token, ignored_inputs, redirect_to) => {
|
||||||
case "autopay":
|
create_ajax_request_form_call_count += 1;
|
||||||
assert.equal(url, "/json/billing/upgrade");
|
switch (form_name) {
|
||||||
assert.equal(stripe_token, "stripe_add_card_token");
|
case "autopay":
|
||||||
assert.equal(redirect_to, undefined);
|
assert.equal(url, "/json/billing/upgrade");
|
||||||
break;
|
assert.equal(stripe_token, "stripe_add_card_token");
|
||||||
case "invoice":
|
assert.equal(ignored_inputs, undefined);
|
||||||
assert.equal(url, "/json/billing/upgrade");
|
assert.equal(redirect_to, undefined);
|
||||||
assert.equal(stripe_token, undefined);
|
break;
|
||||||
assert.equal(redirect_to, undefined);
|
case "invoice":
|
||||||
break;
|
assert.equal(url, "/json/billing/upgrade");
|
||||||
case "sponsorship":
|
assert.equal(stripe_token, undefined);
|
||||||
assert.equal(url, "/json/billing/sponsorship");
|
assert.equal(ignored_inputs, undefined);
|
||||||
assert.equal(stripe_token, undefined);
|
assert.equal(redirect_to, undefined);
|
||||||
assert.equal(redirect_to, "/");
|
break;
|
||||||
break;
|
case "sponsorship":
|
||||||
default:
|
assert.equal(url, "/json/billing/sponsorship");
|
||||||
throw new Error("Unhandled case");
|
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) => {
|
const open_func = (config_opts) => {
|
||||||
assert.equal(config_opts.name, "Zulip");
|
assert.equal(config_opts.name, "Zulip");
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ export function initialize() {
|
|||||||
"planchange",
|
"planchange",
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
|
undefined,
|
||||||
"PATCH",
|
"PATCH",
|
||||||
);
|
);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export function create_ajax_request(
|
|||||||
url,
|
url,
|
||||||
form_name,
|
form_name,
|
||||||
stripe_token = null,
|
stripe_token = null,
|
||||||
|
ignored_inputs = [],
|
||||||
redirect_to = "/billing",
|
redirect_to = "/billing",
|
||||||
type = "POST",
|
type = "POST",
|
||||||
) {
|
) {
|
||||||
@@ -36,6 +37,9 @@ export function create_ajax_request(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const item of form.serializeArray()) {
|
for (const item of form.serializeArray()) {
|
||||||
|
if (ignored_inputs.includes(item.name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
data[item.name] = item.value;
|
data[item.name] = item.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,13 @@ export const initialize = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
helpers.create_ajax_request("/json/billing/sponsorship", "sponsorship", undefined, "/");
|
helpers.create_ajax_request(
|
||||||
|
"/json/billing/sponsorship",
|
||||||
|
"sponsorship",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
"/",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const prices = {};
|
const prices = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user