Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions app/controllers/state_file/questions/return_status_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
module StateFile
module Questions
class ReturnStatusController < QuestionsController
before_action :redirect_if_from_efile
before_action :redirect_if_no_submission
skip_before_action :redirect_if_in_progress_intakes_ended

def edit
@submission_to_show = submission_to_show
@error = submission_error
@submission_to_show = current_intake.latest_submission
@return_status = return_status
@error = submission_error
@tax_refund_url = StateFile::StateInformationService.tax_refund_url(current_state_code)
@tax_payment_url = StateFile::StateInformationService.tax_payment_url(current_state_code)
@voucher_form_name = StateFile::StateInformationService.voucher_form_name(current_state_code)
Expand All @@ -23,28 +22,16 @@ def prev_path

private

def submission_to_show
is_az_intake = current_intake.is_a?(StateFileAzIntake)
latest_submission_has_901_error = current_intake.latest_submission&.efile_submission_transitions&.where(to_state: "rejected")&.last&.efile_errors&.pluck(:code)&.include?("901")
accepted_submissions = current_intake.efile_submissions.filter { |submission| submission.in_state?(:accepted) }

if is_az_intake && latest_submission_has_901_error && accepted_submissions.present?
accepted_submissions.last
else
current_intake.latest_submission
end
end

def submission_error
return nil unless return_status == 'rejected'
# in the case that its in the notified_of_rejection or waiting state
# we can't just grab the efile errors from the last transition
submission_to_show&.efile_submission_transitions&.where(to_state: 'rejected')&.last&.efile_errors&.last
@submission_to_show&.efile_submission_transitions&.where(to_state: 'rejected')&.last&.efile_errors&.last
end

def return_status
# return status for display
case submission_to_show.current_state
case @submission_to_show.current_state
when 'accepted'
'accepted'
when 'notified_of_rejection', 'waiting'
Expand All @@ -61,15 +48,6 @@ def redirect_if_no_submission
redirect_to StateFile::Questions::InitiateDataTransferController.to_path_helper
end
end

def redirect_if_from_efile
# We had a situation where we gave the wrong URL to direct file, and they were redirecting
# here when the federal return was not yet approved.
# We have alerted them, and once they have updated their URL we can probably remove this
if params[:ref_location] == "df_authorize_state"
redirect_to StateFile::Questions::PendingFederalReturnController.to_path_helper
end
end
end
end
end
154 changes: 86 additions & 68 deletions spec/controllers/state_file/questions/return_status_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,87 +1,105 @@
require "rails_helper"

RSpec.describe StateFile::Questions::ReturnStatusController do
describe "#edit" do
context "assignment of various instance variables" do
it "assigns them correctly" do
az_intake = create(:state_file_az_intake)
sign_in az_intake
create(:efile_submission, :notified_of_rejection, :for_state, data_source: az_intake)
get :edit

expect(assigns(:tax_refund_url)).to eq "https://aztaxes.gov/home/checkrefund"
expect(assigns(:tax_payment_url)).to eq "AZTaxes.gov"
expect(assigns(:voucher_form_name)).to eq "Form AZ-140V"
expect(assigns(:mail_voucher_address)).to eq "Arizona Department of Revenue<br/>"\
"PO Box 29085<br/>"\
"Phoenix, AZ 85038-9085"
expect(assigns(:voucher_path)).to eq "/pdfs/AZ-140V.pdf"
expect(assigns(:survey_link)).to eq "https://codeforamerica.co1.qualtrics.com/jfe/form/SV_7UTycCvS3UEokey"
end
end

context "AZ" do
render_views
let(:az_intake) { create :state_file_az_intake }
before do
sign_in az_intake
end

context "happy path" do
let!(:efile_submission) { create(:efile_submission, :notified_of_rejection, :for_state, data_source: az_intake) }

it "shows the most recent submission" do
get :edit

expect(assigns(:submission_to_show)).to eq efile_submission
end
end

context "unhappy path" do
let!(:previous_efile_submission) { create(:efile_submission, :accepted, :for_state, data_source: az_intake) }
let!(:latest_efile_submission) { create(:efile_submission, :transmitted, :for_state, data_source: az_intake) }
StateFile::StateInformationService.active_state_codes.each do |state_code|
context "#{state_code}" do
describe "#edit" do
render_views
let(:intake) { create(StateFile::StateInformationService.intake_class(state_code).name.underscore.to_sym) }

