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
15 changes: 13 additions & 2 deletions app/jobs/reports/duplicate_ssn_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,40 @@ def report_body

profiles_connected_by_ssn.sort_by!(&:id).reverse!

count_by_ssn = profiles_connected_by_ssn.group_by(&:ssn_signature).transform_values(&:count)
count_by_ssn = profiles_connected_by_ssn.
group_by(&:ssn_signature).
transform_values(&:count)
count_by_ssn_active = profiles_connected_by_ssn.
select(&:active?).
group_by(&:ssn_signature).
transform_values(&:count)

CSV.generate do |csv|
csv << %w[
new_account
uuid
account_created_at
identity_verified_at
profile_active
ssn_fingerprint
count_ssn_fingerprint
count_active_ssn_fingerprint
]

profiles_connected_by_ssn.each do |profile|
ssn_count = count_by_ssn[profile.ssn_signature]
ssn_count_active = count_by_ssn_active[profile.ssn_signature]
next if ssn_count < 2

csv << [
todays_profile_ids.include?(profile.id),
profile.user.uuid,
profile.user.created_at.in_time_zone('UTC').iso8601,
profile.activated_at.in_time_zone('UTC').iso8601,
profile.activated_at&.in_time_zone('UTC')&.iso8601,
profile.active,
profile.ssn_signature,
ssn_count,
ssn_count_active,
]
end
end
Expand Down
20 changes: 15 additions & 5 deletions spec/jobs/reports/duplicate_ssn_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@
end

let!(:fingerprint2_previous_profiles) do
2.times.map do
[
create(
:profile,
:active,
active: false,
ssn_signature: ssn_fingerprint2,
activated_at: report_date - 10.days,
).tap(&:reload)
end
),
create(
:profile,
active: false,
ssn_signature: ssn_fingerprint2,
activated_at: nil,
),
].map(&:reload)
end

it 'creates csv with corresponding data', aggregate_failures: true do
Expand Down Expand Up @@ -83,9 +89,13 @@ def expect_row_matches_profile(row:, profile:)
expect(row).to be
expect(row['uuid']).to eq(profile.user.uuid)
expect(Time.zone.parse(row['account_created_at']).to_i).to eq(profile.user.created_at.to_i)
expect(Time.zone.parse(row['identity_verified_at']).to_i).to eq(profile.activated_at.to_i)
if profile.activated_at
expect(Time.zone.parse(row['identity_verified_at']).to_i).to eq(profile.activated_at.to_i)
end
expect(row['profile_active']).to eq(profile.active.to_s)
expect(row['ssn_fingerprint']).to eq(ssn_fingerprint2)
expect(row['count_ssn_fingerprint']).to eq('3')
expect(row['count_active_ssn_fingerprint']).to eq('1')
end
end
end
Expand Down