Skip to content

Commit

Permalink
WIP: submit on hidden field instead
Browse files Browse the repository at this point in the history
  • Loading branch information
embarnard committed Apr 22, 2024
1 parent 254c53c commit 1c4129d
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -430,6 +430,15 @@ def before_withdrawal_date_deadline?
end
helper_method :before_withdrawal_date_deadline?

def withdrawal_date_post_deadline
if params[:us_state] == 'ny'
app_time.in_time_zone('America/New_York')
else
app_time.in_time_zone('America/Phoenix')
end
end
helper_method :withdrawal_date_post_deadline

private

def locale
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/state_file/questions/taxes_owed_controller.rb
Expand Up @@ -34,9 +34,15 @@ def pay_mail_online_text
end
helper_method :pay_mail_online_text

#find where we initialize the form and pass it to the form through there

private

# def initialized_update_form
# form_class.new(current_resource, form_params)
# end
#instead of validating on the form we should just put the date in as a hidden param

def card_postscript; end

end
Expand Down
27 changes: 26 additions & 1 deletion app/forms/state_file/taxes_owed_form.rb
Expand Up @@ -37,7 +37,7 @@ def self.existing_attributes(intake)
private

def date_electronic_withdrawal
if app_time.before?(withdrawal_date_deadline)
if before_withdrawal_date_deadline?
parse_date_params(date_electronic_withdrawal_year, date_electronic_withdrawal_month, date_electronic_withdrawal_day)
else
if params[:us_state] == 'ny'
Expand Down Expand Up @@ -67,5 +67,30 @@ def withdrawal_date_before_deadline
self.errors.add(:date_electronic_withdrawal, I18n.t("forms.errors.taxes_owed.withdrawal_date_deadline", year: withdrawal_date_deadline.year))
end
end


def withdrawal_date_deadline
# binding.pry
case params[:us_state]
when 'ny'
Rails.configuration.state_file_withdrawal_date_deadline_ny
else
# Arizona's withdrawal date deadline is the same as the end-new-intakes date which is set in PDT,
# if this was during daylight-savings, it would be different except in the Navajo Nation
Rails.configuration.state_file_end_of_new_intakes
end
end

def before_withdrawal_date_deadline?
app_time < withdrawal_date_deadline
end

def app_time
if Rails.env.production?
Time.current
else
SessionToggle.new(session, 'app_time').value || Time.current
end
end
end
end
27 changes: 27 additions & 0 deletions app/helpers/application_time_helper.rb
@@ -0,0 +1,27 @@
module ApplicationTimeHelper
def app_time
if Rails.env.production?
Time.current
else
SessionToggle.new(session, 'app_time').value || Time.current
end
end


def withdrawal_date_deadline
# binding.pry
case params[:us_state]
when 'ny'
Rails.configuration.state_file_withdrawal_date_deadline_ny
else
# Arizona's withdrawal date deadline is the same as the end-new-intakes date which is set in PDT,
# if this was during daylight-savings, it would be different except in the Navajo Nation
Rails.configuration.state_file_end_of_new_intakes
end
end

def before_withdrawal_date_deadline?
app_time < withdrawal_date_deadline
end

end
20 changes: 19 additions & 1 deletion app/views/state_file/questions/tax_refund/_bank_details.html.erb
Expand Up @@ -2,8 +2,26 @@
<p class="spacing-below-0"><%= t(".bank_title") %></p>
<p class="text--small"><%= t(".foreign_accounts") %></p>
<div class="form-group-tight">
<% if owe_taxes && before_withdrawal_date_deadline? %>
<% if owe_taxes %>
<%= form.cfa_input_field(:withdraw_amount, t('.withdraw_amount', owed_amount: taxes_owed), classes: ["form-width--long"]) %>
<% if before_withdrawal_date_deadline? %>
# if its the time of transmission really we should be doing these checks when we submit
# could put hidden value, could overwrite it in the model, could do it when we transmit and bundle??
# hidden value and transmission?
<div class="date-select">
<% year = MultiTenantService.new(:statefile).current_tax_year + 1 %>
<%= form.cfa_date_select(
:date_electronic_withdrawal,
t(".date_withdraw_text"),
options: {
start_year: year,
end_year: year,
}
) %>
</div>
<% else %>
<%= form.hidden_field :date_electronic_withdrawal, value: withdrawal_date_post_deadline %>
<% end %>
<% end %>
<%= form.cfa_input_field(:bank_name, t("views.questions.bank_details.bank_name"), classes: ["form-width--long"]) %>
Expand Down
21 changes: 21 additions & 0 deletions spec/controllers/application_controller_spec.rb
Expand Up @@ -1408,6 +1408,27 @@ def index
end
end

describe "#withdrawal_date_deadline" do
let(:state) { "ny" }
before { @params = { us_state: state } }

context "for a New York return" do
it "returns the NY withdrawal date deadline" do
get :index, params: @params
expect(subject.withdrawal_date_deadline).to eq Rails.configuration.state_file_withdrawal_date_deadline_ny
end
end

context "for an Arizona return" do
let(:state) { "az" }

it "returns the AZ withdrawal date deadline" do
get :index, params: @params
expect(subject.withdrawal_date_deadline).to eq Rails.configuration.state_file_end_of_new_intakes
end
end
end

context "when receiving invalid requests from robots" do
before do
allow(DatadogApi).to receive(:increment)
Expand Down

0 comments on commit 1c4129d

Please sign in to comment.