Skip to content

Commit

Permalink
Merge branch 'main' into wmg/2466-rename-pinwheel_end_user_id
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/db/schema.rb
#	docs/app/rendered/database-schema.pdf
  • Loading branch information
allthesignals committed Feb 27, 2025
2 parents 91963b6 + 1045804 commit c365c63
Show file tree
Hide file tree
Showing 29 changed files with 101 additions and 97 deletions.
2 changes: 1 addition & 1 deletion app/app/channels/paystubs_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def subscribed
private

def check_pinwheel_account_synchrony
pinwheel_account = PinwheelAccount.find_by_pinwheel_account_id(params["account_id"])
pinwheel_account = PayrollAccount.find_by_pinwheel_account_id(params["account_id"])

if pinwheel_account.present?
broadcast_to(@cbv_flow, {
Expand Down
2 changes: 1 addition & 1 deletion app/app/controllers/cbv/employer_searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Cbv::EmployerSearchesController < Cbv::BaseController
def show
@query = search_params[:query]
@employers = @query.blank? ? [] : provider_search(@query)
@has_pinwheel_account = @cbv_flow.pinwheel_accounts.any?
@has_pinwheel_account = @cbv_flow.payroll_accounts.any?
@selected_tab = search_params[:type] || "payroll"

case search_params[:type]
Expand Down
2 changes: 1 addition & 1 deletion app/app/controllers/cbv/missing_results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Cbv::MissingResultsController < Cbv::BaseController
before_action :track_missing_results_event, only: :show

def show
@has_pinwheel_account = @cbv_flow.pinwheel_accounts.any?
@has_pinwheel_account = @cbv_flow.payroll_accounts.any?
end

def track_missing_results_event
Expand Down
2 changes: 1 addition & 1 deletion app/app/controllers/cbv/payment_details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Cbv::PaymentDetailsController < Cbv::BaseController

def show
account_id = params[:user][:account_id]
@pinwheel_account = @cbv_flow.pinwheel_accounts.find_by(pinwheel_account_id: account_id)
@pinwheel_account = @cbv_flow.payroll_accounts.find_by(pinwheel_account_id: account_id)

# security check - make sure the account_id is associated with the current cbv_flow_id
if @pinwheel_account.nil?
Expand Down
8 changes: 4 additions & 4 deletions app/app/controllers/cbv/summaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def transmit_to_caseworker
employments: @employments,
incomes: @incomes,
identities: @identities,
payments_grouped_by_employer: summarize_by_employer(@payments, @employments, @incomes, @identities, @cbv_flow.pinwheel_accounts),
payments_grouped_by_employer: summarize_by_employer(@payments, @employments, @incomes, @identities, @cbv_flow.payroll_accounts),
has_consent: has_consent
}
)
Expand Down Expand Up @@ -164,7 +164,7 @@ def transmit_to_caseworker
end

def generate_csv
pinwheel_account = PinwheelAccount.find_by(cbv_flow_id: @cbv_flow.id)
pinwheel_account = PayrollAccount.find_by(cbv_flow_id: @cbv_flow.id)

