Skip to content

Commit

Permalink
Support for failed or unsupported jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
allthesignals committed Aug 22, 2024
1 parent 3bce642 commit 2eee81c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
13 changes: 11 additions & 2 deletions app/app/controllers/concerns/cbv/reports_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def summarize_by_employer(payments, employments, incomes)
payments: [],
has_income_data: has_income_data,
has_employment_data: has_employment_data,
employment: employments.find { |employment| employment["account_id"] == account_id },
income: incomes.find { |income| income["account_id"] == account_id }
income: has_income_data && incomes.find { |income| income["account_id"] == account_id },
employment: has_employment_data && employments.find { |employment| employment["account_id"] == account_id }
}
hash[account_id][:total] += payment[:gross_pay_amount]
hash[account_id][:payments] << payment
Expand All @@ -44,6 +44,7 @@ def summarize_by_employer(payments, employments, incomes)

def fetch_employments
fetch_end_user_account_ids.map do |account_id|
return [] unless does_pinwheel_account_support_job?(account_id, "employment")
fetch_employments_for_account_id account_id
end.flatten
end
Expand All @@ -54,11 +55,19 @@ def fetch_employments_for_account_id(account_id)

def fetch_incomes
fetch_end_user_account_ids.map do |account_id|
return [] unless does_pinwheel_account_support_job?(account_id, "income")
fetch_incomes_for_account_id account_id
end.flatten
end

def fetch_incomes_for_account_id(account_id)
pinwheel.fetch_income_metadata(account_id: account_id)["data"]
end

def does_pinwheel_account_support_job?(account_id, job)
pinwheel_account = PinwheelAccount.find_by_pinwheel_account_id(account_id)
return false unless pinwheel_account

pinwheel_account.supported_jobs.include?(job)
end
end
18 changes: 10 additions & 8 deletions app/app/views/cbv/summaries/show.pdf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@

<% if @payments.any? %>
<% payments_grouped_by_employer.each_with_index do |(account_id, summary), index| %>
<h3><%= t(".table_caption_no_name", number: index + 1) %>: <%= summary[:employment]["employer_name"] %></h3>
<h3><%= t(".table_caption_no_name", number: index + 1) %>: <%= summary[:employer_name] %></h3>

<%= render(TableComponent.new) do |table| %>
<%= table.with_header do %>
<h3 class="margin-0"><%= summary[:employment]["employer_name"] %> Employment Information</h3>
<h3 class="margin-0"><%= summary[:employer_name] %> Employment Information</h3>
<% end %>
<% if summary[:has_employment_data] %>
<%= table.with_data_point(:employer_phone, summary[:employment]["employer_phone_number"]["value"]) %>
<%= table.with_data_point(:employer_address, summary[:employment]["employer_address"]["raw"]) %>
<%= table.with_data_point(:employment_status, summary[:employment]["status"]) %>
<%= table.with_data_point(:employment_start_date, summary[:employment]["start_date"]) %>
<%= table.with_data_point(:employment_end_date, summary[:employment]["termination_date"]) %>
<% end %>
<%= table.with_data_point(:employer_phone, summary[:employment]["employer_phone_number"]["value"]) %>
<%= table.with_data_point(:employer_address, summary[:employment]["employer_address"]["raw"]) %>
<%= table.with_data_point(:employment_status, summary[:employment]["status"]) %>
<%= table.with_data_point(:employment_start_date, summary[:employment]["start_date"]) %>
<%= table.with_data_point(:employment_end_date, summary[:employment]["termination_date"]) %>
<% if summary[:has_income_data] %>
<%= table.with_data_point(:pay_frequency, summary[:income]["pay_frequency"]&.humanize) %>
<%= table.with_data_point(:hourly_rate, summary[:income]["compensation_amount"], summary[:income]["compensation_unit"]) %>
Expand All @@ -52,7 +54,7 @@
<% summary[:payments].each do |payment| %>
<%= render(TableComponent.new) do |table| %>
<%= table.with_header do %>
<h3 class="margin-0"><%= summary[:employment]["employer_name"] %> Pay Date: <%= format_date(payment[:pay_date]) %></h3>
<h3 class="margin-0"><%= summary[:employer_name] %> Pay Date: <%= format_date(payment[:pay_date]) %></h3>
<% end %>
<%= table.with_data_point(:pay_period, payment[:start], payment[:end]) %>
<%= table.with_data_point(:pay_gross, payment[:gross_pay_amount]) %>
Expand Down
15 changes: 13 additions & 2 deletions app/spec/controllers/cbv/summaries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
RSpec.describe Cbv::SummariesController do
include PinwheelApiHelper

let(:cbv_flow) { create(:cbv_flow, :with_pinwheel_account, case_number: "ABC1234") }
let(:supported_jobs) { %w[income paystubs employment] }
let(:cbv_flow) { create(:cbv_flow, :with_pinwheel_account, case_number: "ABC1234", supported_jobs: supported_jobs) }
let(:cbv_flow_invitation) { cbv_flow.cbv_flow_invitation }

before do
Expand All @@ -19,7 +20,7 @@
stub_request_end_user_accounts_response
stub_request_end_user_paystubs_response
stub_request_employment_info_response
stub_request_income_metadata_response
stub_request_income_metadata_response if supported_jobs.include?("income")
end

context "when rendering views" do
Expand All @@ -43,6 +44,16 @@
expect(response).to be_successful
expect(response.header['Content-Type']).to include 'pdf'
end

context "when only paystubs are supported" do
let(:supported_jobs) { %w[paystubs] }

it "renders pdf properly" do
get :show, format: :pdf
expect(response).to be_successful
expect(response.header['Content-Type']).to include 'pdf'
end
end
end

context "when legal agreement checked" do
Expand Down
4 changes: 2 additions & 2 deletions app/spec/controllers/concerns/cbv/reports_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
net_pay_amount: 321609
}
],
has_income_data: false,
has_employment_data: false,
has_income_data: true,
has_employment_data: true,
employment: employments,
income: incomes,
total: 480720
Expand Down
8 changes: 7 additions & 1 deletion app/spec/factories/cbv_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
cbv_flow_invitation

trait :with_pinwheel_account do
pinwheel_accounts { [ create(:pinwheel_account) ] }
transient do
supported_jobs { %w[income paystubs employment] }
end

after(:build) do |cbv_flow, evaluator|
cbv_flow.pinwheel_accounts = [ create(:pinwheel_account, supported_jobs: evaluator.supported_jobs) ]
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"direct_deposit_allocations": "2021-01-08T00:00:00.000000+00:00"
},
"end_user_id": "my_user_12345",
"id": "eb240ec6-a227-47ca-b7c7-fbbdfe7170a0",
"id": "03e29160-f7e7-4a28-b2d8-813640e030d3",
"link_token_id": "bd2c09e7-1303-46d5-87c0-0ffa572d7ae4",
"monitoring_status": "active",
"platform_id": "fce3eee0-285b-496f-9b36-30e976194736"
Expand Down

0 comments on commit 2eee81c

Please sign in to comment.