2019-01-08 18:06:06 +01:00
|
|
|
const noop = () => {};
|
|
|
|
const fs = require("fs");
|
|
|
|
|
2020-07-24 06:02:07 +02:00
|
|
|
const {JSDOM} = require("jsdom");
|
|
|
|
|
2019-01-08 18:06:06 +01:00
|
|
|
const template = fs.readFileSync("templates/corporate/billing.html", "utf-8");
|
2020-07-16 22:40:18 +02:00
|
|
|
const dom = new JSDOM(template, {pretendToBeVisual: true});
|
2019-01-08 18:06:06 +01:00
|
|
|
const document = dom.window.document;
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let jquery_init;
|
2020-07-15 00:34:28 +02:00
|
|
|
global.$ = (f) => {
|
|
|
|
jquery_init = f;
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("helpers", {
|
2019-01-08 18:06:06 +01:00
|
|
|
set_tab: noop,
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("StripeCheckout", {
|
2019-01-08 18:06:06 +01:00
|
|
|
configure: noop,
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("billing", "js/billing/billing");
|
|
|
|
set_global("$", global.make_zjquery());
|
2019-01-08 18:06:06 +01:00
|
|
|
|
|
|
|
run_test("initialize", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let token_func;
|
2020-04-24 17:38:13 +02:00
|
|
|
|
|
|
|
let set_tab_called = false;
|
2019-01-08 18:06:06 +01:00
|
|
|
helpers.set_tab = (page_name) => {
|
|
|
|
assert.equal(page_name, "billing");
|
2020-04-24 17:38:13 +02:00
|
|
|
set_tab_called = true;
|
2019-01-08 18:06:06 +01:00
|
|
|
};
|
|
|
|
|
2020-04-24 17:38:13 +02:00
|
|
|
let create_ajax_request_called = false;
|
2019-01-08 18:06:06 +01:00
|
|
|
helpers.create_ajax_request = (url, form_name, stripe_token) => {
|
|
|
|
assert.equal(url, "/json/billing/sources/change");
|
|
|
|
assert.equal(form_name, "cardchange");
|
|
|
|
assert.equal(stripe_token, "stripe_token");
|
2020-04-24 17:38:13 +02:00
|
|
|
create_ajax_request_called = true;
|
2019-01-08 18:06:06 +01:00
|
|
|
};
|
|
|
|
|
2020-04-24 17:38:13 +02:00
|
|
|
let open_func_called = false;
|
2019-01-08 18:06:06 +01:00
|
|
|
const open_func = (config_opts) => {
|
|
|
|
assert.equal(config_opts.name, "Zulip");
|
|
|
|
assert.equal(config_opts.zipCode, true);
|
|
|
|
assert.equal(config_opts.billingAddress, true);
|
|
|
|
assert.equal(config_opts.panelLabel, "Update card");
|
|
|
|
assert.equal(config_opts.label, "Update card");
|
|
|
|
assert.equal(config_opts.allowRememberMe, false);
|
|
|
|
assert.equal(config_opts.email, "{{stripe_email}}");
|
|
|
|
|
|
|
|
token_func("stripe_token");
|
2020-04-24 17:38:13 +02:00
|
|
|
open_func_called = true;
|
2019-01-08 18:06:06 +01:00
|
|
|
};
|
|
|
|
|
2020-04-24 17:38:13 +02:00
|
|
|
let stripe_checkout_configure_called = false;
|
2019-01-08 18:06:06 +01:00
|
|
|
StripeCheckout.configure = (config_opts) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(config_opts.image, "/static/images/logo/zulip-icon-128x128.png");
|
|
|
|
assert.equal(config_opts.locale, "auto");
|
|
|
|
assert.equal(config_opts.key, "{{publishable_key}}");
|
2019-01-08 18:06:06 +01:00
|
|
|
token_func = config_opts.token;
|
2020-04-24 17:38:13 +02:00
|
|
|
stripe_checkout_configure_called = true;
|
2019-01-08 18:06:06 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
open: open_func,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#payment-method").data = (key) =>
|
|
|
|
document.querySelector("#payment-method").getAttribute("data-" + key);
|
2019-01-08 18:06:06 +01:00
|
|
|
|
|
|
|
jquery_init();
|
|
|
|
|
2020-04-24 17:38:13 +02:00
|
|
|
assert(set_tab_called);
|
|
|
|
assert(stripe_checkout_configure_called);
|
2019-01-08 18:06:06 +01:00
|
|
|
const e = {
|
|
|
|
preventDefault: noop,
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
const update_card_click_handler = $("#update-card-button").get_on_handler("click");
|
2020-04-24 17:38:13 +02:00
|
|
|
update_card_click_handler(e);
|
|
|
|
assert(create_ajax_request_called);
|
|
|
|
assert(open_func_called);
|
|
|
|
|
|
|
|
create_ajax_request_called = false;
|
|
|
|
helpers.create_ajax_request = (url, form_name, stripe_token, numeric_inputs) => {
|
|
|
|
assert.equal(url, "/json/billing/plan/change");
|
|
|
|
assert.equal(form_name, "planchange");
|
|
|
|
assert.equal(stripe_token, undefined);
|
|
|
|
assert.deepEqual(numeric_inputs, ["status"]);
|
|
|
|
create_ajax_request_called = true;
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const change_plan_status_click_handler = $("#change-plan-status").get_on_handler("click");
|
2020-04-24 17:38:13 +02:00
|
|
|
change_plan_status_click_handler(e);
|
|
|
|
assert(create_ajax_request_called);
|
2019-01-08 18:06:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
run_test("billing_template", () => {
|
|
|
|
// Elements necessary for create_ajax_request
|
|
|
|
assert(document.querySelector("#cardchange-error"));
|
|
|
|
assert(document.querySelector("#cardchange-loading"));
|
|
|
|
assert(document.querySelector("#cardchange_loading_indicator"));
|
|
|
|
assert(document.querySelector("#cardchange-success"));
|
|
|
|
|
|
|
|
assert(document.querySelector("input[name=csrfmiddlewaretoken]"));
|
|
|
|
});
|