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
20 changes: 15 additions & 5 deletions app/services/idv/steps/send_link_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,22 @@ def call
build_telephony_form_response(telephony_result)
end

def extra_view_variables
{
idv_phone_form: build_form,
}
end

private

def build_form
Idv::PhoneForm.new(
previous_params: {},
user: current_user,
delivery_methods: [:sms],
)
end

def build_telephony_form_response(telephony_result)
FormResponse.new(
success: telephony_result.success?,
Expand Down Expand Up @@ -76,11 +90,7 @@ def sp_or_app_name
def form_submit
params = permit(:phone)
params[:otp_delivery_preference] = 'sms'
Idv::PhoneForm.new(
previous_params: {},
user: current_user,
delivery_methods: [:sms],
).submit(params)
build_form.submit(params)
end

def formatted_destination_phone
Expand Down
3 changes: 2 additions & 1 deletion app/views/idv/doc_auth/send_link.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

<p><%= t('doc_auth.instructions.send_sms') %></p>
<%= simple_form_for(
:doc_auth,
idv_phone_form,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to check: the only reason we're building the form is so we can pass it something that responds to #phone right? Could we pass a different object or like a simple PORO/Struct that has a #phone method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based this usage on Idv::PhoneController which also uses Idv::PhoneForm. The form has some logic already built into it to pre-fill the user's MFA phone number.

as: :doc_auth,
url: url_for,
method: 'PUT',
html: { autocomplete: 'off' },
Expand Down
5 changes: 5 additions & 0 deletions spec/features/idv/doc_auth/send_link_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
let(:fake_analytics) { FakeAnalytics.new }
let(:fake_attempts_tracker) { IrsAttemptsApiTrackingHelper::FakeAttemptsTracker.new }

it "defaults phone to user's 2fa phone numebr" do
field = page.find_field(t('two_factor_authentication.phone_label'))
expect(field.value).to eq('+1 202-555-1212')
end

it 'proceeds to the next page with valid info' do
expect_any_instance_of(IrsAttemptsApi::Tracker).to receive(:track_event).with(
:idv_phone_upload_link_sent,
Expand Down
10 changes: 10 additions & 0 deletions spec/services/idv/steps/send_link_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
and_return(irs_attempts_api_tracker)
end

describe '#extra_view_variables' do
it 'includes form' do
expect(step.extra_view_variables).to include(
{
idv_phone_form: be_an_instance_of(Idv::PhoneForm),
},
Comment on lines +74 to +76
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically the curly braces could be optional, though I don't have a strong preference in case you think they help readability.

Suggested change
{
idv_phone_form: be_an_instance_of(Idv::PhoneForm),
},
idv_phone_form: be_an_instance_of(Idv::PhoneForm),

)
end
end

describe 'the return value from #call' do
let(:response) { step.call }

Expand Down