Skip to content

Commit

Permalink
Rc release 5.8.12 (#2748)
Browse files Browse the repository at this point in the history
* 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 <utkarsh7989@gmail.com>
Co-authored-by: Ryan Eddy <44847768+RyanEddyIC@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent f98a3f8 commit b08fc2e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/javascript/benefit_sponsors/office_locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b08fc2e

Please sign in to comment.