-
Notifications
You must be signed in to change notification settings - Fork 166
Add separate OtpDeliveryMethodForm for IdV #2440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,24 @@ | ||
| module Idv | ||
| class OtpDeliveryMethodForm | ||
| include ActiveModel::Model | ||
|
|
||
| attr_reader :otp_delivery_preference | ||
|
|
||
| validates :otp_delivery_preference, inclusion: { in: %w[sms voice] } | ||
|
|
||
| def submit(params) | ||
| self.otp_delivery_preference = params[:otp_delivery_preference] | ||
| FormResponse.new(success: valid?, errors: errors.messages, extra: extra_analytics_attributes) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_writer :otp_delivery_preference | ||
|
|
||
| def extra_analytics_attributes | ||
| { | ||
| otp_delivery_preference: otp_delivery_preference, | ||
| } | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -39,9 +39,9 @@ | |
| subject.idv_session.vendor_phone_confirmation = false | ||
| end | ||
|
|
||
| it 'redirects to the review controller' do | ||
| it 'redirects to the phone controller' do | ||
| get :new | ||
| expect(response).to redirect_to idv_review_path | ||
| expect(response).to redirect_to idv_phone_path | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -51,6 +51,16 @@ | |
| expect(response).to render_template :new | ||
| end | ||
| end | ||
|
|
||
| it 'tracks an analytics event' do | ||
| stub_analytics | ||
| allow(@analytics).to receive(:track_event) | ||
|
|
||
| get :new | ||
|
|
||
| expect(@analytics).to have_received(:track_event). | ||
| with(Analytics::IDV_PHONE_OTP_DELIVERY_SELECTION_VISIT) | ||
| end | ||
| end | ||
|
|
||
| describe '#create' do | ||
|
|
@@ -89,9 +99,9 @@ | |
| subject.idv_session.vendor_phone_confirmation = false | ||
| end | ||
|
|
||
| it 'redirects to the review controller' do | ||
| it 'redirects to the phone controller' do | ||
| post :create, params: params | ||
| expect(response).to redirect_to idv_review_path | ||
| expect(response).to redirect_to idv_phone_path | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -100,6 +110,22 @@ | |
| post :create, params: params | ||
| expect(response).to redirect_to otp_send_path(params) | ||
| end | ||
|
|
||
| it 'tracks an analytics event' do | ||
| stub_analytics | ||
| allow(@analytics).to receive(:track_event) | ||
|
|
||
| post :create, params: params | ||
|
|
||
| result = { | ||
| success: true, | ||
| errors: {}, | ||
| otp_delivery_preference: 'sms', | ||
| } | ||
|
|
||
| expect(@analytics).to have_received(:track_event). | ||
| with(Analytics::IDV_PHONE_OTP_DELIVERY_SELECTION_SUBMITTED, result) | ||
| end | ||
| end | ||
|
|
||
| context 'user has selected voice' do | ||
|
|
@@ -115,6 +141,22 @@ | |
| post :create, params: params | ||
| expect(response).to redirect_to otp_send_path(params) | ||
| end | ||
|
|
||
| it 'tracks an analytics event' do | ||
| stub_analytics | ||
| allow(@analytics).to receive(:track_event) | ||
|
|
||
| post :create, params: params | ||
|
|
||
| result = { | ||
| success: true, | ||
| errors: {}, | ||
| otp_delivery_preference: 'voice', | ||
| } | ||
|
|
||
| expect(@analytics).to have_received(:track_event). | ||
| with(Analytics::IDV_PHONE_OTP_DELIVERY_SELECTION_SUBMITTED, result) | ||
| end | ||
| end | ||
|
|
||
| context 'form is invalid' do | ||
|
|
@@ -130,6 +172,22 @@ | |
| post :create, params: params | ||
| expect(response).to render_template :new | ||
| end | ||
|
|
||
| it 'tracks an analytics event' do | ||
| stub_analytics | ||
| allow(@analytics).to receive(:track_event) | ||
|
|
||
| post :create, params: params | ||
|
|
||
| result = { | ||
| success: false, | ||
| errors: { otp_delivery_preference: ['is not included in the list'] }, | ||
| otp_delivery_preference: '🎷', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. love the sax |
||
| } | ||
|
|
||
| expect(@analytics).to have_received(:track_event). | ||
| with(Analytics::IDV_PHONE_OTP_DELIVERY_SELECTION_SUBMITTED, result) | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pictured here: Me begging for merge conflicts against #2430
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a wild idea: what if we got rid of this
otp_delivery_selection_formaltogether? The only thing it's doing is making sure the method is either "sms" or "voice", and the only way it would not be is if someone deliberately manipulated the HTML on the page before submitting the form. How about if we default to "sms" if something other than "sms" or "voice" is submitted?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe default to not do anything and display the delivery selection page again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes some changes to the idv session in the other PR. The delivery preference gets saved there instead of added as a url param. We could move that logic to the controller, but idk if we want to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm looking at my new code now and I do actually already set it in the controller. Hmm, yeah we can try removing it completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though another downside of not have a form is that we don't have a result object to feed to analytics here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@monfresh: Anything to add here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good. I think we decided to leave this here when we discussed this offline.