before do
latest_efile_submission.transition_to!(:rejected)
create(:efile_submission_transition_error, efile_error: efile_error, efile_submission_transition: latest_efile_submission.last_transition, efile_submission_id: latest_efile_submission.id)
latest_efile_submission.transition_to!(:cancelled)
sign_in intake
end

context "client got accepted and then submitted another return which got reject 901" do
let(:efile_error) { create(:efile_error, code: "901", service_type: :state_file_az, expose: true) }

it "shows the most recent accepted submission" do
context "assignment of various instance variables" do
it "assigns the ones from the config service correctly" do
create(:efile_submission, :notified_of_rejection, :for_state, data_source: intake)
get :edit

expect(assigns(:submission_to_show)).to eq previous_efile_submission
expect(assigns(:tax_refund_url)).to eq StateFile::StateInformationService.tax_refund_url(state_code)
expect(assigns(:tax_payment_url)).to eq StateFile::StateInformationService.tax_payment_url(state_code)
expect(assigns(:voucher_form_name)).to eq StateFile::StateInformationService.voucher_form_name(state_code)
expect(assigns(:mail_voucher_address)).to eq StateFile::StateInformationService.mail_voucher_address(state_code)
expect(assigns(:voucher_path)).to eq StateFile::StateInformationService.voucher_path(state_code)
expect(assigns(:survey_link)).to eq StateFile::StateInformationService.survey_link(state_code)
end
end

context "client got accepted and then submitted another return which got a different rejection" do
let(:efile_error) { create(:efile_error, code: "A LEGIT REJECTION I GUESS", service_type: :state_file_az, expose: true) }
context "submission" do
let!(:efile_submission_first) { create(:efile_submission, :notified_of_rejection, :for_state, data_source: intake) }
let!(:efile_submission_last) { create(:efile_submission, :notified_of_rejection, :for_state, data_source: intake) }

it "shows the most recent submission" do
get :edit
it "assigns the most recent submission to submission_to_show" do
get :edit

expect(assigns(:submission_to_show)).to eq latest_efile_submission
expect(assigns(:submission_to_show)).to eq efile_submission_last
end
end
end
end
end

context "NY" do
let(:ny_intake) { create :state_file_ny_intake }
before do
sign_in ny_intake
end

context "happy path" do
let!(:efile_submission) { create(:efile_submission, :notified_of_rejection, :for_state, data_source: ny_intake) }

it "shows the most recent submission" do
get :edit
context "return status" do
it "maps to accepted, rejected, or pending" do
create(:efile_submission, :accepted, :for_state, data_source: intake)
get :edit
expect(assigns(:return_status)).to eq 'accepted'

create(:efile_submission, :notified_of_rejection, :for_state, data_source: intake)
get :edit
expect(assigns(:return_status)).to eq 'rejected'

create(:efile_submission, :waiting, :for_state, data_source: intake)
get :edit
expect(assigns(:return_status)).to eq 'rejected'

EfileSubmissionStateMachine.states.excluding("accepted", "notified_of_rejection", "waiting").each do |status|
create(:efile_submission, status, :for_state, data_source: intake)
get :edit
expect(assigns(:return_status)).to eq 'pending'
end
end
end

expect(assigns(:submission_to_show)).to eq efile_submission
context "efile error" do
context "should expose error" do
[:notified_of_rejection, :waiting].each do |status|
let!(:efile_submission) { create(:efile_submission, :rejected, :with_errors, :for_state, data_source: intake) }
let(:error) { efile_submission.efile_submission_transitions.where(to_state: 'rejected').last.efile_errors.last }
before do
efile_submission.transition_to!(status)
end

it "when #{status}, assigns the last efile error attached to the last rejected transition" do
get :edit

expect(error).to be_a(EfileError)
expect(assigns(:error)).to eq error
end
end
end

context "other status" do
[:new, :preparing, :bundling, :queued, :transmitted, :ready_for_ack, :failed, :rejected, :accepted].each do |status|
it "when #{status}, assigns nil" do
create(:efile_submission, status, :for_state, data_source: intake)

get :edit

expect(assigns(:error)).to be_nil
end
end

[:investigating, :fraud_hold, :resubmitted, :cancelled].each do |status|
it "when #{status}, assigns nil even if errors exist" do
efile_submission = create(:efile_submission, :rejected, :with_errors, :for_state, data_source: intake)
efile_submission.transition_to!(status)
error = efile_submission.efile_submission_transitions.where(to_state: 'rejected').last.efile_errors.last
expect(error).to be_a(EfileError)

get :edit

expect(assigns(:error)).to be_nil
end
end
end
end
end
end
end
Expand Down
Loading