mirror of https://github.com/zulip/zulip.git
billing: Add ignored_inputs paramater to create_ajax_request.
This commit is contained in:
parent
20d2e00cf9
commit
51ef5d62ad
|
@ -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;
|
||||
|
|
|
@ -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",
|
||||
);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -35,6 +35,7 @@ export function initialize() {
|
|||
"planchange",
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
"PATCH",
|
||||
);
|
||||
e.preventDefault();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = {};
|
||||
|
|
Loading…
Reference in New Issue