data = {
client_id: @cbv_flow.cbv_applicant.agency_id_number,
Expand Down Expand Up @@ -195,7 +195,7 @@ def track_transmitted_event(cbv_flow, payments)
cbv_applicant_id: cbv_flow.cbv_applicant_id,
cbv_flow_id: cbv_flow.id,
invitation_id: cbv_flow.cbv_flow_invitation_id,
account_count: cbv_flow.pinwheel_accounts.count,
account_count: cbv_flow.payroll_accounts.count,
paystub_count: payments.count,
account_count_with_additional_information:
cbv_flow.additional_information.values.count { |info| info["comment"].present? },
Expand All @@ -213,7 +213,7 @@ def track_accessed_income_summary_event(cbv_flow, payments)
cbv_flow_id: cbv_flow.id,
cbv_applicant_id: cbv_flow.cbv_applicant_id,
invitation_id: cbv_flow.cbv_flow_invitation_id,
account_count: cbv_flow.pinwheel_accounts.count,
account_count: cbv_flow.payroll_accounts.count,
paystub_count: payments.count,
account_count_with_additional_information:
cbv_flow.additional_information.values.count { |info| info["comment"].present? },
Expand Down
2 changes: 1 addition & 1 deletion app/app/controllers/cbv/synchronizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def redirect_if_sync_finished
def set_pinwheel_account
account_id = params[:user][:account_id]

@pinwheel_account = @cbv_flow.pinwheel_accounts.find_by(pinwheel_account_id: account_id)
@pinwheel_account = @cbv_flow.payroll_accounts.find_by(pinwheel_account_id: account_id)
end
end
10 changes: 5 additions & 5 deletions app/app/controllers/webhooks/pinwheel/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ def create

if params["event"] == "account.added"
supported_jobs = get_supported_jobs(params["payload"]["platform_id"])
PinwheelAccount
PayrollAccount
.create_with(cbv_flow: @cbv_flow, supported_jobs: supported_jobs)
.find_or_create_by(pinwheel_account_id: params["payload"]["account_id"])
track_account_created_event(@cbv_flow, params["payload"]["platform_name"])
end

if PinwheelAccount::EVENTS_MAP.keys.include?(params["event"])
pinwheel_account = PinwheelAccount.find_by_pinwheel_account_id(params["payload"]["account_id"])
if PayrollAccount::EVENTS_MAP.keys.include?(params["event"])
pinwheel_account = PayrollAccount.find_by_pinwheel_account_id(params["payload"]["account_id"])

if pinwheel_account.present?
pinwheel_account.update!(PinwheelAccount::EVENTS_MAP[params["event"]] => Time.now)
pinwheel_account.update!(PayrollAccount::EVENTS_MAP[params["event"]] => Time.now)

if params.dig("payload", "outcome") == "error" || params.dig("payload", "outcome") == "pending"
pinwheel_account.update!(PinwheelAccount::EVENTS_ERRORS_MAP[params["event"]] => Time.now)
pinwheel_account.update!(PayrollAccount::EVENTS_ERRORS_MAP[params["event"]] => Time.now)
end

if pinwheel_account.has_fully_synced?
Expand Down
12 changes: 6 additions & 6 deletions app/app/helpers/cbv/pinwheel_data_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ def set_payments(account_id = nil)
end

def set_employments
@employments = @cbv_flow.pinwheel_accounts.map do |pinwheel_account|
@employments = @cbv_flow.payroll_accounts.map do |pinwheel_account|
next unless pinwheel_account.job_succeeded?("employment")

pinwheel.fetch_employment(account_id: pinwheel_account.pinwheel_account_id)
end.compact
end

def set_incomes
@incomes = @cbv_flow.pinwheel_accounts.map do |pinwheel_account|
@incomes = @cbv_flow.payroll_accounts.map do |pinwheel_account|
next unless pinwheel_account.job_succeeded?("income")

pinwheel.fetch_income(account_id: pinwheel_account.pinwheel_account_id)
end.compact
end

def set_identities
@identities = @cbv_flow.pinwheel_accounts.map do |pinwheel_account|
@identities = @cbv_flow.payroll_accounts.map do |pinwheel_account|
next unless pinwheel_account.job_succeeded?("identity")

pinwheel.fetch_identity(account_id: pinwheel_account.pinwheel_account_id)
Expand All @@ -43,7 +43,7 @@ def hours_by_earning_category(earnings)
end

def payments_grouped_by_employer
summarize_by_employer(@payments, @employments, @incomes, @identities, @cbv_flow.pinwheel_accounts)
summarize_by_employer(@payments, @employments, @incomes, @identities, @cbv_flow.payroll_accounts)
end

def total_gross_income
Expand Down Expand Up @@ -74,7 +74,7 @@ def summarize_by_employer(payments, employments, incomes, identities, pinwheel_a
private

def fetch_paystubs(from_pay_date, to_pay_date)
@cbv_flow.pinwheel_accounts.flat_map do |pinwheel_account|
@cbv_flow.payroll_accounts.flat_map do |pinwheel_account|
next [] unless pinwheel_account.job_succeeded?("paystubs")

fetch_paystubs_for_account_id(pinwheel_account.pinwheel_account_id, from_pay_date, to_pay_date)
Expand All @@ -90,7 +90,7 @@ def fetch_paystubs_for_account_id(account_id, from_pay_date, to_pay_date)
end

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

pinwheel_account.job_succeeded?(job)
Expand Down
3 changes: 1 addition & 2 deletions app/app/javascript/utilities/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ export const trackUserAction = async (eventName, attributes) => {
}).then(response => response.json());
}


export const fetchToken = (response_type, id, locale) => {
return fetchInternal(PINWHEEL_TOKENS_GENERATE, {
method: 'post',
body: JSON.stringify({ response_type, id, locale }),
})
};
};
4 changes: 2 additions & 2 deletions app/app/models/cbv_flow.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class CbvFlow < ApplicationRecord
has_many :pinwheel_accounts, dependent: :destroy
has_many :payroll_accounts, dependent: :destroy
belongs_to :cbv_flow_invitation, optional: true
belongs_to :cbv_applicant, optional: true
validates :client_agency_id, inclusion: Rails.application.config.client_agencies.client_agency_ids
Expand Down Expand Up @@ -28,6 +28,6 @@ def self.create_from_invitation(cbv_flow_invitation)
end

def has_account_with_required_data?
pinwheel_accounts.any?(&:has_required_data?)
payroll_accounts.any?(&:has_required_data?)
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class PinwheelAccount < ApplicationRecord
class PayrollAccount < ApplicationRecord
belongs_to :cbv_flow

after_update_commit {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenamePinwheelAccountsTable < ActiveRecord::Migration[7.1]
def change
rename_table :pinwheel_accounts, :payroll_accounts
end
end
8 changes: 4 additions & 4 deletions app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2025_02_26_205049) do
ActiveRecord::Schema[7.1].define(version: 2025_02_27_162123) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -80,7 +80,7 @@
t.index ["cbv_flow_invitation_id"], name: "index_cbv_flows_on_cbv_flow_invitation_id"
end

create_table "pinwheel_accounts", force: :cascade do |t|
create_table "payroll_accounts", force: :cascade do |t|
t.bigint "cbv_flow_id", null: false
t.string "pinwheel_account_id"
t.datetime "paystubs_synced_at", precision: nil
Expand All @@ -94,7 +94,7 @@
t.datetime "paystubs_errored_at", precision: nil
t.datetime "identity_errored_at", precision: nil
t.datetime "identity_synced_at", precision: nil
t.index ["cbv_flow_id"], name: "index_pinwheel_accounts_on_cbv_flow_id"
t.index ["cbv_flow_id"], name: "index_payroll_accounts_on_cbv_flow_id"
end

create_table "users", force: :cascade do |t|
Expand All @@ -119,5 +119,5 @@

add_foreign_key "cbv_flow_invitations", "users"
add_foreign_key "cbv_flows", "cbv_flow_invitations"
add_foreign_key "pinwheel_accounts", "cbv_flows"
add_foreign_key "payroll_accounts", "cbv_flows"
end
6 changes: 3 additions & 3 deletions app/spec/controllers/cbv/employer_searches_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@

render_views

context "when the user at least one pinwheel_account associated with their cbv_flow" do
context "when the user at least one payroll_account associated with their cbv_flow" do
it "renders the view with a link to the summary page" do
create(:pinwheel_account, cbv_flow_id: cbv_flow.id)
create(:payroll_account, cbv_flow_id: cbv_flow.id)
get :show, params: { query: "no_results" }
expect(response).to be_successful
expect(response.body).to include("continue to review your income report")
expect(response.body).to include("Review my income report")
end
end

context "when the user has does not have a pinwheel_account associated with their cbv_flow" do
context "when the user has does not have a payroll_account associated with their cbv_flow" do
it "renders the view with a link to exit income verification" do
get :show, params: { query: "no_results" }
expect(response).to be_successful
Expand Down
2 changes: 1 addition & 1 deletion app/spec/controllers/cbv/entries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
existing_cbv_flow.update(confirmation_code: "FOOBAR")
end
let!(:connected_account) do
create(:pinwheel_account,
create(:payroll_account,
cbv_flow: existing_cbv_flow,
pinwheel_account_id: SecureRandom.uuid,
created_at: 4.minutes.ago
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end

context "when the user has already linked a pinwheel account" do
let!(:pinwheel_account) { create(:pinwheel_account, cbv_flow: cbv_flow) }
let!(:payroll_account) { create(:payroll_account, cbv_flow: cbv_flow) }

it "renders successfully" do
get :show
Expand Down
12 changes: 6 additions & 6 deletions app/spec/controllers/cbv/payment_details_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
let(:income_errored_at) { nil }
let(:paystubs_errored_at) { nil }
let(:employment_errored_at) { nil }
let!(:pinwheel_account) do
let!(:payroll_account) do
create(
:pinwheel_account,
:payroll_account,
cbv_flow: cbv_flow,
pinwheel_account_id: account_id,
supported_jobs: supported_jobs,
Expand Down Expand Up @@ -45,7 +45,7 @@
.with("ApplicantViewedPaymentDetails", anything, hash_including(
cbv_flow_id: cbv_flow.id,
invitation_id: cbv_flow.cbv_flow_invitation_id,
pinwheel_account_id: pinwheel_account.id,
pinwheel_account_id: payroll_account.id,
payments_length: 1,
has_employment_data: true,
has_paystubs_data: true,
Expand All @@ -57,7 +57,7 @@
.with("ApplicantViewedPaymentDetails", anything, hash_including(
cbv_flow_id: cbv_flow.id,
invitation_id: cbv_flow.cbv_flow_invitation_id,
pinwheel_account_id: pinwheel_account.id,
pinwheel_account_id: payroll_account.id,
payments_length: 1,
has_employment_data: true,
has_paystubs_data: true,
Expand Down Expand Up @@ -197,8 +197,8 @@
end

it "redirects to the entry page when the resolved pinwheel_account is present, but does not match the current session" do
existing_pinwheel_account = create(:pinwheel_account)
get :show, params: { user: { account_id: existing_pinwheel_account.pinwheel_account_id } }
existing_payroll_account = create(:payroll_account)
get :show, params: { user: { account_id: existing_payroll_account.pinwheel_account_id } }
expect(response).to redirect_to(cbv_flow_entry_url)
expect(flash[:slim_alert]).to be_present
expect(flash[:slim_alert][:message]).to eq(I18n.t("cbv.error_no_access"))
Expand Down
2 changes: 1 addition & 1 deletion app/spec/controllers/cbv/summaries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"public_key" => @public_key
})

cbv_flow.pinwheel_accounts.first.update(pinwheel_account_id: "03e29160-f7e7-4a28-b2d8-813640e030d3")
cbv_flow.payroll_accounts.first.update(pinwheel_account_id: "03e29160-f7e7-4a28-b2d8-813640e030d3")
end

around do |ex|
Expand Down
6 changes: 3 additions & 3 deletions app/spec/controllers/cbv/synchronization_failures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
end

context "when the user has already linked a pinwheel account" do
let!(:pinwheel_account) { create(:pinwheel_account, cbv_flow: cbv_flow) }
let!(:payroll_account) { create(:payroll_account, cbv_flow: cbv_flow) }

it "shows continue to report button" do
get :show
expect(response.body).to include I18n.t("cbv.synchronization_failures.show.continue_to_report")
end
end

context "when the user has no successful pinwheel_accounts" do
let!(:pinwheel_account) { create(:pinwheel_account, :with_paystubs_errored, cbv_flow: cbv_flow) }
context "when the user has no successful payroll_accounts" do
let!(:payroll_account) { create(:payroll_account, :with_paystubs_errored, cbv_flow: cbv_flow) }

it "shows cta button" do
get :show
Expand Down
10 changes: 5 additions & 5 deletions app/spec/controllers/cbv/synchronizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@

let(:cbv_flow) { create(:cbv_flow) }

let(:pinwheel_account) { create(:pinwheel_account, cbv_flow: cbv_flow) }
let(:payroll_account) { create(:payroll_account, cbv_flow: cbv_flow) }

before do
session[:cbv_flow_id] = cbv_flow.id
end

describe "#update" do
it "redirects to the payment details page" do
patch :update, params: { user: { account_id: pinwheel_account.pinwheel_account_id } }
patch :update, params: { user: { account_id: payroll_account.pinwheel_account_id } }

expect(response).to redirect_to(cbv_flow_payment_details_path(user: { account_id: pinwheel_account.pinwheel_account_id }))
expect(response).to redirect_to(cbv_flow_payment_details_path(user: { account_id: payroll_account.pinwheel_account_id }))
end

context "when the paystubs synchronization fails" do
it "redirects to the synchronization failures page" do
pinwheel_account = create(:pinwheel_account, :with_paystubs_errored, cbv_flow: cbv_flow)
payroll_account = create(:payroll_account, :with_paystubs_errored, cbv_flow: cbv_flow)

patch :update, params: { user: { account_id: pinwheel_account.pinwheel_account_id } }
patch :update, params: { user: { account_id: payroll_account.pinwheel_account_id } }

expect(response).to redirect_to(cbv_flow_synchronization_failures_path)
end
Expand Down
Loading

0 comments on commit c365c63

Please sign in to comment.