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
2 changes: 1 addition & 1 deletion app/jobs/get_usps_proofing_results_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def check_enrollment(enrollment)
enrollment_outcomes[:enrollments_checked] += 1

response = proofer.request_proofing_results(
enrollment.unique_id, enrollment.enrollment_code
enrollment,
)
rescue Faraday::BadRequestError => err
# 400 status code. This is used for some status updates and some common client errors
Expand Down
2 changes: 1 addition & 1 deletion app/services/usps_in_person_proofing/mock/proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def request_facilities(_location, is_enhanced_ipp)
end
end

def request_proofing_results(_unique_id, _enrollment_code)
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.

Thank you for fixing this!

def request_proofing_results(_enrollment)
JSON.parse(Fixtures.request_passed_proofing_results_response)
end
end
Expand Down
13 changes: 6 additions & 7 deletions app/services/usps_in_person_proofing/proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,18 @@ def request_enroll(applicant, is_enhanced_ipp)
end

# Makes HTTP request to retrieve proofing status
# Requires the applicant's enrollment code and unique ID.
# Requires the applicant's InPersonEnrollment.
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.

👍🏻

# When proofing is complete the API returns 200 status.
# If the applicant has not been to the post office, has proofed recently,
# or there is another issue, the API returns a 400 status with an error message.
# @param unique_id [String]
# @param enrollment_code [String]
# param enrollment [InPersonEnrollment]
# @return [Hash] API response
def request_proofing_results(unique_id, enrollment_code)
def request_proofing_results(enrollment)
url = "#{root_url}/ivs-ippaas-api/IPPRest/resources/rest/getProofingResults"
request_body = {
sponsorID: sponsor_id,
uniqueID: unique_id,
enrollmentCode: enrollment_code,
sponsorID: enrollment.sponsor_id.to_i,
uniqueID: enrollment.unique_id,
enrollmentCode: enrollment.enrollment_code,
}

faraday.post(url, request_body, dynamic_headers) do |req|
Expand Down
44 changes: 28 additions & 16 deletions spec/services/usps_in_person_proofing/proofer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,31 +403,49 @@ def expect_facility_fields_to_be_present(facility)
'applicant',
unique_id: '123456789',
enrollment_code: '123456789',
sponsor_id: '314159265359',
)
end

before do
stub_request_token
end

context 'when the user is going through enhanced ipp' do
let(:request_body) do
{
sponsorID: applicant.sponsor_id.to_i,
uniqueID: applicant.unique_id,
enrollmentCode: applicant.enrollment_code,
}
end
let(:faraday_response) { double('faraday_response', body: 'blah blah') }
let(:faraday) { Faraday.new }
before do
allow(Faraday).to receive(:new).and_return(faraday)
allow(Rails.cache).to receive(:read).and_return('some fake token')
end
it 'sends the correct information in the request body' do
expect(faraday).to receive(:post).with(
anything, request_body,
anything
).and_return(faraday_response)
subject.request_proofing_results(applicant)
end
end

it 'returns failed enrollment information' do
stub_request_failed_proofing_results

proofing_results = subject.request_proofing_results(
applicant.unique_id,
applicant.enrollment_code,
)
proofing_results = subject.request_proofing_results(applicant)
expect(proofing_results['status']).to eq 'In-person failed'
expect(proofing_results['fraudSuspected']).to eq false
end

it 'returns passed enrollment information' do
stub_request_passed_proofing_results

proofing_results = subject.request_proofing_results(
applicant.unique_id,
applicant.enrollment_code,
)
proofing_results = subject.request_proofing_results(applicant)
expect(proofing_results['status']).to eq 'In-person passed'
expect(proofing_results['fraudSuspected']).to eq false
end
Expand All @@ -436,10 +454,7 @@ def expect_facility_fields_to_be_present(facility)
stub_request_in_progress_proofing_results

expect do
subject.request_proofing_results(
applicant.unique_id,
applicant.enrollment_code,
)
subject.request_proofing_results(applicant)
end.to raise_error(
an_instance_of(Faraday::BadRequestError).
and(having_attributes(
Expand Down Expand Up @@ -469,10 +484,7 @@ def expect_facility_fields_to_be_present(facility)
subject.token
proofing_results = nil
travel_to(expires_at) do
proofing_results = subject.request_proofing_results(
applicant.unique_id,
applicant.enrollment_code,
)
proofing_results = subject.request_proofing_results(applicant)
end

expect(WebMock).to have_requested(:post, "#{root_url}/oauth/authenticate").twice
Expand Down