Skip to content

Commit

Permalink
trigger notices report via rake and add spec for oeg/oeq script
Browse files Browse the repository at this point in the history
  • Loading branch information
saipraveen18 committed Aug 22, 2024
1 parent 27bb9a5 commit 6329dbb
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/tasks/generate_notices_report.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

desc "Task to generate notices report"
# Example rake command with start and end dates:
# rake generate_notices_report start_date="01/01/2021" end_date="01/31/2021"
task :generate_notices_report => :environment do
start_date = ENV['start_date'] || TimeKeeper.date_of_record.beginning_of_day
end_date = ENV['end_date'] || TimeKeeper.date_of_record.end_of_day

log "Beginning notices report process for #{start_date} to #{end_date}"

result = Operations::Reports::GenerateNoticesReport.new.call({start_date: start_date, end_date: end_date})

log "Notices report process completed with status: #{result.success? ? 'Success' : 'Failure'}"
end
1 change: 1 addition & 0 deletions script/oeg_oeq_notice_triggers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
oeg_enrollments = HbxEnrollment.individual_market.active.enrolled.current_year.where(:family_id.in=> oeg_family_ids).distinct(:family_id)
families = oeq_enrollments + oeg_enrollments

logger.info "Total number of families to trigger OEQ/OEG notices: #{families.size}"
families.each_with_index do |family_id, index|
family = Family.find_by(id: family_id)
next unless family.present?
Expand Down
91 changes: 91 additions & 0 deletions spec/script/oeg_oeq_notice_triggers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'OEQ & OEG notice triggers script', dbclean: :after_each do
before :all do
DatabaseCleaner.clean
end

let(:primary) { FactoryBot.create(:person, :with_consumer_role, :with_active_consumer_role) }
let(:family) { FactoryBot.create(:family, :with_primary_family_member, person: primary) }
let!(:application) do
FactoryBot.create(:financial_assistance_application,
family_id: family.id,
account_transferred: false,
transfer_requested: true,
assistance_year: TimeKeeper.date_of_record.next_year.year,
aasm_state: 'applicants_update_required',
hbx_id: "830293",
submitted_at: Date.yesterday,
created_at: Date.yesterday)
end
let!(:applicant) do
applicant = FactoryBot.create(:applicant,
first_name: primary.first_name,
last_name: primary.last_name,
dob: primary.dob,
gender: primary.gender,
application: application,
ethnicity: [])
applicant
end

let(:ivl_enrollment) do
FactoryBot.create(
:hbx_enrollment,
:individual_unassisted,
:with_product,
aasm_state: "coverage_selected",
effective_on: TimeKeeper.date_of_record.beginning_of_year,
household: family.households.first,
family: family,
coverage_kind: 'health'
)
end

let(:shop_enrollment) do
FactoryBot.create(
:hbx_enrollment,
:shop,
:with_product,
aasm_state: "coverage_enrolled",
effective_on: TimeKeeper.date_of_record.beginning_of_year,
household: family.households.first,
family: family,
coverage_kind: 'health'
)
end

before :each do
Dir.glob("#{Rails.root}/log/oeg_oeq_notice_triggers_*.log").each do |file|
FileUtils.rm(file)
end
end

context "IVL enrolled family" do
it 'triggers OEG/OEQ notice event' do
ivl_enrollment
load_script
log_file_path = "#{Rails.root}/log/oeg_oeq_notice_triggers_#{TimeKeeper.date_of_record.strftime('%Y_%m_%d')}.log"

expect(File.exist?(log_file_path)).to eq true
expect(File.read(log_file_path)).to include("Total number of families to trigger OEQ/OEG notices: 1")
end
end

context "Employer enrolled family" do
it 'triggers OEG/OEQ notice event' do
shop_enrollment
load_script
log_file_path = "#{Rails.root}/log/oeg_oeq_notice_triggers_#{TimeKeeper.date_of_record.strftime('%Y_%m_%d')}.log"

expect(File.exist?(log_file_path)).to eq true
expect(File.read(log_file_path)).to include("Total number of families to trigger OEQ/OEG notices: 0")
end
end

def load_script
load Rails.root.join('script/oeg_oeq_notice_triggers.rb')
end
end

0 comments on commit 6329dbb

Please sign in to comment.