2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2019-02-27 12:52:05 +01:00
|
|
|
const fs = require("fs");
|
2020-07-24 06:02:07 +02:00
|
|
|
|
|
|
|
const JQuery = require("jquery");
|
|
|
|
const {JSDOM} = require("jsdom");
|
|
|
|
|
2019-02-27 12:52:05 +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});
|
2020-07-24 06:02:07 +02:00
|
|
|
const jquery = JQuery(dom.window);
|
2019-02-27 12:52:05 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("$", global.make_zjquery());
|
|
|
|
set_global("page_params", {});
|
|
|
|
set_global("loading", {});
|
|
|
|
set_global("history", {});
|
|
|
|
set_global("document", {
|
2019-02-27 12:52:05 +01:00
|
|
|
title: "Zulip",
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("location", {
|
2019-02-27 12:52:05 +01:00
|
|
|
pathname: "/upgrade/",
|
|
|
|
search: "",
|
|
|
|
hash: "#billing",
|
|
|
|
});
|
2019-01-02 12:00:51 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
zrequire("helpers", "js/billing/helpers");
|
2019-02-27 12:52:05 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("create_ajax_request", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const form_loading_indicator = "#autopay_loading_indicator";
|
|
|
|
const form_input_section = "#autopay-input-section";
|
|
|
|
const form_success = "#autopay-success";
|
|
|
|
const form_error = "#autopay-error";
|
|
|
|
const form_loading = "#autopay-loading";
|
2020-05-22 15:42:46 +02:00
|
|
|
const zulip_limited_section = "#zulip-limited-section";
|
2020-05-22 15:30:39 +02:00
|
|
|
const free_trial_alert_message = "#free-trial-alert-message";
|
2019-02-27 12:52:05 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const state = {
|
2019-02-27 12:52:05 +01:00
|
|
|
form_input_section_show: 0,
|
|
|
|
form_input_section_hide: 0,
|
|
|
|
form_error_show: 0,
|
|
|
|
form_error_hide: 0,
|
|
|
|
form_loading_show: 0,
|
|
|
|
form_loading_hide: 0,
|
|
|
|
form_success_show: 0,
|
2020-05-22 15:42:46 +02:00
|
|
|
zulip_limited_section_show: 0,
|
|
|
|
zulip_limited_section_hide: 0,
|
2020-05-22 15:30:39 +02:00
|
|
|
free_trial_alert_message_hide: 0,
|
|
|
|
free_trial_alert_message_show: 0,
|
2019-02-27 12:52:05 +01:00
|
|
|
location_reload: 0,
|
|
|
|
pushState: 0,
|
|
|
|
make_indicator: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
loading.make_indicator = function (loading_indicator, config) {
|
|
|
|
assert.equal(loading_indicator.selector, form_loading_indicator);
|
|
|
|
assert.equal(config.text, "Processing ...");
|
|
|
|
assert.equal(config.abs_positioned, true);
|
|
|
|
state.make_indicator += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$(form_input_section).hide = function () {
|
|
|
|
state.form_input_section_hide += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$(form_input_section).show = function () {
|
|
|
|
state.form_input_section_show += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$(form_error).hide = function () {
|
|
|
|
state.form_error_hide += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$(form_error).show = function () {
|
|
|
|
state.form_error_show += 1;
|
|
|
|
return {
|
|
|
|
text: (msg) => {
|
|
|
|
assert.equal(msg, "response_message");
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$(form_success).show = function () {
|
|
|
|
state.form_success_show += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$(form_loading).show = function () {
|
|
|
|
state.form_loading_show += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$(form_loading).hide = function () {
|
|
|
|
state.form_loading_hide += 1;
|
|
|
|
};
|
|
|
|
|
2020-05-22 15:42:46 +02:00
|
|
|
$(zulip_limited_section).show = () => {
|
|
|
|
state.zulip_limited_section_show += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$(zulip_limited_section).hide = () => {
|
|
|
|
state.zulip_limited_section_hide += 1;
|
|
|
|
};
|
|
|
|
|
2020-05-22 15:30:39 +02:00
|
|
|
$(free_trial_alert_message).show = () => {
|
|
|
|
state.free_trial_alert_message_show += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$(free_trial_alert_message).hide = () => {
|
|
|
|
state.free_trial_alert_message_hide += 1;
|
|
|
|
};
|
|
|
|
|
2020-07-02 01:41:40 +02:00
|
|
|
$("#autopay-form").serializeArray = () => jquery("#autopay-form").serializeArray();
|
2019-02-27 12:52:05 +01:00
|
|
|
|
|
|
|
$.post = ({url, data, success, error}) => {
|
|
|
|
assert.equal(state.form_input_section_hide, 1);
|
|
|
|
assert.equal(state.form_error_hide, 1);
|
|
|
|
assert.equal(state.form_loading_show, 1);
|
2020-05-22 15:42:46 +02:00
|
|
|
assert.equal(state.zulip_limited_section_hide, 1);
|
|
|
|
assert.equal(state.zulip_limited_section_show, 0);
|
2020-05-22 15:30:39 +02:00
|
|
|
assert.equal(state.free_trial_alert_message_hide, 1);
|
|
|
|
assert.equal(state.free_trial_alert_message_show, 0);
|
2019-02-27 12:52:05 +01:00
|
|
|
assert.equal(state.make_indicator, 1);
|
|
|
|
|
|
|
|
assert.equal(url, "/json/billing/upgrade");
|
|
|
|
|
|
|
|
assert.equal(Object.keys(data).length, 8);
|
|
|
|
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"');
|
2020-04-17 11:17:28 +02:00
|
|
|
assert.equal(data.schedule, '"monthly"');
|
2019-02-27 12:52:05 +01:00
|
|
|
assert.equal(data.license_management, '"automatic"');
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(data.licenses, "");
|
2019-02-27 12:52:05 +01:00
|
|
|
|
|
|
|
history.pushState = (state_object, title, path) => {
|
|
|
|
state.pushState += 1;
|
|
|
|
assert.equal(state_object, "");
|
|
|
|
assert.equal(title, "Zulip");
|
|
|
|
assert.equal(path, "/upgrade/");
|
|
|
|
};
|
|
|
|
|
|
|
|
location.reload = () => {
|
|
|
|
state.location_reload += 1;
|
|
|
|
};
|
|
|
|
|
2020-06-09 12:24:32 +02:00
|
|
|
window.location.replace = (reload_to) => {
|
|
|
|
state.location_reload += 1;
|
|
|
|
assert.equal(reload_to, "/billing");
|
|
|
|
};
|
|
|
|
|
2019-02-27 12:52:05 +01:00
|
|
|
success();
|
|
|
|
|
|
|
|
assert.equal(state.location_reload, 1);
|
|
|
|
assert.equal(state.pushState, 1);
|
|
|
|
assert.equal(state.form_success_show, 1);
|
|
|
|
assert.equal(state.form_error_hide, 2);
|
|
|
|
assert.equal(state.form_loading_hide, 1);
|
2020-05-22 15:42:46 +02:00
|
|
|
assert.equal(state.zulip_limited_section_hide, 1);
|
|
|
|
assert.equal(state.zulip_limited_section_show, 0);
|
2020-05-22 15:30:39 +02:00
|
|
|
assert.equal(state.free_trial_alert_message_hide, 1);
|
|
|
|
assert.equal(state.free_trial_alert_message_show, 0);
|
2019-02-27 12:52:05 +01:00
|
|
|
|
|
|
|
error({responseText: '{"msg": "response_message"}'});
|
|
|
|
|
|
|
|
assert.equal(state.form_loading_hide, 2);
|
|
|
|
assert.equal(state.form_error_show, 1);
|
|
|
|
assert.equal(state.form_input_section_show, 1);
|
2020-05-22 15:42:46 +02:00
|
|
|
assert.equal(state.zulip_limited_section_hide, 1);
|
2020-05-22 15:30:39 +02:00
|
|
|
assert.equal(state.free_trial_alert_message_hide, 1);
|
|
|
|
assert.equal(state.free_trial_alert_message_show, 1);
|
2019-02-27 12:52:05 +01:00
|
|
|
};
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
helpers.create_ajax_request("/json/billing/upgrade", "autopay", {id: "stripe_token_id"}, [
|
|
|
|
"licenses",
|
|
|
|
]);
|
2019-02-27 12:52:05 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
run_test("format_money", () => {
|
|
|
|
assert.equal(helpers.format_money("100"), "1");
|
|
|
|
assert.equal(helpers.format_money("123.00"), "1.23");
|
|
|
|
assert.equal(helpers.format_money("123.45"), "1.24");
|
|
|
|
assert.equal(helpers.format_money("600"), "6");
|
|
|
|
assert.equal(helpers.format_money("640"), "6.40");
|
|
|
|
assert.equal(helpers.format_money("666.6666666666666"), "6.67");
|
|
|
|
assert.equal(helpers.format_money("7600"), "76");
|
|
|
|
assert.equal(helpers.format_money("8000"), "80");
|
|
|
|
assert.equal(helpers.format_money("123416.323"), "1234.17");
|
|
|
|
assert.equal(helpers.format_money("927268238"), "9272682.38");
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test("update_charged_amount", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const prices = {};
|
2019-02-27 12:52:05 +01:00
|
|
|
prices.annual = 8000;
|
|
|
|
prices.monthly = 800;
|
|
|
|
page_params.seat_count = 35;
|
|
|
|
|
|
|
|
helpers.update_charged_amount(prices, "annual");
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal($("#charged_amount").text(), (80 * 35).toString());
|
2019-02-27 12:52:05 +01:00
|
|
|
|
|
|
|
helpers.update_charged_amount(prices, "monthly");
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal($("#charged_amount").text(), (8 * 35).toString());
|
2019-02-27 12:52:05 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
run_test("show_license_section", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const state = {
|
2019-02-27 12:52:05 +01:00
|
|
|
show_license_automatic_section: 0,
|
|
|
|
show_license_manual_section: 0,
|
|
|
|
hide_license_automatic_section: 0,
|
|
|
|
hide_license_manual_section: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
$("#license-automatic-section").show = () => {
|
|
|
|
state.show_license_automatic_section += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$("#license-manual-section").show = () => {
|
|
|
|
state.show_license_manual_section += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$("#license-automatic-section").hide = () => {
|
|
|
|
state.hide_license_automatic_section += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$("#license-manual-section").hide = () => {
|
|
|
|
state.hide_license_manual_section += 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
helpers.show_license_section("automatic");
|
|
|
|
|
|
|
|
assert.equal(state.hide_license_automatic_section, 1);
|
|
|
|
assert.equal(state.hide_license_manual_section, 1);
|
|
|
|
assert.equal(state.show_license_automatic_section, 1);
|
|
|
|
assert.equal(state.show_license_manual_section, 0);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#automatic_license_count").prop("disabled"), false);
|
|
|
|
assert.equal($("#manual_license_count").prop("disabled"), true);
|
2019-02-27 12:52:05 +01:00
|
|
|
|
|
|
|
helpers.show_license_section("manual");
|
|
|
|
|
|
|
|
assert.equal(state.hide_license_automatic_section, 2);
|
|
|
|
assert.equal(state.hide_license_manual_section, 2);
|
|
|
|
assert.equal(state.show_license_automatic_section, 1);
|
|
|
|
assert.equal(state.show_license_manual_section, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal($("#automatic_license_count").prop("disabled"), true);
|
|
|
|
assert.equal($("#manual_license_count").prop("disabled"), false);
|
2019-02-27 12:52:05 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
run_test("set_tab", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const state = {
|
2019-02-27 12:52:05 +01:00
|
|
|
show_tab_billing: 0,
|
|
|
|
show_tab_payment_method: 0,
|
|
|
|
scrollTop: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
$('#upgrade-tabs.nav a[href="#billing"]').tab = (action) => {
|
|
|
|
state.show_tab_billing += 1;
|
|
|
|
assert.equal(action, "show");
|
|
|
|
};
|
|
|
|
|
|
|
|
$('#upgrade-tabs.nav a[href="#payment-method"]').tab = (action) => {
|
|
|
|
state.show_tab_payment_method += 1;
|
|
|
|
assert.equal(action, "show");
|
|
|
|
};
|
|
|
|
|
|
|
|
$("html").scrollTop = (val) => {
|
|
|
|
state.scrollTop += 1;
|
|
|
|
assert.equal(val, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
helpers.set_tab("upgrade");
|
|
|
|
assert.equal(state.show_tab_billing, 1);
|
|
|
|
assert.equal(state.scrollTop, 1);
|
|
|
|
|
|
|
|
const click_handler = $("#upgrade-tabs.nav-tabs a").get_on_handler("click");
|
|
|
|
click_handler.call({hash: "#payment-method"});
|
|
|
|
assert.equal(location.hash, "#payment-method");
|
|
|
|
|
|
|
|
const hash_change_handler = window.onhashchange;
|
|
|
|
hash_change_handler();
|
|
|
|
assert.equal(state.show_tab_payment_method, 1);
|
|
|
|
assert.equal(state.scrollTop, 2);
|
|
|
|
});
|