2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
2019-01-30 14:08:46 +01:00
|
|
|
const fs = require("fs");
|
|
|
|
|
2020-07-24 06:02:07 +02:00
|
|
|
const {JSDOM} = require("jsdom");
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2020-12-01 00:12:33 +01:00
|
|
|
const {make_zjquery} = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const noop = () => {};
|
2019-01-30 14:08:46 +01:00
|
|
|
const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8");
|
2020-07-16 22:40:18 +02:00
|
|
|
const dom = new JSDOM(template, {pretendToBeVisual: true});
|
2019-01-30 14:08:46 +01:00
|
|
|
const document = dom.window.document;
|
2019-11-02 00:06:25 +01:00
|
|
|
let jquery_init;
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2020-12-01 00:53:02 +01:00
|
|
|
set_global("$", (f) => {
|
2020-07-15 00:34:28 +02:00
|
|
|
jquery_init = f;
|
2020-12-01 00:53:02 +01:00
|
|
|
});
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("helpers", {
|
2019-01-30 14:08:46 +01:00
|
|
|
set_tab: noop,
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("StripeCheckout", {
|
2019-01-30 14:08:46 +01:00
|
|
|
configure: noop,
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("page_params", {
|
2019-01-30 14:08:46 +01:00
|
|
|
annual_price: 8000,
|
|
|
|
monthly_price: 800,
|
|
|
|
seat_count: 8,
|
|
|
|
percent_off: 20,
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("helpers", "js/billing/helpers");
|
|
|
|
zrequire("upgrade", "js/billing/upgrade");
|
2020-12-01 00:12:33 +01:00
|
|
|
set_global("$", make_zjquery());
|
2019-01-30 14:08:46 +01:00
|
|
|
|
|
|
|
run_test("initialize", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let token_func;
|
2019-01-30 14:08:46 +01:00
|
|
|
helpers.set_tab = (page_name) => {
|
|
|
|
assert.equal(page_name, "upgrade");
|
|
|
|
};
|
|
|
|
|
2020-07-31 16:55:55 +02:00
|
|
|
let create_ajax_request_form_call_count = 0;
|
2020-06-09 12:24:32 +02:00
|
|
|
helpers.create_ajax_request = (url, form_name, stripe_token, numeric_inputs, redirect_to) => {
|
2020-07-31 16:55:55 +02:00
|
|
|
create_ajax_request_form_call_count += 1;
|
2019-01-30 14:08:46 +01:00
|
|
|
if (form_name === "autopay") {
|
2020-06-09 12:24:32 +02:00
|
|
|
assert.equal(url, "/json/billing/upgrade");
|
2019-01-30 14:08:46 +01:00
|
|
|
assert.equal(stripe_token, "stripe_add_card_token");
|
2020-06-09 12:24:32 +02:00
|
|
|
assert.deepEqual(numeric_inputs, ["licenses"]);
|
|
|
|
assert.equal(redirect_to, undefined);
|
2019-01-30 14:08:46 +01:00
|
|
|
} else if (form_name === "invoice") {
|
2020-06-09 12:24:32 +02:00
|
|
|
assert.equal(url, "/json/billing/upgrade");
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal(stripe_token, undefined);
|
2020-06-09 12:24:32 +02:00
|
|
|
assert.deepEqual(numeric_inputs, ["licenses"]);
|
|
|
|
assert.equal(redirect_to, undefined);
|
|
|
|
} else if (form_name === "sponsorship") {
|
|
|
|
assert.equal(url, "/json/billing/sponsorship");
|
|
|
|
assert.equal(stripe_token, undefined);
|
|
|
|
assert.equal(numeric_inputs, undefined);
|
|
|
|
assert.equal(redirect_to, "/");
|
2019-01-30 14:08:46 +01:00
|
|
|
} else {
|
2020-10-07 09:58:04 +02:00
|
|
|
throw new Error("Unhandled case");
|
2019-01-30 14:08:46 +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, "Make payment");
|
|
|
|
assert.equal(config_opts.label, "Add card");
|
|
|
|
assert.equal(config_opts.allowRememberMe, false);
|
2019-02-27 13:53:43 +01:00
|
|
|
assert.equal(config_opts.email, "{{ email }}");
|
2019-01-30 14:08:46 +01:00
|
|
|
assert.equal(config_opts.description, "Zulip Cloud Standard");
|
|
|
|
token_func("stripe_add_card_token");
|
|
|
|
};
|
|
|
|
|
|
|
|
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-30 14:08:46 +01:00
|
|
|
token_func = config_opts.token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
open: open_func,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
helpers.show_license_section = (section) => {
|
|
|
|
assert.equal(section, "automatic");
|
|
|
|
};
|
|
|
|
|
|
|
|
helpers.update_charged_amount = (prices, schedule) => {
|
|
|
|
assert.equal(prices.annual, 6400);
|
|
|
|
assert.equal(prices.monthly, 640);
|
2020-04-17 11:17:28 +02:00
|
|
|
assert.equal(schedule, "monthly");
|
2019-01-30 14:08:46 +01:00
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("input[type=radio][name=license_management]:checked").val = () =>
|
|
|
|
document.querySelector("input[type=radio][name=license_management]:checked").value;
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("input[type=radio][name=schedule]:checked").val = () =>
|
|
|
|
document.querySelector("input[type=radio][name=schedule]:checked").value;
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#autopay-form").data = (key) =>
|
|
|
|
document.querySelector("#autopay-form").getAttribute("data-" + key);
|
2019-01-30 14:08:46 +01:00
|
|
|
|
|
|
|
jquery_init();
|
|
|
|
|
|
|
|
const e = {
|
|
|
|
preventDefault: noop,
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const add_card_click_handler = $("#add-card-button").get_on_handler("click");
|
|
|
|
const invoice_click_handler = $("#invoice-button").get_on_handler("click");
|
|
|
|
const request_sponsorship_click_handler = $("#sponsorship-button").get_on_handler("click");
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2020-07-02 01:41:40 +02:00
|
|
|
helpers.is_valid_input = () => true;
|
2019-01-30 14:08:46 +01:00
|
|
|
add_card_click_handler(e);
|
2020-07-31 16:55:55 +02:00
|
|
|
assert.equal(create_ajax_request_form_call_count, 1);
|
2019-01-30 14:08:46 +01:00
|
|
|
invoice_click_handler(e);
|
2020-07-31 16:55:55 +02:00
|
|
|
assert.equal(create_ajax_request_form_call_count, 2);
|
|
|
|
request_sponsorship_click_handler(e);
|
|
|
|
assert.equal(create_ajax_request_form_call_count, 3);
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2020-07-02 01:41:40 +02:00
|
|
|
helpers.is_valid_input = () => false;
|
2019-01-30 14:08:46 +01:00
|
|
|
add_card_click_handler(e);
|
|
|
|
invoice_click_handler(e);
|
2020-06-09 12:24:32 +02:00
|
|
|
request_sponsorship_click_handler(e);
|
2020-07-31 16:55:55 +02:00
|
|
|
assert.equal(create_ajax_request_form_call_count, 3);
|
2020-06-09 12:24:32 +02:00
|
|
|
|
2019-01-30 14:08:46 +01:00
|
|
|
helpers.show_license_section = (section) => {
|
|
|
|
assert.equal(section, "manual");
|
|
|
|
};
|
2020-07-15 00:34:28 +02:00
|
|
|
const license_change_handler = $("input[type=radio][name=license_management]").get_on_handler(
|
|
|
|
"change",
|
|
|
|
);
|
2019-01-30 14:08:46 +01:00
|
|
|
license_change_handler.call({value: "manual"});
|
|
|
|
|
|
|
|
helpers.update_charged_amount = (prices, schedule) => {
|
|
|
|
assert.equal(prices.annual, 6400);
|
|
|
|
assert.equal(prices.monthly, 640);
|
|
|
|
assert.equal(schedule, "monthly");
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
const schedule_change_handler = $("input[type=radio][name=schedule]").get_on_handler("change");
|
2019-01-30 14:08:46 +01:00
|
|
|
schedule_change_handler.call({value: "monthly"});
|
|
|
|
|
|
|
|
assert.equal($("#autopay_annual_price").text(), "64");
|
|
|
|
assert.equal($("#autopay_annual_price_per_month").text(), "5.34");
|
|
|
|
assert.equal($("#autopay_monthly_price").text(), "6.40");
|
|
|
|
assert.equal($("#invoice_annual_price").text(), "64");
|
|
|
|
assert.equal($("#invoice_annual_price_per_month").text(), "5.34");
|
2020-06-09 12:24:32 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const organization_type_change_handler = $("select[name=organization-type]").get_on_handler(
|
|
|
|
"change",
|
|
|
|
);
|
2020-06-09 12:24:32 +02:00
|
|
|
organization_type_change_handler.call({value: "open_source"});
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
|
|
|
"Open source projects are eligible for fully sponsored (free) Zulip Standard.",
|
|
|
|
);
|
2020-06-09 12:24:32 +02:00
|
|
|
organization_type_change_handler.call({value: "research"});
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
|
|
|
"Academic research organizations are eligible for fully sponsored (free) Zulip Standard.",
|
|
|
|
);
|
2020-06-09 12:24:32 +02:00
|
|
|
organization_type_change_handler.call({value: "event"});
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
|
|
|
"Events are eligible for fully sponsored (free) Zulip Standard.",
|
|
|
|
);
|
2020-06-09 12:24:32 +02:00
|
|
|
organization_type_change_handler.call({value: "education"});
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
|
|
|
"Education use is eligible for an 85%-100% discount.",
|
|
|
|
);
|
2020-06-09 12:24:32 +02:00
|
|
|
organization_type_change_handler.call({value: "non_profit"});
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
|
|
|
"Nonprofits are eligible for an 85%-100% discount.",
|
|
|
|
);
|
2020-06-09 12:24:32 +02:00
|
|
|
organization_type_change_handler.call({value: "other"});
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
|
|
|
"Your organization might be eligible for a discount or sponsorship.",
|
|
|
|
);
|
2019-01-30 14:08:46 +01:00
|
|
|
});
|
|
|
|
|
2019-02-27 13:53:43 +01:00
|
|
|
run_test("autopay_form_fields", () => {
|
|
|
|
assert.equal(document.querySelector("#autopay-form").dataset.key, "{{ publishable_key }}");
|
|
|
|
assert.equal(document.querySelector("#autopay-form").dataset.email, "{{ email }}");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
document.querySelector("#autopay-form [name=seat_count]").value,
|
|
|
|
"{{ seat_count }}",
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
document.querySelector("#autopay-form [name=signed_seat_count]").value,
|
|
|
|
"{{ signed_seat_count }}",
|
|
|
|
);
|
2019-02-27 13:53:43 +01:00
|
|
|
assert.equal(document.querySelector("#autopay-form [name=salt]").value, "{{ salt }}");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
document.querySelector("#autopay-form [name=billing_modality]").value,
|
|
|
|
"charge_automatically",
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
document.querySelector("#autopay-form #automatic_license_count").value,
|
|
|
|
"{{ seat_count }}",
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
document.querySelector("#autopay-form #manual_license_count").min,
|
|
|
|
"{{ seat_count }}",
|
|
|
|
);
|
|
|
|
|
|
|
|
const license_options = document.querySelectorAll(
|
|
|
|
"#autopay-form input[type=radio][name=license_management]",
|
|
|
|
);
|
2019-01-30 14:08:46 +01:00
|
|
|
assert.equal(license_options.length, 2);
|
|
|
|
assert.equal(license_options[0].value, "automatic");
|
|
|
|
assert.equal(license_options[1].value, "manual");
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const schedule_options = document.querySelectorAll(
|
|
|
|
"#autopay-form input[type=radio][name=schedule]",
|
|
|
|
);
|
2019-02-27 13:53:43 +01:00
|
|
|
assert.equal(schedule_options.length, 2);
|
2020-04-17 11:17:28 +02:00
|
|
|
assert.equal(schedule_options[0].value, "monthly");
|
|
|
|
assert.equal(schedule_options[1].value, "annual");
|
2019-01-30 14:08:46 +01:00
|
|
|
|
|
|
|
assert(document.querySelector("#autopay-error"));
|
|
|
|
assert(document.querySelector("#autopay-loading"));
|
|
|
|
assert(document.querySelector("#autopay"));
|
|
|
|
assert(document.querySelector("#autopay-success"));
|
2019-02-27 13:53:43 +01:00
|
|
|
assert(document.querySelector("#autopay_loading_indicator"));
|
|
|
|
|
|
|
|
assert(document.querySelector("input[name=csrfmiddlewaretoken]"));
|
2020-05-22 15:42:46 +02:00
|
|
|
|
2020-05-22 15:30:39 +02:00
|
|
|
assert(document.querySelector("#free-trial-alert-message"));
|
2019-02-27 13:53:43 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
run_test("invoice_form_fields", () => {
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
document.querySelector("#invoice-form [name=signed_seat_count]").value,
|
|
|
|
"{{ signed_seat_count }}",
|
|
|
|
);
|
2019-02-27 13:53:43 +01:00
|
|
|
assert.equal(document.querySelector("#invoice-form [name=salt]").value, "{{ salt }}");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
document.querySelector("#invoice-form [name=billing_modality]").value,
|
|
|
|
"send_invoice",
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
document.querySelector("#invoice-form [name=licenses]").min,
|
|
|
|
"{{ min_invoiced_licenses }}",
|
|
|
|
);
|
|
|
|
|
|
|
|
const schedule_options = document.querySelectorAll(
|
|
|
|
"#invoice-form input[type=radio][name=schedule]",
|
|
|
|
);
|
2019-02-27 13:53:43 +01:00
|
|
|
assert.equal(schedule_options.length, 1);
|
|
|
|
assert.equal(schedule_options[0].value, "annual");
|
2019-01-30 14:08:46 +01:00
|
|
|
|
|
|
|
assert(document.querySelector("#invoice-error"));
|
|
|
|
assert(document.querySelector("#invoice-loading"));
|
|
|
|
assert(document.querySelector("#invoice"));
|
|
|
|
assert(document.querySelector("#invoice-success"));
|
2019-02-27 13:53:43 +01:00
|
|
|
assert(document.querySelector("#invoice_loading_indicator"));
|
2019-01-30 14:08:46 +01:00
|
|
|
|
|
|
|
assert(document.querySelector("input[name=csrfmiddlewaretoken]"));
|
2020-05-22 15:42:46 +02:00
|
|
|
|
2020-05-22 15:30:39 +02:00
|
|
|
assert(document.querySelector("#free-trial-alert-message"));
|
2019-01-30 14:08:46 +01:00
|
|
|
});
|