Skip to content

Commit

Permalink
Some changes to help with testing in the hub
Browse files Browse the repository at this point in the history
  • Loading branch information
embarnard committed Mar 21, 2024
1 parent d24575c commit 879ce6e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 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
9 changes: 7 additions & 2 deletions 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 Expand Up @@ -139,7 +144,7 @@ class EfileSubmissionStateMachine
end

after_transition(to: :rejected, after_commit: true) do |submission, transition|
AfterTransitionTasksForRejectedReturnJob.perform_later(submission, transition)
AfterTransitionTasksForRejectedReturnJob.perform_now(submission, transition)
if submission.is_for_state_filing?
EfileSubmissionStateMachine.send_mixpanel_event(submission, "state_file_efile_return_rejected")
StateFile::SendStillProcessingNoticeJob.set(wait: 24.hours).perform_later(submission)
Expand Down
8 changes: 7 additions & 1 deletion app/views/hub/state_file/efile_submissions/_log.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
<% transition.efile_errors.each do |error| %>
<div>
<strong><%= "#{error.code}" if error.code.present? %></strong>
<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 %>

<!-- bring this out to partial? maybe should gather them by statuses? at least for transmitted and rejected-->
<% if transition.to_state == "transmitted" %>
<table>
<tr>
Expand Down Expand Up @@ -47,6 +52,7 @@
</table>
<% end %>

<!-- clean this up I think I can remove this-->
<% 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 %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/hub/state_file/efile_submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
<%= 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| %>
<% errors = submission.last_transition&.efile_errors %>
<% errors = submission&.efile_submission_transitions&.where(to_state: 'rejected')&.last&.efile_errors if ['waiting', 'notified_of_rejection'].include?(submission.current_state) %>
<% errors&.each do |error| %>
<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>
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
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 879ce6e

Please sign in to comment.