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

Create a phone step spec #2103

Merged
merged 2 commits into from
Apr 16, 2018
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
4 changes: 0 additions & 4 deletions spec/features/idv/cancel_idv_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
it_behaves_like 'cancel at idv step', :address, :saml
end

xcontext 'phone step' do
# Phone step doesn't have a cancel button :(
end

xcontext 'phone otp delivery method selection step' do
# Phone OTP delivery method step doesn't have a cancel button :(
end
Expand Down
6 changes: 0 additions & 6 deletions spec/features/idv/failed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
include IdvStepHelper

context 'profile job' do
let(:idv_job_class) { Idv::ProfileJob }
it_behaves_like 'failed idv job', :profile
end

context 'phone job' do
let(:idv_job_class) { Idv::PhoneJob }
it_behaves_like 'failed idv job', :phone
end
end
6 changes: 0 additions & 6 deletions spec/features/idv/max_attempts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,4 @@
it_behaves_like 'verification step max attempts', :profile, :oidc
it_behaves_like 'verification step max attempts', :profile, :saml
end

context 'phone step' do
it_behaves_like 'verification step max attempts', :phone
it_behaves_like 'verification step max attempts', :phone, :oidc
it_behaves_like 'verification step max attempts', :phone, :saml
end
end
94 changes: 94 additions & 0 deletions spec/features/idv/steps/phone_step_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
require 'rails_helper'

feature 'idv profile step', :idv_job do
include IdvStepHelper

context 'with valid information' do
it 'allows the user to continue to the phone otp delivery selection step' do
start_idv_from_sp
complete_idv_steps_before_phone_step
fill_out_phone_form_ok
click_idv_continue

expect(page).to have_content(t('idv.titles.otp_delivery_method'))
expect(page).to have_current_path(verify_otp_delivery_method_path)
end
end

context 'after submitting valid information' do
it 'is re-entrant before confirming OTP' do
first_phone_number = '5551231234'
second_phone_number = '5557897890'

start_idv_from_sp
complete_idv_steps_before_phone_step
fill_out_phone_form_ok(first_phone_number)
click_idv_continue
choose_idv_otp_delivery_method_sms

expect(page).to have_content(first_phone_number)

click_link t('forms.two_factor.try_again')

expect(page).to have_content(t('idv.titles.session.phone'))
expect(page).to have_current_path(verify_phone_path)

fill_out_phone_form_ok(second_phone_number)
click_idv_continue
choose_idv_otp_delivery_method_sms

expect(page).to have_content(second_phone_number)
end

it 'is not re-entrant after confirming OTP' do
user = user_with_2fa

start_idv_from_sp
complete_idv_steps_before_phone_step(user)
fill_out_phone_form_ok
click_idv_continue
choose_idv_otp_delivery_method_sms
enter_correct_otp_code_for_user(user)

visit verify_phone_path
expect(page).to have_content(t('idv.titles.session.review'))
expect(page).to have_current_path(verify_review_path)

fill_in 'Password', with: user_password
click_continue

# Currently this byasses the confirmation step since that is only
# accessible once
visit verify_phone_path
expect(page).to_not have_current_path(verify_phone_path)
end
end

it 'does not allow the user to advance without completing' do
start_idv_from_sp
complete_idv_steps_before_phone_step

# Try to skip ahead to review step
visit verify_review_path
# Get redirected to the address step (which leads to phone step)
expect(page).to have_current_path(verify_address_path)
end

xcontext 'cancelling IdV' do
# The phone step does not have any cancel behavior :(
end

context "when the user's information cannot be verified" do
it_behaves_like 'fail to verify idv info', :phone
end

context 'when the IdV background job fails' do
it_behaves_like 'failed idv job', :phone
end

context 'after the max number of attempts' do
it_behaves_like 'verification step max attempts', :phone
it_behaves_like 'verification step max attempts', :phone, :oidc
it_behaves_like 'verification step max attempts', :phone, :saml
end
end
132 changes: 132 additions & 0 deletions spec/support/idv_examples/fail_to_verify.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
shared_examples 'fail to verify idv info' do |step|
let(:step_locale_key) do
return :sessions if step == :profile
step
end

