Skip to content

Commit 56810f6

Browse files
authored
Preliminary work for FYST-1221: remove old workarounds and update tests (#5034)
* remove wonky workarounds from last season; add more test coverage * refactor test to be more clear
1 parent 347f1f5 commit 56810f6

File tree

2 files changed

+90
-94
lines changed

2 files changed

+90
-94
lines changed
Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
module StateFile
22
module Questions
33
class ReturnStatusController < QuestionsController
4-
before_action :redirect_if_from_efile
54
before_action :redirect_if_no_submission
65
skip_before_action :redirect_if_in_progress_intakes_ended
76

87
def edit
9-
@submission_to_show = submission_to_show
10-
@error = submission_error
8+
@submission_to_show = current_intake.latest_submission
119
@return_status = return_status
10+
@error = submission_error
1211
@tax_refund_url = StateFile::StateInformationService.tax_refund_url(current_state_code)
1312
@tax_payment_url = StateFile::StateInformationService.tax_payment_url(current_state_code)
1413
@voucher_form_name = StateFile::StateInformationService.voucher_form_name(current_state_code)
@@ -23,28 +22,16 @@ def prev_path
2322

2423
private
2524

26-
def submission_to_show
27-
is_az_intake = current_intake.is_a?(StateFileAzIntake)
28-
latest_submission_has_901_error = current_intake.latest_submission&.efile_submission_transitions&.where(to_state: "rejected")&.last&.efile_errors&.pluck(:code)&.include?("901")
29-
accepted_submissions = current_intake.efile_submissions.filter { |submission| submission.in_state?(:accepted) }
30-
31-
if is_az_intake && latest_submission_has_901_error && accepted_submissions.present?
32-
accepted_submissions.last
33-
else
34-
current_intake.latest_submission
35-
end
36-
end
37-
3825
def submission_error
3926
return nil unless return_status == 'rejected'
4027
# in the case that its in the notified_of_rejection or waiting state
4128
# we can't just grab the efile errors from the last transition
42-
submission_to_show&.efile_submission_transitions&.where(to_state: 'rejected')&.last&.efile_errors&.last
29+
@submission_to_show&.efile_submission_transitions&.where(to_state: 'rejected')&.last&.efile_errors&.last
4330
end
4431

4532
def return_status
4633
# return status for display
47-
case submission_to_show.current_state
34+
case @submission_to_show.current_state
4835
when 'accepted'
4936
'accepted'
5037
when 'notified_of_rejection', 'waiting'
@@ -61,15 +48,6 @@ def redirect_if_no_submission
6148
redirect_to StateFile::Questions::InitiateDataTransferController.to_path_helper
6249
end
6350
end
64-
65-
def redirect_if_from_efile
66-
# We had a situation where we gave the wrong URL to direct file, and they were redirecting
67-
# here when the federal return was not yet approved.
68-
# We have alerted them, and once they have updated their URL we can probably remove this
69-
if params[:ref_location] == "df_authorize_state"
70-
redirect_to StateFile::Questions::PendingFederalReturnController.to_path_helper
71-
end
72-
end
7351
end
7452
end
7553
end

spec/controllers/state_file/questions/return_status_controller_spec.rb

Lines changed: 86 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,105 @@
11
require "rails_helper"
22

33
RSpec.describe StateFile::Questions::ReturnStatusController do
4-
describe "#edit" do
5-
context "assignment of various instance variables" do
6-
it "assigns them correctly" do
7-
az_intake = create(:state_file_az_intake)
8-
sign_in az_intake
9-
create(:efile_submission, :notified_of_rejection, :for_state, data_source: az_intake)
10-
get :edit
11-
12-
expect(assigns(:tax_refund_url)).to eq "https://aztaxes.gov/home/checkrefund"
13-
expect(assigns(:tax_payment_url)).to eq "AZTaxes.gov"
14-
expect(assigns(:voucher_form_name)).to eq "Form AZ-140V"
15-
expect(assigns(:mail_voucher_address)).to eq "Arizona Department of Revenue<br/>"\
16-
"PO Box 29085<br/>"\
17-
"Phoenix, AZ 85038-9085"
18-
expect(assigns(:voucher_path)).to eq "/pdfs/AZ-140V.pdf"
19-
expect(assigns(:survey_link)).to eq "https://codeforamerica.co1.qualtrics.com/jfe/form/SV_7UTycCvS3UEokey"
20-
end
21-
end
22-
23-
context "AZ" do
24-
render_views
25-
let(:az_intake) { create :state_file_az_intake }
26-
before do
27-
sign_in az_intake
28-
end
29-
30-
context "happy path" do
31-
let!(:efile_submission) { create(:efile_submission, :notified_of_rejection, :for_state, data_source: az_intake) }
32-
33-
it "shows the most recent submission" do
34-
get :edit
35-
36-
expect(assigns(:submission_to_show)).to eq efile_submission
37-
end
38-
end
39-
40-
context "unhappy path" do
41-
let!(:previous_efile_submission) { create(:efile_submission, :accepted, :for_state, data_source: az_intake) }
42-
let!(:latest_efile_submission) { create(:efile_submission, :transmitted, :for_state, data_source: az_intake) }
4+
StateFile::StateInformationService.active_state_codes.each do |state_code|
5+
context "#{state_code}" do
6+
describe "#edit" do
7+
render_views
8+
let(:intake) { create(StateFile::StateInformationService.intake_class(state_code).name.underscore.to_sym) }
439

4410
before do
45-
latest_efile_submission.transition_to!(:rejected)
46-
create(:efile_submission_transition_error, efile_error: efile_error, efile_submission_transition: latest_efile_submission.last_transition, efile_submission_id: latest_efile_submission.id)
47-
latest_efile_submission.transition_to!(:cancelled)
11+
sign_in intake
4812
end
4913

50-
context "client got accepted and then submitted another return which got reject 901" do
51-
let(:efile_error) { create(:efile_error, code: "901", service_type: :state_file_az, expose: true) }
52-
53-
it "shows the most recent accepted submission" do
14+
context "assignment of various instance variables" do
15+
it "assigns the ones from the config service correctly" do
16+
create(:efile_submission, :notified_of_rejection, :for_state, data_source: intake)
5417
get :edit
5518

56-
expect(assigns(:submission_to_show)).to eq previous_efile_submission
19+
expect(assigns(:tax_refund_url)).to eq StateFile::StateInformationService.tax_refund_url(state_code)
20+
expect(assigns(:tax_payment_url)).to eq StateFile::StateInformationService.tax_payment_url(state_code)
21+
expect(assigns(:voucher_form_name)).to eq StateFile::StateInformationService.voucher_form_name(state_code)
22+
expect(assigns(:mail_voucher_address)).to eq StateFile::StateInformationService.mail_voucher_address(state_code)
23+
expect(assigns(:voucher_path)).to eq StateFile::StateInformationService.voucher_path(state_code)
24+
expect(assigns(:survey_link)).to eq StateFile::StateInformationService.survey_link(state_code)
5725
end
58-
end
5926

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

63-
it "shows the most recent submission" do
64-
get :edit
31+
it "assigns the most recent submission to submission_to_show" do
32+
get :edit
6533

66-
expect(assigns(:submission_to_show)).to eq latest_efile_submission
34+
expect(assigns(:submission_to_show)).to eq efile_submission_last
35+
end
6736
end
68-
end
69-
end
70-
end
7137

72-
context "NY" do
73-
let(:ny_intake) { create :state_file_ny_intake }
74-
before do
75-
sign_in ny_intake
76-
end
77-
78-
context "happy path" do
79-
let!(:efile_submission) { create(:efile_submission, :notified_of_rejection, :for_state, data_source: ny_intake) }
80-
81-
it "shows the most recent submission" do
82-
get :edit
38+
context "return status" do
39+
it "maps to accepted, rejected, or pending" do
40+
create(:efile_submission, :accepted, :for_state, data_source: intake)
41+
get :edit
42+
expect(assigns(:return_status)).to eq 'accepted'
43+
44+
create(:efile_submission, :notified_of_rejection, :for_state, data_source: intake)
45+
get :edit
46+
expect(assigns(:return_status)).to eq 'rejected'
47+
48+
create(:efile_submission, :waiting, :for_state, data_source: intake)
49+
get :edit
50+
expect(assigns(:return_status)).to eq 'rejected'
51+
52+
EfileSubmissionStateMachine.states.excluding("accepted", "notified_of_rejection", "waiting").each do |status|
53+
create(:efile_submission, status, :for_state, data_source: intake)
54+
get :edit
55+
expect(assigns(:return_status)).to eq 'pending'
56+
end
57+
end
58+
end
8359

84-
expect(assigns(:submission_to_show)).to eq efile_submission
60+
context "efile error" do
61+
context "should expose error" do
62+
[:notified_of_rejection, :waiting].each do |status|
63+
let!(:efile_submission) { create(:efile_submission, :rejected, :with_errors, :for_state, data_source: intake) }
64+
let(:error) { efile_submission.efile_submission_transitions.where(to_state: 'rejected').last.efile_errors.last }
65+
before do
66+
efile_submission.transition_to!(status)
67+
end
68+
69+
it "when #{status}, assigns the last efile error attached to the last rejected transition" do
70+
get :edit
71+
72+
expect(error).to be_a(EfileError)
73+
expect(assigns(:error)).to eq error
74+
end
75+
end
76+
end
77+
78+
context "other status" do
79+
[:new, :preparing, :bundling, :queued, :transmitted, :ready_for_ack, :failed, :rejected, :accepted].each do |status|
80+
it "when #{status}, assigns nil" do
81+
create(:efile_submission, status, :for_state, data_source: intake)
82+
83+
get :edit
84+
85+
expect(assigns(:error)).to be_nil
86+
end
87+
end
88+
89+
[:investigating, :fraud_hold, :resubmitted, :cancelled].each do |status|
90+
it "when #{status}, assigns nil even if errors exist" do
91+
efile_submission = create(:efile_submission, :rejected, :with_errors, :for_state, data_source: intake)
92+
efile_submission.transition_to!(status)
93+
error = efile_submission.efile_submission_transitions.where(to_state: 'rejected').last.efile_errors.last
94+
expect(error).to be_a(EfileError)
95+
96+
get :edit
97+
98+
expect(assigns(:error)).to be_nil
99+
end
100+
end
101+
end
102+
end
85103
end
86104
end
87105
end

0 commit comments

Comments
 (0)