Skip to content
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
2 changes: 1 addition & 1 deletion app/controllers/idv/otp_delivery_method_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def handle_send_phone_confirmation_otp_failure(result)

def save_delivery_preference
original_session = idv_session.user_phone_confirmation_session
idv_session.user_phone_confirmation_session = PhoneConfirmation::ConfirmationSession.new(
idv_session.user_phone_confirmation_session = Idv::PhoneConfirmationSession.new(
code: original_session.code,
phone: original_session.phone,
sent_at: original_session.sent_at,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module PhoneConfirmation
class ConfirmationSession
module Idv
class PhoneConfirmationSession
attr_reader :code, :phone, :sent_at, :delivery_method

def self.generate_code
OtpCodeGenerator.generate_alphanumeric_digits(
TwoFactorAuthenticatable::PROOFING_DIRECT_OTP_LENGTH,
)
end

def initialize(code:, phone:, sent_at:, delivery_method:)
@code = code
@phone = phone
Expand All @@ -11,7 +17,7 @@ def initialize(code:, phone:, sent_at:, delivery_method:)

def self.start(phone:, delivery_method:)
new(
code: CodeGenerator.call,
code: generate_code,
phone: phone,
sent_at: Time.zone.now,
delivery_method: delivery_method,
Expand All @@ -20,7 +26,7 @@ def self.start(phone:, delivery_method:)

def regenerate_otp
self.class.new(
code: CodeGenerator.call,
code: self.class.generate_code,
phone: phone,
sent_at: Time.zone.now,
delivery_method: delivery_method,
Expand Down
2 changes: 1 addition & 1 deletion app/services/idv/phone_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def update_idv_session
end

def start_phone_confirmation_session
idv_session.user_phone_confirmation_session = PhoneConfirmation::ConfirmationSession.start(
idv_session.user_phone_confirmation_session = Idv::PhoneConfirmationSession.start(
phone: PhoneFormatter.format(applicant[:phone]),
delivery_method: :sms,
)
Expand Down
2 changes: 1 addition & 1 deletion app/services/idv/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def address_mechanism_chosen?
def user_phone_confirmation_session
session_value = session[:user_phone_confirmation_session]
return if session_value.blank?
PhoneConfirmation::ConfirmationSession.from_h(session_value)
Idv::PhoneConfirmationSession.from_h(session_value)
end

def user_phone_confirmation_session=(new_user_phone_confirmation_session)
Expand Down
11 changes: 0 additions & 11 deletions app/services/phone_confirmation/code_generator.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
subject.idv_session.address_verification_mechanism = 'phone'
subject.idv_session.vendor_phone_confirmation = true
subject.idv_session.user_phone_confirmation = false
user_phone_confirmation_session = PhoneConfirmation::ConfirmationSession.start(
user_phone_confirmation_session = Idv::PhoneConfirmationSession.start(
phone: valid_phone_number,
delivery_method: :sms,
)
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/idv/otp_verification_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let(:phone_confirmation_otp_code) { '777777' }
let(:phone_confirmation_otp_sent_at) { Time.zone.now }
let(:user_phone_confirmation_session) do
PhoneConfirmation::ConfirmationSession.new(
Idv::PhoneConfirmationSession.new(
code: phone_confirmation_otp_code,
phone: phone,
sent_at: phone_confirmation_otp_sent_at,
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/idv/resend_otp_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:user_phone_confirmation) { false }
let(:delivery_method) { 'sms' }
let(:user_phone_confirmation_session) do
PhoneConfirmation::ConfirmationSession.start(
Idv::PhoneConfirmationSession.start(
phone: phone,
delivery_method: delivery_method,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:phone_confirmation_otp_sent_at) { Time.zone.now }
let(:phone_confirmation_otp_code) { '123456' }
let(:user_phone_confirmation_session) do
PhoneConfirmation::ConfirmationSession.new(
Idv::PhoneConfirmationSession.new(
code: phone_confirmation_otp_code,
phone: phone,
sent_at: phone_confirmation_otp_sent_at,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe PhoneConfirmation::ConfirmationSession do
RSpec.describe Idv::PhoneConfirmationSession do
describe '.start' do
it 'starts a session for voice' do
result = described_class.start(
Expand Down
6 changes: 2 additions & 4 deletions spec/services/idv/send_phone_confirmation_otp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:delivery_preference) { :sms }
let(:otp_code) { '777777' }
let(:user_phone_confirmation_session) do
PhoneConfirmation::ConfirmationSession.new(
Idv::PhoneConfirmationSession.new(
code: '123456',
phone: phone,
sent_at: Time.zone.now,
Expand All @@ -26,9 +26,7 @@
# Setup Idv::Session
idv_session.user_phone_confirmation_session = user_phone_confirmation_session

# Mock PhoneConfirmation::CodeGenerator
allow(PhoneConfirmation::CodeGenerator).to receive(:call).
and_return(otp_code)
allow(Idv::PhoneConfirmationSession).to receive(:generate_code).and_return(otp_code)

# Mock OtpRateLimiter
allow(OtpRateLimiter).to receive(:new).with(user: user, phone: phone, phone_confirmed: true).
Expand Down