Skip to content
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

Lg-14794 reuse valid capture app url #11555

Merged
merged 11 commits into from
Dec 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def show
Funnel::DocAuth::RegisterStep.new(document_capture_user.id, sp_session[:issuer]).
call('hybrid_mobile_socure_document_capture', :view, true)

if document_capture_session.socure_docv_capture_app_url.present?
@url = document_capture_session.socure_docv_capture_app_url
Copy link
Contributor

@amirbey amirbey Nov 27, 2024

Choose a reason for hiding this comment

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

since we've added the interstitial page ... it appears we no longer need the other instance variables below ... as opposed to cleaning up here. however, i think it'd be easier to rid of them in LG-14279

return
end

# document request
document_request = DocAuth::Socure::Requests::DocumentRequest.new(
redirect_url: idv_hybrid_mobile_socure_document_capture_update_url,
Expand All @@ -40,9 +45,6 @@ def show
return
end

document_capture_session = DocumentCaptureSession.find_by(
uuid: document_capture_session_uuid,
)
document_capture_session.socure_docv_transaction_token = document_response.dig(
:data,
:docvTransactionToken,
Expand Down
9 changes: 5 additions & 4 deletions app/controllers/idv/socure/document_capture_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def show
Funnel::DocAuth::RegisterStep.new(current_user.id, sp_session[:issuer]).
call('socure_document_capture', :view, true)

if document_capture_session.socure_docv_capture_app_url.present?
@url = document_capture_session.socure_docv_capture_app_url
Copy link
Contributor

Choose a reason for hiding this comment

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

since we've added the interstitial page ... it appears we no longer need the other instance variables below ... as opposed to cleaning up here. however, i think it'd be easier to rid of them in LG-14279

return
end

# document request
document_request = DocAuth::Socure::Requests::DocumentRequest.new(
redirect_url: idv_socure_document_capture_update_url,
Expand All @@ -50,10 +55,6 @@ def show
return
end

document_capture_session = DocumentCaptureSession.find_by(
uuid: document_capture_session_uuid,
)

document_capture_session.socure_docv_transaction_token = document_response.dig(
:data,
:docvTransactionToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,39 @@
expect(response).to redirect_to(idv_hybrid_mobile_socure_document_capture_errors_url)
end
end
context 'reuse of valid capture app urls when appropriate' do
let(:fake_capture_app_url) { 'https://verify.socure.test/fake_capture_app' }
let(:socure_capture_app_url) { 'https://verify.socure.test/' }
let(:docv_transaction_token) { '176dnc45d-2e34-46f3-82217-6f540ae90673' }
let(:response_body) do
{
referenceId: '123ab45d-2e34-46f3-8d17-6f540ae90303',
data: {
eventId: 'zoYgIxEZUbXBoocYAnbb5DrT',
docvTransactionToken: docv_transaction_token,
qrCode: 'data:image/png;base64,iVBO......K5CYII=',
url: socure_capture_app_url,
},
}
end

before do
allow(request_class).to receive(:new).and_call_original
allow(I18n).to receive(:locale).and_return(expected_language)
end

it 'does not create a DocumentRequest when valid capture app exists' do
dcs = create(
:document_capture_session,
uuid: user.id,
socure_docv_capture_app_url: fake_capture_app_url,
)
allow(DocumentCaptureSession).to receive(:find_by).and_return(dcs)
get(:show)
expect(request_class).not_to have_received(:new)
expect(dcs.socure_docv_capture_app_url).to eq(fake_capture_app_url)
end
end
end

describe '#update' do
Expand Down
34 changes: 34 additions & 0 deletions spec/controllers/idv/socure/document_capture_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,40 @@
expect(response).to redirect_to(idv_socure_document_capture_errors_url)
end
end

context 'reuse of valid capture app urls when appropriate' do
let(:fake_capture_app_url) { 'https://verify.socure.test/fake_capture_app' }
let(:socure_capture_app_url) { 'https://verify.socure.test/' }
let(:docv_transaction_token) { '176dnc45d-2e34-46f3-82217-6f540ae90673' }
let(:response_body) do
{
referenceId: '123ab45d-2e34-46f3-8d17-6f540ae90303',
data: {
eventId: 'zoYgIxEZUbXBoocYAnbb5DrT',
docvTransactionToken: docv_transaction_token,
qrCode: 'data:image/png;base64,iVBO......K5CYII=',
url: socure_capture_app_url,
},
}
end

before do
allow(request_class).to receive(:new).and_call_original
allow(I18n).to receive(:locale).and_return(expected_language)
end

it 'does not create a DocumentRequest when valid capture app exists' do
dcs = create(
:document_capture_session,
uuid: user.id,
socure_docv_capture_app_url: fake_capture_app_url,
)
allow(DocumentCaptureSession).to receive(:find_by).and_return(dcs)
get(:show)
expect(request_class).not_to have_received(:new)
expect(dcs.socure_docv_capture_app_url).to eq(fake_capture_app_url)
end
end
end

describe '#update' do
Expand Down
56 changes: 55 additions & 1 deletion spec/features/idv/doc_auth/socure_document_capture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,61 @@
end
end

context 'network connection errors', allow_browser_log: true do
context 'reuses valid capture app urls when appropriate', allow_browser_log: true do
context 'successfully erases capture app url when flow is complete' do
it 'proceeds to the next page with valid info' do
document_capture_session = DocumentCaptureSession.find_by(user_id: @user.id)
AShukla-GSA marked this conversation as resolved.
Show resolved Hide resolved
expect(document_capture_session.socure_docv_capture_app_url).
to eq(fake_socure_document_capture_app_url)
expect(page).to have_current_path(fake_socure_document_capture_app_url)
visit idv_socure_document_capture_path
expect(page).to have_current_path(idv_socure_document_capture_path)
document_capture_session.reload
expect(document_capture_session.socure_docv_capture_app_url).
to eq(fake_socure_document_capture_app_url)
socure_docv_upload_documents(
docv_transaction_token: @docv_transaction_token,
)
document_capture_session.reload
expect(document_capture_session.socure_docv_capture_app_url).to be_nil
end

it 'reuse capture app url when appropriate and creates new when not' do
document_capture_session = DocumentCaptureSession.find_by(user_id: @user.id)
AShukla-GSA marked this conversation as resolved.
Show resolved Hide resolved
expect(document_capture_session.socure_docv_capture_app_url).
to eq(fake_socure_document_capture_app_url)
expect(page).to have_current_path(fake_socure_document_capture_app_url)
visit idv_socure_document_capture_path
expect(page).to have_current_path(idv_socure_document_capture_path)
document_capture_session.reload
expect(document_capture_session.socure_docv_capture_app_url).
to eq(fake_socure_document_capture_app_url)
fake_capture_app2 = 'https://verify.fake-socure.test/capture2'
document_capture_session.socure_docv_capture_app_url = fake_capture_app2
document_capture_session.save
socure_docv_send_webhook(
docv_transaction_token: @docv_transaction_token,
event_type: 'DOCUMENT_FRONT_UPLOADED',
)
document_capture_session.reload
expect(document_capture_session.socure_docv_capture_app_url).
to eq(fake_capture_app2)
socure_docv_send_webhook(
docv_transaction_token: @docv_transaction_token,
event_type: 'SESSION_EXPIRED',
)
document_capture_session.reload
expect(document_capture_session.socure_docv_capture_app_url).to be_nil
visit idv_socure_document_capture_path
expect(page).to have_current_path(idv_socure_document_capture_path)
document_capture_session.reload
expect(document_capture_session.socure_docv_capture_app_url).
to eq(fake_socure_document_capture_app_url)
end
end
end

context 'network connection errors' do
context 'getting the capture path' do
before do
allow_any_instance_of(Faraday::Connection).to receive(:post).
Expand Down