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
1 change: 0 additions & 1 deletion app/jobs/reports/api_transaction_count_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def perform(date = Time.zone.yesterday.end_of_day)
end

ReportMailer.tables_report(
title: 'API Transaction Count Report',
email: email_addresses,
subject: "API Transaction Count Report - #{report_date.to_date}",
reports: reports,
Expand Down
7 changes: 3 additions & 4 deletions lib/reporting/api_transaction_count_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def as_tables
def as_emailable_reports
[
Reporting::EmailableReport.new(
title: 'API Transaction Count Report',
subtitle: '',
float_as_percent: true,
precision: 2,
Expand Down Expand Up @@ -119,12 +118,12 @@ def fraud_score_and_attribute_table

def fetch_results(query:)
Rails.logger.info("Executing query: #{query}")
Rails.logger.info("Time range: #{time_range.begin.to_date} to #{time_range.end.to_date}")
Rails.logger.info("Time range: #{time_range.begin.to_time} to #{time_range.end.to_time}")

results = cloudwatch_client.fetch(
query:,
from: time_range.begin.to_date,
to: time_range.end.to_date,
from: time_range.begin.to_time,
to: time_range.end.to_time,
)

Rails.logger.info("Results: #{results.inspect}")
Expand Down
31 changes: 24 additions & 7 deletions spec/lib/reporting/api_transaction_count_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
let(:expected_api_transaction_count_table) do
[
['Week', 'True ID', 'Instant verify', 'Phone Finder', 'Socure (DocV)',
'Fraud Score and Attribute', 'Instant Verify', 'Threat Metrix'],
["#{time_range.begin.to_date} - #{time_range.end.to_date}", 10, 15, 20, 25, 30, 35, 40, 45],
'Fraud Score and Attribute', 'Threat Metrix'],
["#{time_range.begin.to_date} - #{time_range.end.to_date}", 10, 15, 20, 25, 30, 40],
]
end

subject(:report) { Reporting::ApiTransactionCountReport.new(time_range:) }
subject(:report) { described_class.new(time_range:) }

before do
allow_any_instance_of(Reporting::CloudwatchClient).to receive(:fetch).and_return(mock_results)
allow(report).to receive(:true_id_table).and_return([10, mock_results])
allow(report).to receive(:instant_verify_table).and_return([15, mock_results])
allow(report).to receive(:phone_finder_table).and_return([20, mock_results])
allow(report).to receive(:socure_table).and_return([25, mock_results])
allow(report).to receive(:fraud_score_and_attribute_table).and_return([30, mock_results])
allow(report).to receive(:threat_metrix_table).and_return([40, mock_results])
end

describe '#api_transaction_count' do
Expand All @@ -35,9 +41,12 @@
header_row = table.first
data_row = table.last

expect(header_row).to include('Week', 'True ID', 'Instant verify', 'Phone Finder')
expect(header_row).to eq(
['Week', 'True ID', 'Instant verify', 'Phone Finder', 'Socure (DocV)',
'Fraud Score and Attribute', 'Threat Metrix'],
)
expect(data_row.first).to eq("#{time_range.begin.to_date} - #{time_range.end.to_date}")
expect(data_row[1..].all? { |val| val.is_a?(Integer) || val.is_a?(Array) }).to be true
expect(data_row[1..]).to eq([10, 15, 20, 25, 30, 40])
end
end

Expand All @@ -49,7 +58,13 @@
expect(csvs.size).to eq(1)

csv = csvs.first
expect(csv).to include('Week,True ID,Instant verify')
expect(csv).to match(
/
Week,True\ ID,Instant\ verify,Phone\ Finder, # Match the first part
Socure\ \(DocV\),Fraud\ Score\ and\ Attribute, # Match the second part
Threat\ Metrix # Match the last part
/x,
)
expect(csv).to include("#{time_range.begin.to_date} - #{time_range.end.to_date}")
end
end
Expand All @@ -58,8 +73,10 @@
it 'returns a valid emailable report object' do
reports = report.as_emailable_reports

expect(reports).to be_an(Array)
expect(reports.first).to be_a(Reporting::EmailableReport)
expect(reports.first.title).to eq('API Transaction Count Report')
expect(reports.first.filename).to eq('api_transaction_count_report')
expect(reports.first.table).to eq(report.api_transaction_count)
end
end
end