diff --git a/spec/controllers/two_factor_authentication/sms_opt_in_controller_spec.rb b/spec/controllers/two_factor_authentication/sms_opt_in_controller_spec.rb index cb5983b890d..6b93bd08245 100644 --- a/spec/controllers/two_factor_authentication/sms_opt_in_controller_spec.rb +++ b/spec/controllers/two_factor_authentication/sms_opt_in_controller_spec.rb @@ -53,8 +53,6 @@ end context 'when loaded while adding a new phone' do - render_views - let(:user) { create(:user) } let(:phone) { Faker::PhoneNumber.cell_phone_in_e164 } let(:opt_out_uuid) { PhoneNumberOptOut.create_or_find_with_phone(phone).uuid } diff --git a/spec/features/two_factor_authentication/sign_in_spec.rb b/spec/features/two_factor_authentication/sign_in_spec.rb index 560f65eb5aa..ed9c9a1900a 100644 --- a/spec/features/two_factor_authentication/sign_in_spec.rb +++ b/spec/features/two_factor_authentication/sign_in_spec.rb @@ -59,6 +59,35 @@ end end + context 'with a number that has opted out of SMS delivery' do + let(:user) { create(:user, :with_phone) } + let(:phone_configuration) { user.phone_configurations.first } + + before do + PhoneNumberOptOut.create_or_find_with_phone(phone_configuration.phone) + opt_out_manager = instance_double('Telephony::Pinpoint::OptOutManager') + allow(opt_out_manager). + to receive(:opt_in_phone_number). + with(phone_configuration.formatted_phone). + and_return(FormResponse.new(success: true)) + allow_any_instance_of(TwoFactorAuthentication::SmsOptInController). + to receive(:opt_out_manager).and_return(opt_out_manager) + end + + scenario 'renders the sms opt-out error screen when signing in' do + sign_in_before_2fa(user) + + expect(page).to have_content(t('two_factor_authentication.opt_in.title')) + + click_button t('forms.buttons.send_one_time_code') + + fill_in_code_with_last_phone_otp + click_submit_default + + expect(page).to have_current_path(account_path) + end + end + context 'with international phone that does not support voice delivery' do scenario 'updates international code as user types', :js do sign_in_before_2fa