Skip to content

Commit

Permalink
1853: Send weekly report to MA as well (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdooner authored Oct 16, 2024
1 parent 567857a commit 5d3e7a4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ NYC_PINWHEEL_ENVIRONMENT=sandbox
MA_PINWHEEL_ENVIRONMENT=sandbox
SANDBOX_PINWHEEL_ENVIRONMENT=sandbox
MAINTENANCE_MODE=false
MA_WEEKLY_REPORT_RECIPIENTS=[email protected]
23 changes: 17 additions & 6 deletions app/app/mailers/weekly_report_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion app/config/site-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion app/lib/tasks/weekly_reports.rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
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

WeeklyReportMailer
.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
22 changes: 20 additions & 2 deletions app/spec/mailers/weekly_report_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions infra/app/app-config/env-config/environment-variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
}
}

0 comments on commit 5d3e7a4

Please sign in to comment.