-
Notifications
You must be signed in to change notification settings - Fork 166
Use form object pattern for Idv::AddressController submission
#10388
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
jmhooper
merged 3 commits into
main
from
jmhooper-use-form-object-pattern-in-address-controller
Apr 9, 2024
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
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
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,78 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Idv::AddressForm do | ||
| let(:pii) do | ||
| { | ||
| first_name: 'Test', | ||
| last_name: 'McTesterson', | ||
| address1: '123 Main St', | ||
| address2: nil, | ||
| city: 'Testertown', | ||
| state: 'TX', | ||
| zipcode: '11111', | ||
| } | ||
| end | ||
|
|
||
| let(:params) do | ||
| { | ||
| address1: '456 Other St', | ||
| address2: 'Apt 1', | ||
| city: 'McTestville', | ||
| state: 'IL', | ||
| zipcode: '22222', | ||
| } | ||
| end | ||
|
|
||
| it 'is initialized with values from the hash in the initializer' do | ||
| address_form = Idv::AddressForm.new(pii) | ||
| expect(address_form.address1).to eq('123 Main St') | ||
| expect(address_form.address2).to eq(nil) | ||
| expect(address_form.city).to eq('Testertown') | ||
| expect(address_form.state).to eq('TX') | ||
| expect(address_form.zipcode).to eq('11111') | ||
| end | ||
|
|
||
| describe '#submit' do | ||
| context 'with valid params' do | ||
| it 'returns a successful result' do | ||
| result = Idv::AddressForm.new(pii).submit(params) | ||
|
|
||
| expect(result.success?).to eq(true) | ||
| expect(result.extra[:address_edited]).to eq(true) | ||
| end | ||
| end | ||
|
|
||
| context 'with a malformed param' do | ||
| it 'returns an error result' do | ||
| params[:zipcode] = 'this is not a valid zipcde' | ||
|
|
||
| result = Idv::AddressForm.new(pii).submit(params) | ||
|
|
||
| expect(result.success?).to eq(false) | ||
| expect(result.errors[:zipcode]).to be_present | ||
| end | ||
| end | ||
|
|
||
| context 'with a missing params' do | ||
| it 'returns an error result' do | ||
| params.delete(:zipcode) | ||
|
|
||
| result = Idv::AddressForm.new(pii).submit(params) | ||
|
|
||
| expect(result.success?).to eq(false) | ||
| expect(result.errors[:zipcode]).to be_present | ||
| end | ||
| end | ||
|
|
||
| context 'the user submits the same address that is in the pii' do | ||
| it 'does not set `address_edited` to true' do | ||
| params = pii.slice(:address1, :address2, :city, :state, :zipcode) | ||
|
|
||
| result = Idv::AddressForm.new(pii).submit(params) | ||
|
|
||
| expect(result.success?).to eq(true) | ||
| expect(result.extra[:address_edited]).to eq(false) | ||
| 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
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.
It looks like this is very similar to
set_ivars_with_piiexcept this sets@address_edited = true, do you think it would be worth trying to combine? or nahThere 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.
I made an effort to combine and struggled with a good way to do it well. I am going to be working on this again in #10385 and I'm hoping that it will be easier when we have a struct to represent an address because then we can just compare them.
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.
Sorry, I'll be working on this in a follow-up to #10385 since #10385 is just for reads.
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.
@zachmargolis: I just opened #10390 which includes these changes to the
AddressForm: https://github.com/18F/identity-idp/pull/10390/files#diff-1b0c80e533f13f34a865f61b08ff023a3efbd21ba6bfa03aa84e0c3d0c108128I got it out of the business of tracking address edits. My thinking is that once we stop overwriting the address in
pii_from_docwe will get a fix for this bug: https://github.com/18F/identity-idp/pull/10385/files#diff-ee8ce27b8fbb65556458f217dd0017a6418194fd31087457ac79c219f750d337R130There 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.
Awesome!