-
Notifications
You must be signed in to change notification settings - Fork 166
LG-3423: Refactor doc capture (hybrid) polling to own endpoint #4293
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
+191
−29
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| module Idv | ||
| class CaptureDocStatusController < ApplicationController | ||
| before_action :confirm_two_factor_authenticated | ||
|
|
||
| respond_to :json | ||
|
|
||
| def show | ||
| result = if FeatureManagement.document_capture_step_enabled? | ||
| document_capture_session_poll_render_result | ||
| else | ||
| doc_capture_poll_render_result | ||
| end | ||
|
|
||
| render result | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def doc_capture_poll_render_result | ||
| doc_capture = DocCapture.find_by(user_id: current_user.id) | ||
| return { plain: 'Unauthorized', status: :unauthorized } if doc_capture.blank? | ||
| return { plain: 'Pending', status: :accepted } if doc_capture.acuant_token.blank? | ||
| { plain: 'Complete', status: :ok } | ||
| end | ||
|
|
||
| def document_capture_session_poll_render_result | ||
| session_uuid = flow_session[:document_capture_session_uuid] | ||
| document_capture_session = DocumentCaptureSession.find_by(uuid: session_uuid) | ||
| return { plain: 'Unauthorized', status: :unauthorized } unless document_capture_session | ||
|
|
||
| result = document_capture_session.load_result | ||
| return { plain: 'Pending', status: :accepted } if result.blank? | ||
| return { plain: 'Unauthorized', status: :unauthorized } unless result.success? | ||
| { plain: 'Complete', status: :ok } | ||
| end | ||
|
|
||
| def flow_session | ||
| user_session['idv/doc_auth'] | ||
| 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 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
149 changes: 149 additions & 0 deletions
149
spec/controllers/idv/capture_doc_status_controller_spec.rb
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,149 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe Idv::CaptureDocStatusController do | ||
| let(:user) { build(:user) } | ||
| let(:document_capture_step_enabled) { false } | ||
|
|
||
| before do | ||
| stub_sign_in(user) if user | ||
|
|
||
| allow(FeatureManagement).to receive(:document_capture_step_enabled?). | ||
| and_return(document_capture_step_enabled) | ||
| end | ||
|
|
||
| describe '#show' do | ||
| context 'when unauthenticated' do | ||
| let(:user) { nil } | ||
|
|
||
| it 'redirects to the root url' do | ||
| get :show | ||
|
|
||
| expect(response).to redirect_to root_url | ||
| end | ||
| end | ||
|
|
||
| context 'when document capture step is disabled' do | ||
| let(:document_capture_step_enabled) { false } | ||
| let(:doc_capture) { nil } | ||
|
|
||
| before do | ||
| allow(DocCapture).to receive(:find_by).and_return(doc_capture) | ||
| end | ||
|
|
||
| context 'when session does not exist' do | ||
| let(:doc_capture) { nil } | ||
|
|
||
| it 'returns unauthorized' do | ||
| get :show | ||
|
|
||
| expect(response.status).to eq(401) | ||
| expect(response.body).to eq('Unauthorized') | ||
| end | ||
| end | ||
|
|
||
| context 'when result is pending' do | ||
| let(:doc_capture) do | ||
| DocCapture.create( | ||
| user_id: user.id, | ||
| request_token: SecureRandom.uuid, | ||
| requested_at: Time.zone.now, | ||
| ) | ||
| end | ||
|
|
||
| it 'returns pending result' do | ||
| get :show | ||
|
|
||
| expect(response.status).to eq(202) | ||
| expect(response.body).to eq('Pending') | ||
| end | ||
| end | ||
|
|
||
| context 'when capture is complete' do | ||
| let(:doc_capture) do | ||
| DocCapture.create( | ||
| user_id: user.id, | ||
| request_token: SecureRandom.uuid, | ||
| requested_at: Time.zone.now, | ||
| acuant_token: SecureRandom.uuid, | ||
| ) | ||
| end | ||
|
|
||
| it 'returns success' do | ||
| get :show | ||
|
|
||
| expect(response.status).to eq(200) | ||
| expect(response.body).to eq('Complete') | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'when document capture step is enabled' do | ||
| let(:document_capture_step_enabled) { true } | ||
| let(:document_capture_session) { DocumentCaptureSession.create! } | ||
| let(:flow_session) { { document_capture_session_uuid: document_capture_session.uuid } } | ||
|
|
||
| before do | ||
| allow_any_instance_of(Flow::BaseFlow).to receive(:flow_session).and_return(flow_session) | ||
| controller.user_session['idv/doc_auth'] = flow_session | ||
| end | ||
|
|
||
| context 'when session does not exist' do | ||
| let(:flow_session) { {} } | ||
|
|
||
| it 'returns unauthorized' do | ||
| get :show | ||
|
|
||
| expect(response.status).to eq(401) | ||
| expect(response.body).to eq('Unauthorized') | ||
| end | ||
| end | ||
|
|
||
| context 'when result is pending' do | ||
| it 'returns pending result' do | ||
| get :show | ||
|
|
||
| expect(response.status).to eq(202) | ||
| expect(response.body).to eq('Pending') | ||
| end | ||
| end | ||
|
|
||
| context 'when capture failed' do | ||
| before do | ||
| allow(EncryptedRedisStructStorage).to receive(:load).and_return( | ||
| DocumentCaptureSessionResult.new( | ||
| id: SecureRandom.uuid, | ||
| success: false, | ||
| pii: {}, | ||
| ), | ||
| ) | ||
| end | ||
|
|
||
| it 'returns unauthorized' do | ||
| get :show | ||
|
|
||
| expect(response.status).to eq(401) | ||
| expect(response.body).to eq('Unauthorized') | ||
| end | ||
| end | ||
|
|
||
| context 'when capture succeeded' do | ||
| before do | ||
| allow(EncryptedRedisStructStorage).to receive(:load).and_return( | ||
| DocumentCaptureSessionResult.new( | ||
| id: SecureRandom.uuid, | ||
| success: true, | ||
| pii: {}, | ||
| ), | ||
| ) | ||
| end | ||
|
|
||
| it 'returns success' do | ||
| get :show | ||
|
|
||
| expect(response.status).to eq(200) | ||
| expect(response.body).to eq('Complete') | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
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.
Uh oh!
There was an error while loading. Please reload this page.