diff --git a/components/benefit_sponsors/app/models/benefit_sponsors/benefit_sponsorships/benefit_sponsorship.rb b/components/benefit_sponsors/app/models/benefit_sponsors/benefit_sponsorships/benefit_sponsorship.rb index 904c0665a22..091894a49f7 100644 --- a/components/benefit_sponsors/app/models/benefit_sponsors/benefit_sponsorships/benefit_sponsorship.rb +++ b/components/benefit_sponsors/app/models/benefit_sponsors/benefit_sponsorships/benefit_sponsorship.rb @@ -461,7 +461,7 @@ def overlapping_coverage_exists?(benefit_application) end def oe_extended_applications - benefit_applications.select do |application| + benefit_applications.select do |application| application.enrollment_extended? && TimeKeeper.date_of_record > open_enrollment_period_for(application.effective_date).max end end @@ -501,7 +501,7 @@ def dt_display_benefit_application end def off_cycle_benefit_application - recent_bas = benefit_applications.where(:aasm_state.ne => :canceled).order_by(:created_at.asc).to_a.last(3) + recent_bas = benefit_applications.where(:aasm_state.ne => :canceled).order_by(:created_at.asc).to_a.last(4) termed_or_ineligible_app = recent_bas.select(&:is_termed_or_ineligible?).max_by(&:start_on) return nil unless termed_or_ineligible_app @@ -604,7 +604,7 @@ def carriers_dropped_for(product_kind) renewal_benefit_application.predecessor.issuers_offered_for(product_kind) - renewal_benefit_application.issuers_offered_for(product_kind) if renewal_benefit_application.present? late_renewal_benefit_application.predecessor.issuers_offered_for(product_kind) - late_renewal_benefit_application.issuers_offered_for(product_kind) if late_renewal_benefit_application.present? end - + #### # Workflow for self service @@ -624,7 +624,7 @@ def carriers_dropped_for(product_kind) state :suspended # Premium payment is 61-90 days past due and Sponsor's benefit coverage has lapsed state :terminated # Sponsor's ability to offer benefits under this BenefitSponsorship is permanently terminated state :ineligible # Sponsor is permanently banned from sponsoring benefits due to regulation or policy - + # event :approve_initial_application do # transitions from: [:applicant, :initial_application_under_review], to: :initial_application_approved # end diff --git a/components/benefit_sponsors/spec/models/benefit_sponsors/benefit_sponsorships/benefit_sponsorship_spec.rb b/components/benefit_sponsors/spec/models/benefit_sponsors/benefit_sponsorships/benefit_sponsorship_spec.rb index 81679da17af..9a6badd8b9f 100644 --- a/components/benefit_sponsors/spec/models/benefit_sponsors/benefit_sponsorships/benefit_sponsorship_spec.rb +++ b/components/benefit_sponsors/spec/models/benefit_sponsors/benefit_sponsorships/benefit_sponsorship_spec.rb @@ -1286,6 +1286,20 @@ module BenefitSponsors it_behaves_like "for off-cycle employer", "active", "enrollment_ineligible", nil, false it_behaves_like "for off-cycle employer", "active", "terminated", "draft", true it_behaves_like "for off-cycle employer", "active", "termination_pending", "draft", true + + context 'employer has 1 draft and 2 expired applications after terminated application' do + let(:start_on) { TimeKeeper.date_of_record.beginning_of_month.prev_month } + let(:termination_date) { TimeKeeper.date_of_record.next_month.end_of_month } + let!(:renewal_effective_period) { termination_date.next_day..termination_date.next_day.next_year.prev_day } + let!(:effective_period) { start_on..termination_date } + let!(:term_application) { create(:benefit_sponsors_benefit_application, aasm_state: :termination_pending, effective_period: effective_period, benefit_sponsorship: active_benefit_sponsorship) } + let!(:canceled_app1) { create(:benefit_sponsors_benefit_application, aasm_state: :expired, effective_period: renewal_effective_period, benefit_sponsorship: active_benefit_sponsorship) } + let!(:canceled_app2) { create(:benefit_sponsors_benefit_application, aasm_state: :expired, effective_period: renewal_effective_period, benefit_sponsorship: active_benefit_sponsorship) } + let!(:draft_app) { create(:benefit_sponsors_benefit_application, aasm_state: :draft, effective_period: renewal_effective_period, benefit_sponsorship: active_benefit_sponsorship) } + + + it { expect(active_benefit_sponsorship.off_cycle_benefit_application).to eq draft_app } + end end end end