Skip to content
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
14 changes: 7 additions & 7 deletions app/jobs/reports/monthly_account_reuse_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def perform(report_date)
@report_date = report_date

_latest, path = generate_s3_paths(REPORT_NAME, 'json', now: report_date)
body = report_body.to_json
body = report_body

if bucket_name.present?
upload_file_to_s3_bucket(
path: path,
body: body,
content_type: 'application/json',
content_type: 'text/csv',
bucket: bucket_name,
)
end
Expand Down Expand Up @@ -152,11 +152,11 @@ def report_csv
end

def report_body
{
report_date: first_day_of_report_month,
month: stats_month,
results: [report_csv],
}
CSV.generate do |csv|
report_csv.each do |row|
csv << row
end
end
end
end
end
34 changes: 17 additions & 17 deletions spec/jobs/reports/monthly_account_reuse_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
expect(report).to receive(:upload_file_to_s3_bucket).with(
path: s3_report_path,
body: kind_of(String),
content_type: 'application/json',
content_type: 'text/csv',
bucket: 'reports-bucket.1234-us-west-1',
).exactly(1).time.and_call_original

Expand Down Expand Up @@ -122,22 +122,22 @@ def create_identity(id, provider, verified_time)
it 'aggregates by issuer' do
expect(report).to receive(:upload_file_to_s3_bucket).
exactly(1).times do |path:, body:, content_type:, bucket:|
parsed = JSON.parse(body, symbolize_names: true)

expect(parsed[:report_date]).to eq(report_date.strftime('%Y-%m-01'))
expect(parsed[:month]).to eq(report_date.prev_month(1).strftime('%b-%Y'))
actual_csv = parsed[:results]
expected_csv = [
['IDV app reuse rate Feb-2021'],
['Num. SPs', 'Num. users', 'Percentage'],
[2, 3, 30.0],
[3, 2, 20.0],
['Total (all >1)', 5, 50.0],
[],
['Total proofed identities'],
['Total proofed identities (Feb-2021)', 10],
]
expect(actual_csv.first).to eq(expected_csv)
actual_csv = body # CSV.parse(body, headers: true)
expected_csv = CSV.generate do |csv|
[
['IDV app reuse rate Feb-2021'],
['Num. SPs', 'Num. users', 'Percentage'],
[2, 3, 30.0],
[3, 2, 20.0],
['Total (all >1)', 5, 50.0],
[],
['Total proofed identities'],
['Total proofed identities (Feb-2021)', 10],
].each do |row|
csv << row
end
end
expect(actual_csv).to eq(expected_csv)
end

report.perform(report_date)
Expand Down