-
Notifications
You must be signed in to change notification settings - Fork 166
Jmax/lg 8889 best effort parsing of aamva exceptions #7879
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
Changes from all commits
16f534e
a60662a
1368401
5bf80bd
3b039f2
5eee27a
9fe364a
a711ed0
0e214e8
8c958b6
698528f
21896c3
e8997a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,13 @@ | |
| subject(:verification_client) { described_class.new(AamvaFixtures.example_config) } | ||
|
|
||
| describe '#send_verification_request' do | ||
| it 'should get the auth token from the auth client' do | ||
| before do | ||
| auth_client = instance_double(Proofing::Aamva::AuthenticationClient) | ||
| allow(auth_client).to receive(:fetch_token).and_return('ThisIsTheToken') | ||
| allow(Proofing::Aamva::AuthenticationClient).to receive(:new).and_return(auth_client) | ||
| end | ||
|
|
||
| it 'gets the auth token from the auth client' do | ||
| verification_stub = stub_request(:post, AamvaFixtures.example_config.verification_url). | ||
| to_return(body: AamvaFixtures.verification_response, status: 200). | ||
| with do |request| | ||
|
|
@@ -37,45 +39,149 @@ | |
|
|
||
| expect(verification_stub).to have_been_requested | ||
| end | ||
| end | ||
|
|
||
| context 'when verification is successful' do | ||
| it 'should return a successful response' do | ||
| auth_client = instance_double(Proofing::Aamva::AuthenticationClient) | ||
| allow(auth_client).to receive(:fetch_token).and_return('ThisIsTheToken') | ||
| allow(Proofing::Aamva::AuthenticationClient).to receive(:new).and_return(auth_client) | ||
| stub_request(:post, AamvaFixtures.example_config.verification_url). | ||
| to_return(body: AamvaFixtures.verification_response, status: 200) | ||
|
|
||
| response = verification_client.send_verification_request( | ||
| applicant: applicant, | ||
| session_id: '1234-abcd-efgh', | ||
| ) | ||
| describe '#send_verification_request' do | ||
| let(:response_body) { AamvaFixtures.verification_response } | ||
| let(:response_http_status) { 200 } | ||
|
|
||
| before do | ||
| auth_client = instance_double(Proofing::Aamva::AuthenticationClient) | ||
| allow(auth_client).to receive(:fetch_token).and_return('ThisIsTheToken') | ||
| allow(Proofing::Aamva::AuthenticationClient).to receive(:new).and_return(auth_client) | ||
|
|
||
| stub_request(:post, AamvaFixtures.example_config.verification_url). | ||
| to_return(body: response_body, status: response_http_status) | ||
| end | ||
|
|
||
| let(:response) do | ||
| verification_client.send_verification_request( | ||
| applicant: applicant, | ||
| session_id: '1234-abcd-efgh', | ||
| ) | ||
| end | ||
|
|
||
| context 'when verification is successful' do | ||
| it 'returns a successful response' do | ||
| expect(response).to be_a Proofing::Aamva::Response::VerificationResponse | ||
| expect(response.success?).to eq(true) | ||
| end | ||
| end | ||
|
|
||
| context 'when verification is not successful' do | ||
| it 'should return an unsuccessful response with errors' do | ||
| auth_client = instance_double(Proofing::Aamva::AuthenticationClient) | ||
| allow(auth_client).to receive(:fetch_token).and_return('ThisIsTheToken') | ||
| allow(Proofing::Aamva::AuthenticationClient).to receive(:new).and_return(auth_client) | ||
| context 'because we have a valid response and a 200 status, but the response says "no"' do | ||
| let(:response_body) do | ||
| modify_xml_at_xpath( | ||
| AamvaFixtures.verification_response, | ||
| '//PersonBirthDateMatchIndicator', | ||
| 'false', | ||
| ) | ||
| end | ||
|
|
||
| it 'returns an unsuccessful response with errors' do | ||
| expect(response).to be_a Proofing::Aamva::Response::VerificationResponse | ||
| expect(response.success?).to eq(false) | ||
| end | ||
| end | ||
|
|
||
| stub_request(:post, AamvaFixtures.example_config.verification_url). | ||
| to_return(status: 200, body: modify_xml_at_xpath( | ||
| context 'because we have a valid response and a non-200 status, and the response says "no"' do | ||
| let(:response_body) do | ||
| modify_xml_at_xpath( | ||
| AamvaFixtures.verification_response, | ||
| '//PersonBirthDateMatchIndicator', | ||
| 'false', | ||
| )) | ||
| ) | ||
| end | ||
| let(:response_http_status) { 500 } | ||
|
|
||
| it 'throws an exception about the status code' do | ||
| expect { response }.to raise_error( | ||
| Proofing::Aamva::VerificationError, | ||
| /Unexpected status code in response: 500/, | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| response = verification_client.send_verification_request( | ||
| applicant: applicant, | ||
| session_id: '1234-abcd-efgh', | ||
| ) | ||
| context 'because we have an MVA timeout and 500 status' do | ||
| let(:response_body) { AamvaFixtures.soap_fault_response } | ||
| let(:response_http_status) { 500 } | ||
|
|
||
| expect(response).to be_a Proofing::Aamva::Response::VerificationResponse | ||
| expect(response.success?).to eq(false) | ||
| it 'throws an exception about the MVA timeout' do | ||
| expect { response }.to raise_error( | ||
| Proofing::Aamva::VerificationError, | ||
| /#{Proofing::Aamva::Response::VerificationResponse::MVA_TIMEOUT_EXCEPTION}/o, | ||
| ) | ||
| end | ||
|
|
||
| it 'throws an exception about the status code' do | ||
| expect { response }.to raise_error( | ||
| Proofing::Aamva::VerificationError, | ||
| /Unexpected status code in response: 500/, | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| context 'because we have an MVA timeout and 200 status' do | ||
| let(:response_body) { AamvaFixtures.soap_fault_response } | ||
| let(:response_http_status) { 200 } | ||
|
|
||
| it 'parses the raw response body' do | ||
| begin | ||
| response | ||
|
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. I'm not sure I follow what this test is trying to accomplish? It looks like the test below covers what we actually care about.
Contributor
Author
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. An explicit test that we tried to parse the body.
Contributor
Author
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. Removed. |
||
| rescue Proofing::Aamva::VerificationError | ||
| end | ||
| end | ||
|
|
||
| it 'throws an exception about the MVA timeout' do | ||
| expect { response }.to raise_error( | ||
| Proofing::Aamva::VerificationError, | ||
| /#{Proofing::Aamva::Response::VerificationResponse::MVA_TIMEOUT_EXCEPTION}/o, | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| context 'because we have an invalid response and a 200 status' do | ||
| let(:response_body) { 'error: computer has no brain.<br>' } | ||
|
|
||
| it 'tries to parse the raw response body' do | ||
| begin | ||
| response | ||
| rescue Proofing::Aamva::VerificationError | ||
| end | ||
| end | ||
|
|
||
| it 'throws a SOAP exception' do | ||
| expect { response }.to raise_error( | ||
| Proofing::Aamva::VerificationError, | ||
| /No close tag for \/br/, | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| context 'because we have an invalid response and a non-200 status' do | ||
| let(:response_body) { '<h1>I\'m a teapot' } | ||
| let(:response_http_status) { 418 } | ||
|
|
||
| it 'tries to parse the raw response body' do | ||
| begin | ||
| response | ||
| rescue Proofing::Aamva::VerificationError | ||
| end | ||
| end | ||
|
|
||
| it 'throws an error which complains about the invalid response' do | ||
| expect { response }.to raise_error( | ||
| Proofing::Aamva::VerificationError, | ||
| /No close tag for \/h1/, | ||
| ) | ||
| end | ||
|
|
||
| it 'throws an error which complains about the HTTP error code' do | ||
| expect { response }.to raise_error( | ||
| Proofing::Aamva::VerificationError, | ||
| /Unexpected status code in response: 418/, | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
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.
This
describeblock looks like it is describing the same method as the block aboveThere 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 is, but a different aspect of the method. The setup code was different enough to warrant splitting the describe block.