-
Notifications
You must be signed in to change notification settings - Fork 118
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
Test failed and timed out jobs in shared examples #2097
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
becec7b
Test failed and timed out jobs in shared examples
jmhooper 44902a0
Merge branch 'master' into jmhooper-failed-job-shared-examples
jmhooper 6c913c1
use idv step helpers from master
jmhooper 85d8163
Merge branch 'master' into jmhooper-failed-job-shared-examples
jmhooper deac0a4
add strip tags helper
jmhooper 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 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 |
---|---|---|
@@ -1,25 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
feature 'IdV session' do | ||
include IdvHelper | ||
feature 'IdV session', :idv_job do | ||
include IdvStepHelper | ||
|
||
context 'Idv job raises an error', idv_job: true do | ||
it 'displays a warning that something went wrong' do | ||
sign_in_and_2fa_user | ||
|
||
step = instance_double( | ||
Idv::ProfileStep, attempts_exceeded?: false, vendor_validator_job_failed?: true | ||
) | ||
allow(Idv::ProfileStep).to receive(:new).and_return(step) | ||
allow(step).to receive(:submit). | ||
and_return(FormResponse.new(success: false, errors: {}, extra: {})) | ||
|
||
visit verify_session_path | ||
fill_out_idv_form_ok | ||
click_idv_continue | ||
context 'profile job' do | ||
let(:idv_job_class) { Idv::ProfileJob } | ||
it_behaves_like 'failed idv job', :profile | ||
end | ||
|
||
expect(page).to have_current_path(verify_session_result_path) | ||
expect(page).to have_content t('idv.modal.sessions.jobfail') | ||
end | ||
context 'phone job' do | ||
let(:idv_job_class) { Idv::PhoneJob } | ||
it_behaves_like 'failed idv job', :phone | ||
end | ||
end |
This file contains 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,102 @@ | ||
shared_examples 'failed idv job' do |step| | ||
let(:step_locale_key) do | ||
return :sessions if step == :profile | ||
step | ||
end | ||
|
||
before do | ||
visit_idp_from_sp_with_loa3(:oidc) | ||
click_link t('links.sign_in') | ||
complete_idv_steps_before_step(step) | ||
end | ||
|
||
context 'the job raises an error' do | ||
before do | ||
stub_idv_job_to_raise_error_in_background(idv_job_class) | ||
|
||
fill_out_idv_form_ok if step == :profile | ||
fill_out_phone_form_ok if step == :phone | ||
click_idv_continue | ||
end | ||
|
||
context 'without js' do | ||
it 'shows a warning' do | ||
expect(page).to have_content t("idv.modal.#{step_locale_key}.heading") | ||
expect(page).to have_content t("idv.modal.#{step_locale_key}.jobfail") | ||
expect(page).to have_current_path(verify_session_result_path) if step == :profile | ||
expect(page).to have_current_path(verify_phone_result_path) if step == :phone | ||
end | ||
end | ||
|
||
context 'with js', :js do | ||
it 'shows a modal' do | ||
expect(page).to have_css('.modal-warning', text: t("idv.modal.#{step_locale_key}.heading")) | ||
expect(page).to have_css( | ||
'.modal-warning', | ||
text: ActionController::Base.helpers.strip_tags(t("idv.modal.#{step_locale_key}.jobfail")) | ||
) | ||
expect(page).to have_current_path(verify_session_result_path) if step == :profile | ||
expect(page).to have_current_path(verify_phone_result_path) if step == :phone | ||
end | ||
end | ||
end | ||
|
||
context 'the job times out' do | ||
before do | ||
stub_idv_job_to_timeout_in_background(idv_job_class) | ||
|
||
fill_out_idv_form_ok if step == :profile | ||
fill_out_phone_form_ok('5202691958') if step == :phone | ||
click_idv_continue | ||
|
||
Timecop.travel (Figaro.env.async_job_refresh_max_wait_seconds.to_i + 1).seconds | ||
|
||
visit current_path | ||
end | ||
|
||
after do | ||
Timecop.return | ||
end | ||
|
||
context 'without js' do | ||
it 'shows a warning' do | ||
expect(page).to have_content t("idv.modal.#{step_locale_key}.heading") | ||
expect(page).to have_content t("idv.modal.#{step_locale_key}.timeout") | ||
expect(page).to have_current_path(verify_session_result_path) if step == :profile | ||
expect(page).to have_current_path(verify_phone_result_path) if step == :phone | ||
end | ||
end | ||
|
||
context 'with js' do | ||
it 'shows a modal' do | ||
expect(page).to have_css('.modal-warning', text: t("idv.modal.#{step_locale_key}.heading")) | ||
expect(page).to have_css( | ||
'.modal-warning', | ||
text: ActionController::Base.helpers.strip_tags(t("idv.modal.#{step_locale_key}.timeout")) | ||
) | ||
expect(page).to have_current_path(verify_session_result_path) if step == :profile | ||
expect(page).to have_current_path(verify_phone_result_path) if step == :phone | ||
end | ||
end | ||
end | ||
|
||
def stub_idv_job_to_raise_error_in_background(idv_job_class) | ||
allow(idv_job_class).to receive(:new).and_wrap_original do |new, *args| | ||
idv_job = new.call(*args) | ||
allow(idv_job).to receive(:verify_identity_with_vendor). | ||
and_raise('this is a test error') | ||
idv_job | ||
end | ||
allow(idv_job_class).to receive(:perform_now).and_wrap_original do |perform_now, *args| | ||
begin | ||
perform_now.call(*args) | ||
rescue StandardError => err | ||
# Swallow the error so it does not get re-raised by the job | ||
end | ||
end | ||
end | ||
|
||
def stub_idv_job_to_timeout_in_background(idv_job_class) | ||
allow(idv_job_class).to receive(:perform_now) | ||
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.
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.
What do you think about adding a helper method for
strip_tags
like you did in the other PR, so that it can be used in various tests?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.
Yeah, didn't remember that it was also here. Will do once I merge that one.