2019-01-30 14:08:46 +01:00
|
|
|
const noop = () => {};
|
|
|
|
const { JSDOM } = require("jsdom");
|
|
|
|
const fs = require("fs");
|
|
|
|
|
|
|
|
const template = fs.readFileSync("templates/corporate/upgrade.html", "utf-8");
|
|
|
|
const dom = new JSDOM(template, { pretendToBeVisual: true });
|
|
|
|
const document = dom.window.document;
|
2019-11-02 00:06:25 +01:00
|
|
|
let jquery_init;
|
2019-01-30 14:08:46 +01:00
|
|
|
|
|
|
|
global.$ = (f) => {jquery_init = f;};
|
|
|
|
|
|
|
|
set_global('helpers', {
|
|
|
|
set_tab: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('StripeCheckout', {
|
|
|
|
configure: noop,
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('page_params', {
|
|
|
|
annual_price: 8000,
|
|
|
|
monthly_price: 800,
|
|
|
|
seat_count: 8,
|
|
|
|
percent_off: 20,
|
|
|
|
});
|
|
|
|
|
|
|
|
zrequire('helpers', "js/billing/helpers");
|
|
|
|
zrequire('upgrade', "js/billing/upgrade");
|
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
|
|
|
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");
|
|
|
|
};
|
|
|
|
|
|
|
|
helpers.create_ajax_request = (url, form_name, stripe_token) => {
|
|
|
|
assert.equal(url, "/json/billing/upgrade");
|
|
|
|
if (form_name === "autopay") {
|
|
|
|
assert.equal(stripe_token, "stripe_add_card_token");
|
|
|
|
} else if (form_name === "invoice") {
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal(stripe_token, undefined);
|
2019-01-30 14:08:46 +01:00
|
|
|
} else {
|
|
|
|
throw Error("Unhandled case");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
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 }}');
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
$('input[type=radio][name=license_management]:checked').val = () => {
|
|
|
|
return document.querySelector("input[type=radio][name=license_management]:checked").value;
|
|
|
|
};
|
|
|
|
|
|
|
|
$('input[type=radio][name=schedule]:checked').val = () => {
|
|
|
|
return document.querySelector("input[type=radio][name=schedule]:checked").value;
|
|
|
|
};
|
|
|
|
|
|
|
|
$("#autopay-form").data = (key) => {
|
|
|
|
return document.querySelector("#autopay-form").getAttribute("data-" + key);
|
|
|
|
};
|
|
|
|
|
|
|
|
jquery_init();
|
|
|
|
|
|
|
|
const e = {
|
|
|
|
preventDefault: noop,
|
|
|
|
};
|
|
|
|
|
|
|
|
const add_card_click_handler = $('#add-card-button').get_on_handler('click');
|
|
|
|
const invoice_click_handler = $('#invoice-button').get_on_handler('click');
|
|
|
|
|
|
|
|
helpers.is_valid_input = () => {
|
|
|
|
return true;
|
|
|
|
};
|
2020-05-22 15:42:46 +02:00
|
|
|
|
2019-01-30 14:08:46 +01:00
|
|
|
add_card_click_handler(e);
|
|
|
|
invoice_click_handler(e);
|
|
|
|
|
|
|
|
helpers.is_valid_input = () => {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
add_card_click_handler(e);
|
|
|
|
invoice_click_handler(e);
|
|
|
|
|
|
|
|
helpers.show_license_section = (section) => {
|
|
|
|
assert.equal(section, "manual");
|
|
|
|
};
|
|
|
|
const license_change_handler = $('input[type=radio][name=license_management]').get_on_handler('change');
|
|
|
|
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");
|
|
|
|
};
|
|
|
|
const schedule_change_handler = $('input[type=radio][name=schedule]').get_on_handler('change');
|
|
|
|
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");
|
|
|
|
});
|
|
|
|
|
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 }}");
|
|
|
|
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 }}");
|
|
|
|
assert.equal(document.querySelector("#autopay-form [name=salt]").value, "{{ salt }}");
|
|
|
|
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 }}");
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
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");
|
|
|
|
|
2019-11-02 00:06:25 +01: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
|
|
|
|
|
|
|
assert(document.querySelector("#zulip-limited-section"));
|
2019-02-27 13:53:43 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
run_test("invoice_form_fields", () => {
|
|
|
|
assert.equal(document.querySelector("#invoice-form [name=signed_seat_count]").value, "{{ signed_seat_count }}");
|
|
|
|
assert.equal(document.querySelector("#invoice-form [name=salt]").value, "{{ salt }}");
|
|
|
|
assert.equal(document.querySelector("#invoice-form [name=billing_modality]").value, "send_invoice");
|
|
|
|
assert.equal(document.querySelector("#invoice-form [name=licenses]").min, "{{ min_invoiced_licenses }}");
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
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
|
|
|
|
|
|
|
assert(document.querySelector("#zulip-limited-section"));
|
2019-01-30 14:08:46 +01:00
|
|
|
});
|