Skip to content

Commit

Permalink
Changes to return-status page, efile-error form and hub/efile-submiss…
Browse files Browse the repository at this point in the history
…ions (#4382)
  • Loading branch information
embarnard authored Mar 25, 2024
1 parent 636bfe9 commit ae00b01
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 61 deletions.
11 changes: 10 additions & 1 deletion app/controllers/hub/efile_submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def failed

authorize! :update, @efile_submission
@efile_submission.transition_to!(:failed, { initiated_by_id: current_user.id })
flash[:notice] = "Transition to failed (for testing purpose only)"
flash[:notice] = "Transitioned to failed (for testing purpose only)"
redirect_after_action
end

Expand All @@ -52,6 +52,15 @@ def cancel
redirect_after_action
end

def reject
return if Rails.env.production?

authorize! :update, @efile_submission
@efile_submission.transition_to!(:rejected, error_code: EfileError.where(service_type: :state_file).last.code)
flash[:notice] = "Transitioned to rejected (for testing purpose only)"
redirect_after_action
end

def investigate
authorize! :update, @efile_submission
@efile_submission.transition_to!(:investigating, { initiated_by_id: current_user.id })
Expand Down
7 changes: 6 additions & 1 deletion app/state_machines/efile_submission_state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EfileSubmissionStateMachine
transition from: :queued, to: [:transmitted, :failed]
transition from: :transmitted, to: [:accepted, :rejected, :failed, :ready_for_ack, :transmitted, :notified_of_rejection]
transition from: :ready_for_ack, to: [:accepted, :rejected, :failed, :ready_for_ack, :notified_of_rejection]
transition from: :failed, to: [:resubmitted, :cancelled, :investigating, :waiting, :fraud_hold]
transition from: :failed, to: [:resubmitted, :cancelled, :investigating, :waiting, :fraud_hold, :rejected]
transition from: :rejected, to: [:resubmitted, :cancelled, :investigating, :waiting, :fraud_hold, :notified_of_rejection]
transition from: :notified_of_rejection, to: [:resubmitted, :cancelled, :investigating, :waiting, :fraud_hold]
transition from: :investigating, to: [:resubmitted, :cancelled, :waiting, :fraud_hold]
Expand All @@ -46,6 +46,11 @@ class EfileSubmissionStateMachine
submission.is_for_state_filing? || submission.fraud_score.present?
end

guard_transition(from: :failed, to: :rejected) do |_submission|
# we need this for testing since submissions will fail on bundle in heroku and staging
!Rails.env.production?
end

after_transition(to: :preparing) do |submission|
submission.create_qualifying_dependents
if submission.is_for_federal_filing?
Expand Down
39 changes: 29 additions & 10 deletions app/views/hub/state_file/efile_errors/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,51 @@
<hr/>
<h2>Options</h2>
<%= form_with model: @efile_error, method: :put, local: true, url: hub_state_file_efile_error_path, builder: VitaMinFormBuilder do |f| %>
<%= f.hub_checkbox :expose, "Exposed to client? (exposes reject code and description on return-status page)" %>
<%= f.hub_checkbox :auto_cancel, "Auto-cancel?" %>
<%= f.hub_checkbox :auto_wait, "Auto-wait? (shows terminal reject state on return-status page)" %>
<div>
<%= f.label "Correction Path" %><br />
<span class="tooltip" data-position="right" title="will expose the error code, error-message/custom-description and custom-resolution (if present) on the /return-status page">
<%= f.hub_checkbox :expose, "Exposed to client?" %>
</span>
</div>

<div>
<span class="tooltip" data-position="right" title="shows 'what can I do next' or custom resolution text on /return-status page">
<%= f.hub_checkbox :auto_cancel, "Auto-cancel?" %>
</span>
</div>

<div>
<span class="tooltip" data-position="right" title="will allow the client to resubmit their return">
<%= f.hub_checkbox :auto_wait, "Auto-wait?" %>
</span>
</div>

<div>
<%= f.label "Correction Path", class: "h4" %>
<p class="help-text">directs clients to path when resubmitting</p>
<%= f.select :correction_path, @correction_path_options_for_select, selected: @efile_error.correction_path %>
</div>

<div class="spacing-above-25">
<%= f.label :description_en, "Description [English] (overwrites default reject description on return-status page)", class: "h4" %>
<%= f.label :description_en, "English Description", class: "h4" %>
<p class="help-text">overwrites default English reject-description on <em>/return-status</em> if exposed</p>
<%= f.rich_text_area :description_en %>
</div>

<div class="spacing-above-25">
<%= f.label :description_es, "Description [Spanish]", class: "h4" %>
<%= f.label :description_es, "Spanish Description", class: "h4" %>
<p class="help-text">overwrites default Spanish reject-description on <em>/return-status</em> if exposed</p>
<%= f.rich_text_area :description_es %>
</div>


<div class="spacing-above-25">
<%= f.label :resolution_en, "Resolution [English] (overwrites default 'what's next' message on return-status page)", class: "h4" %>
<%= f.label :resolution_en, "English Resolution", class: "h4" %>
<p class="help-text">overwrites default English next-steps message on <em>/return-status</em></p>
<%= f.rich_text_area :resolution_en %>
</div>


<div class="spacing-above-25">
<%= f.label :resolution_es, "Resolution [Spanish]", class: "h4" %>
<%= f.label :resolution_es, "Spanish Resolution", class: "h4" %>
<p class="help-text">overwrites default Spanish next-steps message on <em>/return-status</em></p>
<%= f.rich_text_area :resolution_es %>
</div>

Expand Down
48 changes: 9 additions & 39 deletions app/views/hub/state_file/efile_submissions/_log.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% transmitted_transitions = transitions.select { |t| t.to_state == "transmitted" } %>
<% if transitions.present? %>
<% transitions.each do |transition| %>
<% transitions&.each do |transition| %>
<% transmitted_transitions = transitions.select { |t| t.to_state == "transmitted" } %>
<% unless transmitted_transitions.include?(transition) && transition != transmitted_transitions.first %>
<li role="listitem">
<div class="timestamp"><%= timestamp transition.created_at %></div>
Expand All @@ -11,50 +11,20 @@
<% end %>
<% transition.efile_errors.each do |error| %>
<div>
<strong><%= "#{error.code}" if error.code.present? %></strong>
<div class="spacing-below-10">
<span class="tooltip max-250 error-<%= error.id %>" data-position="left" title="<%= error.message %>">
<%= link_to hub_state_file_efile_error_path(id: error.id) do %>
<div class="label label--red"><%= error.code %></div>
<% end %>
</span>
<%= error.message %>
</div>
<% end %>
<% if transition.to_state == "transmitted" %>
<table>
<tr>
<th>date</th>
<th>submission status</th>
</tr>
<% transmitted_transitions.each do |t| %>
<% if t.metadata["raw_response"].present? %>
<% xml = Nokogiri::XML(t.metadata["raw_response"]) %>
<tr>
<td>
<%= xml.css("SubmsnStatusAcknowledgementDt").text.strip %>
</td>
<td>
<%= xml.css("SubmissionStatusTxt").text.strip %>
</td>
</tr>
<% elsif t.metadata["receipt"] %>
<% xml = Nokogiri::XML(t.metadata["receipt"]) %>
<tr>
<td>
<%= DateTime.parse(xml.css("SubmissionReceivedTs").text.strip).strftime("%Y-%m-%d %H:%M") %>
</td>
<td>Submission received</td>
</tr>
<% end %>
<% end %>
</table>
<%= render 'log_transmitted', transmitted_transitions: transmitted_transitions %>
<% end %>
<% if ["failed", "rejected"].include?(transition.to_state) && transition.metadata["raw_response"].present? && !transition.metadata["raw_response"].kind_of?(Array) %>
<% xml = Nokogiri::XML(transition.metadata["raw_response"]) %>
<% error_msg = xml.css("ErrorMessageTxt").text.strip %>
<% if error_msg.present? %>
<p><strong>Error message:</strong> <%= error_msg %></p>
<% end %>
<% end %>
<% if transition.metadata.present? %>
<div class="accordion spacing-above-10">
<a href="#" class="accordion__button" aria-expanded="true" aria-controls="a2">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="grid">
<div class="grid__item width-one-half">
<table class="fixed-width-table data-table">
<tr>
<th>Date</th>
<th>Sub-status</th>
</tr>
<% transmitted_transitions.each do |t| %>
<% if t.metadata["raw_response"].present? %>
<% xml = Nokogiri::XML(t.metadata["raw_response"]) %>
<tr>
<td>
<%= xml.css("SubmsnStatusAcknowledgementDt").text.strip %>
</td>
<td>
<%= xml.css("SubmissionStatusTxt").text.strip %>
</td>
</tr>
<% elsif t.metadata["receipt"] %>
<% xml = Nokogiri::XML(t.metadata["receipt"]) %>
<tr>
<td>
<%= DateTime.parse(xml.css("SubmissionReceivedTs").text.strip).strftime("%Y-%m-%d %H:%M") %>
</td>
<td>Submission received</td>
</tr>
<% end %>
<% end %>
</table>
</div>
</div>
9 changes: 7 additions & 2 deletions app/views/hub/state_file/efile_submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@
<%= link_to submission.current_state.humanize(capitalize: false), hub_state_file_efile_submission_path(id: submission.id), class: "underline" %>
</td>
<td class="index-table__cell">
<% submission.last_transition&.efile_errors&.each do |error| %>
<span class="tooltip max-250 error-<%= error.id %>" data-position="left" title="<%= error.message %>">
<% errors = if ['waiting', 'notified_of_rejection'].include?(submission.current_state)
submission&.efile_submission_transitions&.where(to_state: 'rejected')&.last&.efile_errors
else
submission.last_transition&.efile_errors
end %>
<% errors&.each do |error| %>
<span class="tooltip max-250 error-<%= error.id %>" data-position="right" title="<%= error.message %>">
<%= link_to hub_state_file_efile_error_path(id: error.id) do %>
<div class="label label--red"><%= error.code %></div>
<% end %>
Expand Down
10 changes: 10 additions & 0 deletions app/views/hub/state_file/efile_submissions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@
class: "button button--danger button--small") %>
</div>
<% end %>
<% if @efile_submission.can_transition_to?(:rejected) && !Rails.env.production? %>
<div style="margin-left: 10px">
<%= link_to("Rejected",
reject_hub_efile_submission_path(id: @efile_submission.id),
method: :patch,
data: { confirm: "Are you sure you want to mark this tax return submission as 'Rejected'?" },
class: "button button--danger button--small") %>
</div>
<% end %>
</div>
<div class="log-wrapper">
<h4 class="spacing-below-10">Status Logs</h4>
Expand Down
16 changes: 8 additions & 8 deletions app/views/state_file/questions/return_status/_rejected.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@
<%= @error.description(I18n.locale).present? ? @error.description(I18n.locale) : @error.message %>
</section>
<% end %>
<% end %>
<% if @reject_description.present? %>
<section class="spacing-below-15">
<strong><%= t('.reject_desc') %></strong>
<%= @reject_description %>
</section>
<% if @error&.resolution(I18n.locale)&.present? && !(@error&.auto_cancel || @error&.auto_wait) %>
<section class="spacing-below-15">
<p class="spacing-below-5"><strong><%= t('.next_steps.can_edit.title') %></strong></p>
<%= @error.resolution(I18n.locale) %>
</section>
<% end %>
<% end %>
<% if @error&.auto_cancel %>
<section class="spacing-below-15">
<p class="spacing-below-5"><strong><%= t('.next_steps.no_edit.title') %></strong></p>
<%= t('.next_steps.no_edit.body_html') %>
<%= @error.resolution(I18n.locale).present? ? @error.resolution(I18n.locale) : t('.next_steps.no_edit.body_html') %>
</section>
<% end %>
<% if @error&.auto_wait %>
<section class="spacing-below-15">
<p class="spacing-below-5"><strong><%= t('.next_steps.can_edit.title') %></strong></p>
<%= @error.resolution(I18n.locale).present? && @error.expose ? @error.resolution(I18n.locale) : t('.next_steps.can_edit.body') %>
<%= @error.resolution(I18n.locale).present? ? @error.resolution(I18n.locale) : t('.next_steps.can_edit.body') %>
</section>

