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");
|
2023-02-24 02:47:55 +01:00
|
|
|
const path = require("path");
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2020-07-24 06:02:07 +02:00
|
|
|
const {JSDOM} = require("jsdom");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {set_global, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const $ = require("./lib/zjquery");
|
|
|
|
const {page_params} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const noop = () => {};
|
2023-02-24 02:47:55 +01:00
|
|
|
const template = fs.readFileSync(
|
|
|
|
path.resolve(__dirname, "../../templates/corporate/upgrade.html"),
|
|
|
|
"utf8",
|
|
|
|
);
|
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;
|
2021-10-14 00:23:21 +02:00
|
|
|
const location = set_global("location", {});
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
const helpers = zrequire("../src/billing/helpers");
|
|
|
|
zrequire("../src/billing/upgrade");
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
run_test("initialize", ({override_rewire}) => {
|
2021-04-03 19:07:13 +02:00
|
|
|
page_params.annual_price = 8000;
|
|
|
|
page_params.monthly_price = 800;
|
|
|
|
page_params.seat_count = 8;
|
|
|
|
page_params.percent_off = 20;
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(helpers, "set_tab", (page_name) => {
|
2019-01-30 14:08:46 +01:00
|
|
|
assert.equal(page_name, "upgrade");
|
2021-02-28 01:28:31 +01:00
|
|
|
});
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2020-07-31 16:55:55 +02:00
|
|
|
let create_ajax_request_form_call_count = 0;
|
2020-12-30 19:00:49 +01:00
|
|
|
helpers.__Rewire__(
|
|
|
|
"create_ajax_request",
|
2021-08-29 15:33:29 +02:00
|
|
|
(url, form_name, ignored_inputs, type, success_callback) => {
|
2020-12-30 19:00:49 +01:00
|
|
|
create_ajax_request_form_call_count += 1;
|
|
|
|
switch (form_name) {
|
|
|
|
case "autopay":
|
|
|
|
assert.equal(url, "/json/billing/upgrade");
|
2020-09-03 15:34:20 +02:00
|
|
|
assert.deepEqual(ignored_inputs, []);
|
|
|
|
assert.equal(type, "POST");
|
2021-10-14 00:23:21 +02:00
|
|
|
location.replace = (new_location) => {
|
2021-08-29 15:33:29 +02:00
|
|
|
assert.equal(new_location, "https://stripe_session_url");
|
2020-09-03 15:34:20 +02:00
|
|
|
};
|
2021-08-29 15:33:29 +02:00
|
|
|
// mock redirectToCheckout and verify its called
|
|
|
|
success_callback({stripe_session_url: "https://stripe_session_url"});
|
2020-12-30 19:00:49 +01:00
|
|
|
break;
|
|
|
|
case "invoice":
|
|
|
|
assert.equal(url, "/json/billing/upgrade");
|
2020-09-03 15:34:20 +02:00
|
|
|
assert.deepEqual(ignored_inputs, []);
|
|
|
|
assert.equal(type, "POST");
|
2021-10-14 00:23:21 +02:00
|
|
|
location.replace = (new_location) => {
|
2023-03-23 04:28:36 +01:00
|
|
|
assert.equal(new_location, "/billing/");
|
2020-09-03 15:34:20 +02:00
|
|
|
};
|
|
|
|
success_callback();
|
2020-12-30 19:00:49 +01:00
|
|
|
break;
|
|
|
|
case "sponsorship":
|
|
|
|
assert.equal(url, "/json/billing/sponsorship");
|
2020-09-03 15:34:20 +02:00
|
|
|
assert.deepEqual(ignored_inputs, []);
|
|
|
|
assert.equal(type, "POST");
|
2021-10-14 00:23:21 +02:00
|
|
|
location.replace = (new_location) => {
|
2020-09-03 15:34:20 +02:00
|
|
|
assert.equal(new_location, "/");
|
|
|
|
};
|
|
|
|
success_callback();
|
2020-12-30 19:00:49 +01:00
|
|
|
break;
|
2022-04-09 23:44:38 +02:00
|
|
|
/* istanbul ignore next */
|
2020-12-30 19:00:49 +01:00
|
|
|
default:
|
|
|
|
throw new Error("Unhandled case");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(helpers, "show_license_section", (section) => {
|
2019-01-30 14:08:46 +01:00
|
|
|
assert.equal(section, "automatic");
|
2021-02-28 01:28:31 +01:00
|
|
|
});
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(helpers, "update_charged_amount", (prices, schedule) => {
|
2019-01-30 14:08:46 +01:00
|
|
|
assert.equal(prices.annual, 6400);
|
|
|
|
assert.equal(prices.monthly, 640);
|
2020-04-17 11:17:28 +02:00
|
|
|
assert.equal(schedule, "monthly");
|
2021-02-28 01:28:31 +01:00
|
|
|
});
|
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
|
|
|
|
2021-08-29 15:33:29 +02:00
|
|
|
const initialize_function = $.get_initialize_function();
|
|
|
|
initialize_function();
|
2019-01-30 14:08:46 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(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
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(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
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(helpers, "show_license_section", (section) => {
|
2019-01-30 14:08:46 +01:00
|
|
|
assert.equal(section, "manual");
|
2021-02-28 01:28:31 +01:00
|
|
|
});
|
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"});
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
override_rewire(helpers, "update_charged_amount", (prices, schedule) => {
|
2019-01-30 14:08:46 +01:00
|
|
|
assert.equal(prices.annual, 6400);
|
|
|
|
assert.equal(prices.monthly, 640);
|
|
|
|
assert.equal(schedule, "monthly");
|
2021-02-28 01:28:31 +01:00
|
|
|
});
|
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
|
|
|
|
2021-07-19 03:36:52 +02:00
|
|
|
helpers.update_discount_details("opensource");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
2021-07-19 03:36:52 +02:00
|
|
|
"Zulip Cloud Standard is free for open-source projects.",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2021-07-19 03:36:52 +02:00
|
|
|
helpers.update_discount_details("research");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
2021-07-19 03:36:52 +02:00
|
|
|
"Zulip Cloud Standard is free for academic research.",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2021-07-19 03:36:52 +02:00
|
|
|
helpers.update_discount_details("event");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
2021-07-19 20:14:45 +02:00
|
|
|
"Zulip Cloud Standard is free for academic conferences and most non-profit events.",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2021-07-19 03:36:52 +02:00
|
|
|
helpers.update_discount_details("education");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
2021-07-19 03:36:52 +02:00
|
|
|
"Zulip Cloud Standard is discounted 85% for education.",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2021-07-19 03:36:52 +02:00
|
|
|
helpers.update_discount_details("nonprofit");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
2021-07-19 20:14:45 +02:00
|
|
|
"Zulip Cloud Standard is discounted 85%+ for registered non-profits.",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2021-07-19 03:36:52 +02:00
|
|
|
helpers.update_discount_details("other");
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
$("#sponsorship-discount-details").text(),
|
2021-07-19 20:14:45 +02:00
|
|
|
"Your organization may be eligible for a discount on Zulip Cloud Standard. Organizations whose members are not employees are generally eligible.",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2019-01-30 14:08:46 +01:00
|
|
|
});
|
|
|
|
|
2019-02-27 13:53:43 +01:00
|
|
|
run_test("autopay_form_fields", () => {
|
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
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(document.querySelector("#autopay-error"));
|
|
|
|
assert.ok(document.querySelector("#autopay-loading"));
|
|
|
|
assert.ok(document.querySelector("#autopay"));
|
|
|
|
assert.ok(document.querySelector("#autopay-success"));
|
|
|
|
assert.ok(document.querySelector("#autopay_loading_indicator"));
|
2019-02-27 13:53:43 +01:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(document.querySelector("input[name=csrfmiddlewaretoken]"));
|
2020-05-22 15:42:46 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(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
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(document.querySelector("#invoice-error"));
|
|
|
|
assert.ok(document.querySelector("#invoice-loading"));
|
|
|
|
assert.ok(document.querySelector("#invoice"));
|
|
|
|
assert.ok(document.querySelector("#invoice-success"));
|
|
|
|
assert.ok(document.querySelector("#invoice_loading_indicator"));
|
2019-01-30 14:08:46 +01:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(document.querySelector("input[name=csrfmiddlewaretoken]"));
|
2020-05-22 15:42:46 +02:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(document.querySelector("#free-trial-alert-message"));
|
2019-01-30 14:08:46 +01:00
|
|
|
});
|