diff --git a/app/.env b/app/.env index a4221cdc..b73b805a 100644 --- a/app/.env +++ b/app/.env @@ -10,3 +10,4 @@ NYC_PINWHEEL_ENVIRONMENT=sandbox MA_PINWHEEL_ENVIRONMENT=sandbox SANDBOX_PINWHEEL_ENVIRONMENT=sandbox MAINTENANCE_MODE=false +MA_WEEKLY_REPORT_RECIPIENTS=test@email.com diff --git a/app/app/mailers/weekly_report_mailer.rb b/app/app/mailers/weekly_report_mailer.rb index c46895ce..2a5c0a7a 100644 --- a/app/app/mailers/weekly_report_mailer.rb +++ b/app/app/mailers/weekly_report_mailer.rb @@ -37,14 +37,25 @@ def weekly_report_data(current_site, report_range) .map do |invitation| cbv_flow = invitation.cbv_flows.find(&:complete?) - { - client_id_number: invitation.client_id_number, - transmitted_at: cbv_flow&.transmitted_at, - case_number: invitation.case_number, + base_fields = { invited_at: invitation.created_at, - snap_application_date: invitation.snap_application_date, - completed_at: cbv_flow&.consented_to_authorized_use_at + transmitted_at: cbv_flow&.transmitted_at, + completed_at: cbv_flow&.consented_to_authorized_use_at, + snap_application_date: invitation.snap_application_date } + + case current_site.id + when "nyc" + base_fields.merge( + client_id_number: invitation.client_id_number, + case_number: invitation.case_number, + ) + when "ma" + base_fields.merge( + agency_id_number: invitation.agency_id_number, + beacon_id: invitation.beacon_id + ) + end end end diff --git a/app/config/site-config.yml b/app/config/site-config.yml index 3fb7ed44..38d9d9e4 100644 --- a/app/config/site-config.yml +++ b/app/config/site-config.yml @@ -42,7 +42,8 @@ invitation_valid_days: 14 logo_path: dta_logo.png logo_square_path: dta_logo_square.png - weekly_report: {} + weekly_report: + recipient: <%= ENV['MA_WEEKLY_REPORT_RECIPIENTS'] %> - id: sandbox agency_name: CBV Test Agency agency_short_name: CBV diff --git a/app/lib/tasks/weekly_reports.rake b/app/lib/tasks/weekly_reports.rake index cb8e92e7..69e9545f 100644 --- a/app/lib/tasks/weekly_reports.rake +++ b/app/lib/tasks/weekly_reports.rake @@ -1,5 +1,5 @@ namespace :weekly_reports do - desc "Send weekly reports (NYC and later others?)" + desc "Send weekly reports (NYC and MA)" task send_all: :environment do report_date = Time.now.in_time_zone("America/New_York").beginning_of_week @@ -7,5 +7,10 @@ namespace :weekly_reports do .with(site_id: "nyc", report_date: report_date.to_date) .report_email .deliver_now + + WeeklyReportMailer + .with(site_id: "ma", report_date: report_date.to_date) + .report_email + .deliver_now end end diff --git a/app/spec/mailers/weekly_report_mailer_spec.rb b/app/spec/mailers/weekly_report_mailer_spec.rb index 97c90830..b15bf3f0 100644 --- a/app/spec/mailers/weekly_report_mailer_spec.rb +++ b/app/spec/mailers/weekly_report_mailer_spec.rb @@ -10,10 +10,9 @@ let(:snap_app_date) { now.strftime("%Y-%m-%d") } let(:cbv_flow_invitation) do create(:cbv_flow_invitation, - :nyc, + site_id.to_sym, created_at: invitation_sent_at, snap_application_date: invitation_sent_at - 1.day, - site_id: site_id ) end let(:cbv_flow) do @@ -115,4 +114,23 @@ )) end end + + context "for the MA site" do + let(:site_id) { "ma" } + + it "renders the CSV data with MA-specific columns" do + expect(mail.attachments.first.filename).to eq("weekly_report_20240902-20240908.csv") + expect(mail.attachments.first.content_type).to start_with('text/csv') + + expect(parsed_csv[0]).to match( + "beacon_id" => cbv_flow_invitation.beacon_id, + "transmitted_at" => "2024-09-04 13:30:00 UTC", + "agency_id_number" => cbv_flow_invitation.agency_id_number, + "invited_at" => "2024-09-04 13:00:00 UTC", + "snap_application_date" => "2024-09-03", + "completed_at" => "2024-09-04 13:30:00 UTC", + ) + expect(parsed_csv.length).to eq(1) + end + end end diff --git a/infra/app/app-config/env-config/environment-variables.tf b/infra/app/app-config/env-config/environment-variables.tf index 7f9a8a5c..7929ff8e 100644 --- a/infra/app/app-config/env-config/environment-variables.tf +++ b/infra/app/app-config/env-config/environment-variables.tf @@ -147,5 +147,9 @@ locals { manage_method = "manual" secret_store_name = "/service/${var.app_name}-${var.environment}/ma-dta-s3-public-key" }, + MA_WEEKLY_REPORT_RECIPIENTS = { + manage_method = "manual" + secret_store_name = "/service/${var.app_name}-${var.environment}/ma-weekly-report-recipients" + }, } }