<section>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def scoped_navigation_routes(context, navigation)
resources :efile_submissions, path: "efile", only: [:index, :show] do
patch '/resubmit', to: 'efile_submissions#resubmit', on: :member, as: :resubmit
patch '/failed', to: 'efile_submissions#failed', on: :member, as: :failed
patch '/reject', to: 'efile_submissions#reject', on: :member, as: :reject
patch '/cancel', to: 'efile_submissions#cancel', on: :member, as: :cancel
patch '/investigate', to: 'efile_submissions#investigate', on: :member, as: :investigate
patch '/notify_of_rejection', to: 'efile_submissions#notify_of_rejection', on: :member, as: :notify_of_rejection
Expand Down
25 changes: 25 additions & 0 deletions spec/state_machines/efile_submission_state_machine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,31 @@
expect(AfterTransitionTasksForRejectedReturnJob).to have_been_enqueued.with(submission, submission.last_transition)
end

context "transition from failed" do
let(:submission) { create(:efile_submission, :failed) }

context "in prod" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end

it "raises an error" do
expect { submission.transition_to!(:rejected) }.to raise_error(Statesman::GuardFailedError)
end
end

context "in heroku" do
before do
allow(Rails.env).to receive(:heroku?).and_return(true)
end

it "succeeds in transitioning to rejected" do
submission.transition_to!(:rejected)
expect(submission.current_state).to eq "rejected"
end
end
end

context "schedule job for still processing notice" do
context "for state filing" do
it "enqueues StateFile::SendStillProcessingNoticeJob with run time at 24 hours from now" do
Expand Down

0 comments on commit ae00b01

Please sign in to comment.