From e736bc3ec6a844eadd4d87f3b96c1f45b773eadf Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Fri, 31 Jul 2020 20:25:55 +0530 Subject: [PATCH] sponsorship: Ensure that all the fields are filled in form. --- frontend_tests/node_tests/upgrade.js | 9 +++++++-- static/js/billing/upgrade.js | 3 +++ templates/corporate/upgrade.html | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend_tests/node_tests/upgrade.js b/frontend_tests/node_tests/upgrade.js index bd76dbcf4d..9b8a8bc904 100644 --- a/frontend_tests/node_tests/upgrade.js +++ b/frontend_tests/node_tests/upgrade.js @@ -37,7 +37,9 @@ run_test("initialize", () => { assert.equal(page_name, "upgrade"); }; + let create_ajax_request_form_call_count = 0; helpers.create_ajax_request = (url, form_name, stripe_token, numeric_inputs, redirect_to) => { + create_ajax_request_form_call_count += 1; if (form_name === "autopay") { assert.equal(url, "/json/billing/upgrade"); assert.equal(stripe_token, "stripe_add_card_token"); @@ -111,15 +113,18 @@ run_test("initialize", () => { const request_sponsorship_click_handler = $("#sponsorship-button").get_on_handler("click"); helpers.is_valid_input = () => true; - add_card_click_handler(e); + assert.equal(create_ajax_request_form_call_count, 1); invoice_click_handler(e); + assert.equal(create_ajax_request_form_call_count, 2); + request_sponsorship_click_handler(e); + assert.equal(create_ajax_request_form_call_count, 3); helpers.is_valid_input = () => false; add_card_click_handler(e); invoice_click_handler(e); - request_sponsorship_click_handler(e); + assert.equal(create_ajax_request_form_call_count, 3); helpers.show_license_section = (section) => { assert.equal(section, "manual"); diff --git a/static/js/billing/upgrade.js b/static/js/billing/upgrade.js index 9a1672cd5f..cb4f7cc4fc 100644 --- a/static/js/billing/upgrade.js +++ b/static/js/billing/upgrade.js @@ -40,6 +40,9 @@ exports.initialize = () => { }); $("#sponsorship-button").on("click", (e) => { + if (!helpers.is_valid_input($("#sponsorship-form"))) { + return; + } e.preventDefault(); helpers.create_ajax_request( "/json/billing/sponsorship", diff --git a/templates/corporate/upgrade.html b/templates/corporate/upgrade.html index b9b5cccf94..6e2907ab3c 100644 --- a/templates/corporate/upgrade.html +++ b/templates/corporate/upgrade.html @@ -223,8 +223,8 @@ - +