before do
start_idv_from_sp
complete_idv_steps_before_step(step)
fill_out_idv_form_fail if step == :profile
fill_out_phone_form_fail if step == :phone
click_continue
end

context 'without js' do
it 'renders a flash message and lets the user try again' do
expect_page_to_have_warning_message
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

fill_out_idv_form_ok if step == :profile
fill_out_phone_form_ok if step == :phone
click_idv_continue

expect(page).to have_content(t('idv.titles.select_verification')) if step == :profile
expect(page).to have_current_path(verify_address_path) if step == :profile
expect(page).to have_content(t('idv.titles.otp_delivery_method')) if step == :phone
expect(page).to have_current_path(verify_otp_delivery_method_path) if step == :phone
end
end

context 'with js', :js do
it 'renders a modal and lets the user try again' do
expect_page_to_have_warning_modal
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

dismiss_warning_modal
fill_out_idv_form_ok if step == :profile
fill_out_phone_form_ok if step == :phone
click_idv_continue

expect(page).to have_content(t('idv.titles.select_verification')) if step == :profile
expect(page).to have_current_path(verify_address_path) if step == :profile
expect(page).to have_content(t('idv.titles.otp_delivery_method')) if step == :phone
expect(page).to have_current_path(verify_otp_delivery_method_path) if step == :phone
end
end

def expect_page_to_have_warning_message
expect(page).to have_content t("idv.modal.#{step_locale_key}.heading")
expect(page).to have_content t("idv.modal.#{step_locale_key}.warning")
end

def expect_page_to_have_warning_modal
expect(page).to have_css('.modal-warning', text: t("idv.modal.#{step_locale_key}.heading"))
expect(page).to have_css(
'.modal-warning',
text: strip_tags(t("idv.modal.#{step_locale_key}.warning"))
)
end

def dismiss_warning_modal
click_button t('idv.modal.button.warning')
end
end
shared_examples 'fail to verify idv info' do |step|
let(:step_locale_key) do
return :sessions if step == :profile
step
end

before do
start_idv_from_sp
complete_idv_steps_before_step(step)
fill_out_idv_form_fail if step == :profile
fill_out_phone_form_fail if step == :phone
click_continue
end

context 'without js' do
it 'renders a flash message and lets the user try again' do
expect_page_to_have_warning_message
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

fill_out_idv_form_ok if step == :profile
fill_out_phone_form_ok if step == :phone
click_idv_continue

expect(page).to have_content(t('idv.titles.select_verification')) if step == :profile
expect(page).to have_current_path(verify_address_path) if step == :profile
expect(page).to have_content(t('idv.titles.otp_delivery_method')) if step == :phone
expect(page).to have_current_path(verify_otp_delivery_method_path) if step == :phone
end
end

context 'with js', :js do
it 'renders a modal and lets the user try again' do
expect_page_to_have_warning_modal
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

dismiss_warning_modal
fill_out_idv_form_ok if step == :profile
fill_out_phone_form_ok if step == :phone
click_idv_continue

expect(page).to have_content(t('idv.titles.select_verification')) if step == :profile
expect(page).to have_current_path(verify_address_path) if step == :profile
expect(page).to have_content(t('idv.titles.otp_delivery_method')) if step == :phone
expect(page).to have_current_path(verify_otp_delivery_method_path) if step == :phone
end
end

def expect_page_to_have_warning_message
expect(page).to have_content t("idv.modal.#{step_locale_key}.heading")
expect(page).to have_content t("idv.modal.#{step_locale_key}.warning")
end

def expect_page_to_have_warning_modal
expect(page).to have_css('.modal-warning', text: t("idv.modal.#{step_locale_key}.heading"))
expect(page).to have_css(
'.modal-warning',
text: strip_tags(t("idv.modal.#{step_locale_key}.warning"))
)
end

def dismiss_warning_modal
click_button t('idv.modal.button.warning')
end
end
4 changes: 4 additions & 0 deletions spec/support/idv_examples/failed_idv_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
shared_examples 'failed idv job' do |step|
let(:idv_job_class) do
return Idv::ProfileJob if step == :profile
return Idv::PhoneJob if step == :phone
end
let(:step_locale_key) do
return :sessions if step == :profile
step
Expand Down