From acd5cc4f9584bf2652a116381d7c03b082e0bae7 Mon Sep 17 00:00:00 2001 From: Saipraveen Gudimetla Date: Fri, 24 Nov 2023 16:30:43 -0500 Subject: [PATCH] fetch valid aqhp enrollments tax households when selecting thh members --- .../construct_cv3_payload.rb | 4 +- .../construct_cv3_payload_spec.rb | 66 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/app/operations/insurance_policies/aca_individuals/insurance_policies/construct_cv3_payload.rb b/app/operations/insurance_policies/aca_individuals/insurance_policies/construct_cv3_payload.rb index 8d695060..a71e8fc2 100644 --- a/app/operations/insurance_policies/aca_individuals/insurance_policies/construct_cv3_payload.rb +++ b/app/operations/insurance_policies/aca_individuals/insurance_policies/construct_cv3_payload.rb @@ -556,7 +556,9 @@ def fetch_thh_members_from_enr_thhs(enr_thhs, tax_household) return thh_members_from_enr_thhs if enr_thhs.present? && !tax_household.is_aqhp return tax_household.tax_household_members unless tax_household.is_aqhp - enr_thhs_for_month = enr_thhs.select { |enr_thh| valid_enrollment_tax_household?(enr_thh, tax_household) } + enr_thhs_for_month = enr_thhs.select do |enr_thh| + enr_thh.tax_household.is_aqhp && valid_enrollment_tax_household?(enr_thh, tax_household) + end enr_thhs_for_month&.flat_map(&:tax_household)&.flat_map(&:tax_household_members)&.uniq(&:person_id) || thh_members_from_enr_thhs diff --git a/spec/operations/insurance_policies/aca_individuals/insurance_policies/construct_cv3_payload_spec.rb b/spec/operations/insurance_policies/aca_individuals/insurance_policies/construct_cv3_payload_spec.rb index ea79e64a..b558e58d 100644 --- a/spec/operations/insurance_policies/aca_individuals/insurance_policies/construct_cv3_payload_spec.rb +++ b/spec/operations/insurance_policies/aca_individuals/insurance_policies/construct_cv3_payload_spec.rb @@ -390,4 +390,70 @@ expect(@result[:aptc_csr_tax_households].second[:covered_individuals][0][:coverage_end_on]).to eq enrollment_2.end_on end end + + context "fetch_thh_members_from_enr_thhs" do + let(:enrollment_1_subscriber) { FactoryBot.build(:enrolled_member, person: subscriber_person) } + let(:enrollment_1_dependents) { FactoryBot.build(:enrolled_member, person: dependent_person) } + + let!(:enrollment_1) do + FactoryBot.create(:enrollment, start_on: Date.new(year, 1, 1), + effectuated_on: Date.new(year, 1, 1), + created_at: Time.now, + insurance_policy: insurance_policy, + subscriber: enrollment_1_subscriber, + dependents: [enrollment_1_dependents]) + end + let!(:premium_schedule_1_enrollment_1) { FactoryBot.create(:premium_schedule, enrolled_member: enrollment_1.subscriber) } + let!(:premium_schedule_2_enrollment_1) do + FactoryBot.create(:premium_schedule, enrolled_member: enrollment_1.dependents.first) + end + let!(:aqhp_tax_household_1) { FactoryBot.create(:tax_household, is_aqhp: false) } + let!(:aqhp_tax_household_2) { FactoryBot.create(:tax_household, is_aqhp: true) } + let!(:aqhp_tax_household_3) { FactoryBot.create(:tax_household, is_aqhp: true) } + + let!(:uqp_thh_1_sub_tax_household_member) do + FactoryBot.create(:tax_household_member, tax_household: aqhp_tax_household_1, person: subscriber_person, + is_tax_filer: true) + end + let!(:uqhp_thh_1_dep_tax_household_member) do + FactoryBot.create(:tax_household_member, tax_household: aqhp_tax_household_1, person: dependent_person, + is_tax_filer: false) + end + + let!(:aqhp_thh_2_sub_tax_household_member) do + FactoryBot.create(:tax_household_member, tax_household: aqhp_tax_household_2, person: subscriber_person, + is_tax_filer: true) + end + + let!(:aqhp_thh_3_dep_tax_household_member) do + FactoryBot.create(:tax_household_member, tax_household: aqhp_tax_household_3, person: dependent_person, + is_tax_filer: true) + end + + let!(:uqhp_enrollment_tax_household_1) do + FactoryBot.create(:enrollments_tax_households, enrollment_id: enrollment_1.id, tax_household_id: aqhp_tax_household_1.id) + end + + let!(:aqhp_enrollment_tax_household_2) do + FactoryBot.create(:enrollments_tax_households, enrollment_id: enrollment_1.id, tax_household_id: aqhp_tax_household_2.id) + end + + let!(:aqhp_enrollment_tax_household_3) do + FactoryBot.create(:enrollments_tax_households, enrollment_id: enrollment_1.id, tax_household_id: aqhp_tax_household_3.id) + end + + before :each do + @result_call = subject.call({ insurance_policy: insurance_policy }) + @result = @result_call.value! + end + + it "should should publish the event" do + expect(@result_call.success?).to be_truthy + end + + it "should return correct members for each tax_household" do + expect(@result[:aptc_csr_tax_households].first[:covered_individuals].count).to eq 1 + expect(@result[:aptc_csr_tax_households].first[:covered_individuals].count).to eq 1 + end + end end