Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch valid aqhp enrollments tax households when selecting thh members #119

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading