Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearing bank details #187442420 #4502

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
13 changes: 0 additions & 13 deletions app/models/state_file_az_intake.rb
Expand Up @@ -104,19 +104,6 @@ class StateFileAzIntake < StateFileBaseIntake
enum eligibility_married_filing_separately: { unfilled: 0, yes: 1, no: 2 }, _prefix: :eligibility_married_filing_separately
enum eligibility_529_for_non_qual_expense: { unfilled: 0, yes: 1, no: 2 }, _prefix: :eligibility_529_for_non_qual_expense

before_save do
save_nil_enums_with_unfilled

if payment_or_deposit_type_changed?(to: "mail") || payment_or_deposit_type_changed?(to: "unfilled")
self.account_type = "unfilled"
self.bank_name = nil
self.routing_number = nil
self.account_number = nil
self.withdraw_amount = nil
self.date_electronic_withdrawal = nil
end
end

def state_code
STATE_CODE
end
Expand Down
13 changes: 13 additions & 0 deletions app/models/state_file_base_intake.rb
Expand Up @@ -41,6 +41,8 @@ class StateFileBaseIntake < ApplicationRecord
where.not(raw_direct_file_data: nil)
.where(federal_submission_id: nil)
}
before_save :save_nil_enums_with_unfilled
before_save :sanitize_bank_details

def direct_file_data
@direct_file_data ||= DirectFileData.new(raw_direct_file_data)
Expand Down Expand Up @@ -276,4 +278,15 @@ def self.opted_out_state_file_intakes(email)
end
state_intakes
end

def sanitize_bank_details
if (payment_or_deposit_type || "").to_sym != :direct_deposit
self.account_type = "unfilled"
self.bank_name = nil
self.routing_number = nil
self.account_number = nil
self.withdraw_amount = nil
self.date_electronic_withdrawal = nil
end
end
end
9 changes: 0 additions & 9 deletions app/models/state_file_ny_intake.rb
Expand Up @@ -157,7 +157,6 @@ class StateFileNyIntake < StateFileBaseIntake
enum confirmed_third_party_designee: { unfilled: 0, yes: 1, no: 2 }, _prefix: :confirmed_third_party_designee

before_save do
save_nil_enums_with_unfilled

if untaxed_out_of_state_purchases_changed?(to: "no") || untaxed_out_of_state_purchases_changed?(to: "unfilled")
self.sales_use_tax_calculation_method = "unfilled"
Expand All @@ -168,14 +167,6 @@ class StateFileNyIntake < StateFileBaseIntake
self.sales_use_tax = calculate_sales_use_tax
end

if payment_or_deposit_type_changed?(to: "mail") || payment_or_deposit_type_changed?(to: "unfilled")
self.account_type = "unfilled"
self.bank_name = nil
self.routing_number = nil
self.account_number = nil
self.withdraw_amount = nil
self.date_electronic_withdrawal = nil
end
end

def state_code
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/state_file_az_intakes.rb
Expand Up @@ -115,6 +115,7 @@
after(:build) do |intake, evaluator|
intake.direct_file_data.fed_agi = 10000
intake.raw_direct_file_data = intake.direct_file_data.to_s
intake.payment_or_deposit_type = "direct_deposit"
intake.account_type = "savings"
intake.routing_number = 111111111
intake.account_number = 222222222
Expand All @@ -125,6 +126,7 @@
after(:build) do |intake, evaluator|
intake.direct_file_data.fed_agi = 120000
intake.raw_direct_file_data = intake.direct_file_data.to_s
intake.payment_or_deposit_type = "direct_deposit"
intake.account_type = "checking"
intake.routing_number = 111111111
intake.account_number = 222222222
Expand Down
46 changes: 36 additions & 10 deletions spec/forms/state_file/tax_refund_form_spec.rb
Expand Up @@ -4,7 +4,13 @@
let!(:intake) { create :state_file_ny_intake, payment_or_deposit_type: "unfilled" }
let(:valid_params) do
{
payment_or_deposit_type: "mail"
payment_or_deposit_type: "mail",
routing_number: "019456124",
routing_number_confirmation: "019456124",
account_number: "12345",
account_number_confirmation: "12345",
account_type: "checking",
bank_name: "Bank official",
}
end

Expand All @@ -18,20 +24,15 @@
intake.reload
expect(intake.payment_or_deposit_type).to eq "mail"
expect(intake.account_type).to eq "unfilled"
expect(intake.account_number).to be_nil
expect(intake.routing_number).to be_nil
expect(intake.bank_name).to be_nil
end
end

context "when params valid and payment type is deposit" do
let(:valid_params) do
{
payment_or_deposit_type: "direct_deposit",
routing_number: "019456124",
routing_number_confirmation: "019456124",
account_number: "12345",
account_number_confirmation: "12345",
account_type: "checking",
bank_name: "Bank official",
}
super().merge(payment_or_deposit_type: "direct_deposit")
end

it "updates the intake" do
Expand All @@ -46,6 +47,31 @@
expect(intake.account_number).to eq "12345"
expect(intake.bank_name).to eq "Bank official"
end

context "when overwriting an existing intake" do
let!(:intake) do
create(
:state_file_ny_intake,
payment_or_deposit_type: "mail",
routing_number: "019456124",
account_number: "12345",
account_type: "checking",
bank_name: "Bank official"
)
end
it "updates the intake" do
form = described_class.new(intake, valid_params.merge(payment_or_deposit_type: "mail"))
expect(form).to be_valid
form.save

intake.reload
expect(intake.payment_or_deposit_type).to eq "mail"
expect(intake.account_type).to eq "unfilled"
expect(intake.account_number).to be_nil
expect(intake.routing_number).to be_nil
expect(intake.bank_name).to be_nil
end
end
end

context "when params are not valid" do
Expand Down
Expand Up @@ -150,7 +150,7 @@
end

context "when getting a refund to a personal checking account" do
let(:intake) { create(:state_file_ny_intake, filing_status: filing_status, routing_number: "011234567", account_number: "123456789", account_type: 1) }
let(:intake) { create(:state_file_ny_intake, filing_status: filing_status, payment_or_deposit_type: "direct_deposit", routing_number: "011234567", account_number: "123456789", account_type: 1) }
let(:filing_status) { 'single' }

it 'generates XML from the database models' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/state_file_az_intake_spec.rb
Expand Up @@ -118,8 +118,8 @@
expect {
intake.update(armed_forces_member: nil, account_type: nil, spouse_esigned_at: nil)
}.to change(intake, :armed_forces_member).to("unfilled")
.and change(intake, :account_type).to("unfilled")
.and change(intake, :spouse_esigned_at).to(nil)
expect(intake.account_type).to eq "unfilled"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/state_file_ny_intake_spec.rb
Expand Up @@ -165,7 +165,7 @@
expect {
intake.update(eligibility_yonkers: nil, account_type: nil)
}.to change(intake.reload, :eligibility_yonkers).to("unfilled")
.and change(intake.reload, :account_type).to("unfilled")
expect(intake.account_type).to eq "unfilled"
end
end
end
Expand Down