From b08fc2e6e1709922f297cd678c0d323a34a4208e Mon Sep 17 00:00:00 2001 From: Sri Harsha Date: Wed, 28 Aug 2024 13:50:54 -0400 Subject: [PATCH] Rc release 5.8.12 (#2748) * Fix rating area issue due to no county (#2740) * adds county validation on primary office locations * adds specs * adds ajax call on fetching county zip code on page load * fixes rubocop error * fix spec failure --------- Co-authored-by: Ryan Eddy <44847768+RyanEddyIC@users.noreply.github.com> * fixes session expired error on add benefit packcage (#2744) --------- Co-authored-by: Utkarsh Shukla Co-authored-by: Ryan Eddy <44847768+RyanEddyIC@users.noreply.github.com> --- .../benefit_sponsors/office_locations.js | 2 +- .../forms/office_locations/_address.html.slim | 44 +++++++++++++++++++ .../benefit_packages_controller.rb | 1 + .../benefit_sponsors/organizations/profile.rb | 11 +++++ .../registration_form_spec.rb | 9 ++++ 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/app/javascript/benefit_sponsors/office_locations.js b/app/javascript/benefit_sponsors/office_locations.js index dded67e0f1f..7532b548118 100644 --- a/app/javascript/benefit_sponsors/office_locations.js +++ b/app/javascript/benefit_sponsors/office_locations.js @@ -6,7 +6,7 @@ function checkOLKind(element) { row.find('#inputCounty').attr('disabled', true); row.find('#inputCounty').attr('data-target','zip-check.countySelect'); row.find('#inputZip').attr('required', true); - row.find('#inputZip').attr('data-action', 'change->zip-check#zipChange'); + row.find('#inputZip').attr('data-action', 'change->zip-check#zipChange click->zip-check#zipChange'); } else { row.find('#inputCounty').removeAttr('required'); row.find('#inputCounty').removeProp('required'); diff --git a/app/views/ui-components/v1/forms/office_locations/_address.html.slim b/app/views/ui-components/v1/forms/office_locations/_address.html.slim index 218a45e3d59..01233930852 100644 --- a/app/views/ui-components/v1/forms/office_locations/_address.html.slim +++ b/app/views/ui-components/v1/forms/office_locations/_address.html.slim @@ -46,6 +46,50 @@ javascript: function checkKind(element) { checkOLKind(element) + updateCounty(element) + } + + function updateCounty(element) { + var value = element.value; + var zip = document.getElementById('inputZip'); + if (value === 'primary' && zip.value.length > 4) { + var county = document.getElementById('inputCounty'); + var zipValue = zip.value; + var countyNames = fetchCounty(zipValue); + if (countyNames.length >= 1) { + county.removeAttribute('disabled'); + county.setAttribute('required', 'true'); + for (let option of countyNames) { + let newOption = document.createElement("option") + newOption.text = option; + newOption.value = option; + county.add(newOption); + } + } else { + county.setAttribute('disabled', true); + county.options.length = 0; + let newOption = document.createElement("option") + newOption.text = "Zipcode outside of MA"; + newOption.value = "Zipcode outside of MA"; + county.add(newOption); + zip.parentElement.classList.add('was-validated'); + zip.setCustomValidity("Zipcode outside of MA"); + } + }; + } + + function fetchCounty(zip) { + var county = ''; + $.ajax({ + method: 'POST', + url: '/benefit_sponsors/profiles/registrations/counties_for_zip_code', + data: { zip_code: zip }, + async: false, + success: function (data) { + county = data; + } + }); + return county; } document.addEventListener('DOMContentLoaded', function () { diff --git a/components/benefit_sponsors/app/controllers/benefit_sponsors/benefit_packages/benefit_packages_controller.rb b/components/benefit_sponsors/app/controllers/benefit_sponsors/benefit_packages/benefit_packages_controller.rb index 9ea69b8a664..96e10c8bcbf 100644 --- a/components/benefit_sponsors/app/controllers/benefit_sponsors/benefit_packages/benefit_packages_controller.rb +++ b/components/benefit_sponsors/app/controllers/benefit_sponsors/benefit_packages/benefit_packages_controller.rb @@ -5,6 +5,7 @@ module BenefitPackages class BenefitPackagesController < ApplicationController before_action :check_for_late_rates, only: [:new] + skip_before_action :verify_authenticity_token, only: :create include Pundit diff --git a/components/benefit_sponsors/app/models/benefit_sponsors/organizations/profile.rb b/components/benefit_sponsors/app/models/benefit_sponsors/organizations/profile.rb index d7e05b16f09..7e21de8534e 100644 --- a/components/benefit_sponsors/app/models/benefit_sponsors/organizations/profile.rb +++ b/components/benefit_sponsors/app/models/benefit_sponsors/organizations/profile.rb @@ -47,6 +47,8 @@ class Profile inclusion: { in: ::BenefitMarkets::CONTACT_METHOD_KINDS, message: "%{value} is not a valid contact method" }, allow_blank: false + validate :employer_profile_county + after_save :publish_profile_event def publish_profile_event @@ -140,6 +142,15 @@ def initialize_profile # Subclasses may extend this method def build_nested_models end + + def employer_profile_county + return unless _type.match(/.*CcaEmployerProfile$/) + return unless primary_office_location.present? + return unless primary_office_location.address.kind == 'primary' + return unless primary_office_location.address.county.blank? + + organization.errors.add(:base, 'must have a valid County for their primary office location') + end end end end diff --git a/components/benefit_sponsors/spec/models/benefit_sponsors/organizations/organization_forms/registration_form_spec.rb b/components/benefit_sponsors/spec/models/benefit_sponsors/organizations/organization_forms/registration_form_spec.rb index 6686a6ace87..249c9270ddd 100644 --- a/components/benefit_sponsors/spec/models/benefit_sponsors/organizations/organization_forms/registration_form_spec.rb +++ b/components/benefit_sponsors/spec/models/benefit_sponsors/organizations/organization_forms/registration_form_spec.rb @@ -126,6 +126,15 @@ module BenefitSponsors expect(create_form.organization.profile_type).to eq profile_type expect(create_form.organization.profile.profile_type).to eq profile_type end + + it 'should error out create when county is nil' do + if profile_type == "benefit_sponsor" + params["organization"]["profile_attributes"]["office_locations_attributes"]["0"]["address_attributes"]["county"] = nil + create_form_no_county = BenefitSponsors::Organizations::OrganizationForms::RegistrationForm.for_create params + create_form_no_county.save + expect(create_form_no_county.errors.full_messages).to include(/must have a valid County for their primary office location/) + end + end end describe '##for_create' do