-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # app/controllers/state_file/archived_intakes/email_address_controller.rb
- Loading branch information
1 parent
88f1ef1
commit 771f228
Showing
10 changed files
with
161 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/controllers/state_file/archived_intakes/identification_number_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 1. use front end validations for SSN | ||
# 2. give them 1 attempt at an inccorect SSN | ||
# 3. update the access logs to have the correct event | ||
# 4. tests, translations | ||
module StateFile | ||
module ArchivedIntakes | ||
class IdentificationNumberController < ApplicationController | ||
def edit | ||
@form = IdentificationNumberForm.new | ||
render :edit | ||
end | ||
|
||
def update | ||
@form = IdentificationNumberForm.new(identification_number_form_params) | ||
hashed_ssn = SsnHashingService.hash(identification_number_form_params[:ssn]) | ||
archived_intake = StateFileArchivedIntake.find_by(email_address: session[:archived_intake_email_address]) | ||
|
||
if hashed_ssn == archived_intake.hashed_ssn | ||
StateFileArchivedIntakeAccessLog.create!( | ||
ip_address: ip_for_irs, | ||
details: { hashed_ssn: @form.email_address }, | ||
event_type: 0, | ||
state_file_archived_intake: archived_intake | ||
) | ||
else | ||
StateFileArchivedIntakeAccessLog.create!( | ||
ip_address: ip_for_irs, | ||
details: { hashed_ssn: @form.email_address }, | ||
event_type: 0, | ||
) | ||
end | ||
end | ||
|
||
def identification_number_form_params | ||
params.require(:state_file_archived_intakes_identification_number_form).permit(:ssn) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/forms/state_file/archived_intakes/identification_number_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module StateFile | ||
module ArchivedIntakes | ||
class IdentificationNumberForm < Form | ||
validates :ssn, social_security_number: true, presence: true | ||
|
||
def initialize(attributes = {}) | ||
super | ||
assign_attributes(attributes) | ||
end | ||
|
||
def save | ||
run_callbacks :save do | ||
valid? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/views/state_file/archived_intakes/identification_number/edit.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% title ="title" %> | ||
<h1 class="h2" id="main-question"><%= title %></h1> | ||
<p><%= "help_text" %></p> | ||
|
||
<%= form_with model: @form, url: state_file_archived_intakes_identification_number_path, local: true, method: :patch, builder: VitaMinFormBuilder do |f| %> | ||
<div class="white-group"> | ||
<%= f.cfa_input_field(:ssn, "ssn_label", classes: ["form-width--long"]) %> | ||
</div> | ||
<%= f.submit t("general.continue"), class: "button button--primary button--wide spacing-below-15" %> | ||
<% end %> |
2 changes: 2 additions & 0 deletions
2
app/views/state_file/questions/validate_identification_number/edit.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<% content_for :page_title, t(".title") do %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
spec/controllers/state_file/archived_intake/identification_number_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe StateFile::ArchivedIntakes::IdentificationNumberController, type: :controller do | ||
describe "GET #edit" do | ||
it "renders the edit template with a new IdentificationNumberForm" do | ||
get :edit | ||
|
||
expect(assigns(:form)).to be_a(StateFile::ArchivedIntakes::IdentificationNumberForm) | ||
expect(response).to render_template(:edit) | ||
end | ||
end | ||
|
||
describe "POST #update" do | ||
let(:email_address) { "[email protected]" } | ||
let(:ip_address) { "127.0.0.1" } | ||
|
||
before do | ||
allow(controller).to receive(:ip_for_irs).and_return(ip_address) | ||
end | ||
|
||
context "when the form is valid" do | ||
|
||
it "creates an access log and redirects to the verification code page" do | ||
post :update, params: { | ||
state_file_archived_intakes_email_address_form: { email_address: valid_email_address } | ||
} | ||
expect(assigns(:form)).to be_valid | ||
|
||
access_log = StateFileArchivedIntakeAccessLog.last | ||
expect(access_log.ip_address).to eq(ip_address) | ||
expect(access_log.details["email_address"]).to eq(valid_email_address) | ||
expect(access_log.event_type).to eq("issued_email_challenge") | ||
|
||
expect(response).to redirect_to( | ||
state_file_archived_intakes_edit_verification_code_path(email_address: valid_email_address) | ||
) | ||
end | ||
end | ||
|
||
context "when the form is invalid" do | ||
it "renders the edit template" do | ||
post :update, params: { | ||
state_file_archived_intakes_email_address_form: { email_address: invalid_email_address } | ||
} | ||
|
||
expect(assigns(:form)).not_to be_valid | ||
|
||
expect(StateFileArchivedIntakeAccessLog.count).to eq(0) | ||
|
||
expect(response).to render_template(:edit) | ||
end | ||
end | ||
end | ||
end |