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
13 changes: 13 additions & 0 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,19 @@ def idv_in_person_prepare_submitted(flow_path:, in_person_cta_variant:, **extra)
)
end

# @param [String] nontransliterable_characters
# Nontransliterable characters submitted by user
def idv_in_person_proofing_nontransliterable_characters_submitted(
nontransliterable_characters:,
**extra
)
track_event(
'IdV: in person proofing characters submitted could not be transliterated',
nontransliterable_characters: nontransliterable_characters,
**extra,
)
end

def idv_in_person_proofing_residential_address_submitted(**extra)
track_event('IdV: in person proofing residential address submitted', **extra)
end
Expand Down
14 changes: 13 additions & 1 deletion app/services/usps_in_person_proofing/transliterable_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def initialize(options)
# @param [ActiveModel::Validations] record
def validate(record)
return unless IdentityConfig.store.usps_ipp_transliteration_enabled

nontransliterable_chars = Set.new
@fields.each do |field|
next unless record.respond_to?(field)

Expand All @@ -42,12 +42,20 @@ def validate(record)
invalid_chars = get_invalid_chars(value)
next unless invalid_chars.present?

nontransliterable_chars += invalid_chars

record.errors.add(
field,
:nontransliterable_field,
message: get_error_message(invalid_chars),
)
end

if nontransliterable_chars.present?
analytics.idv_in_person_proofing_nontransliterable_characters_submitted(
nontransliterable_characters: nontransliterable_chars.sort,
)
end
end

def transliterator
Expand Down Expand Up @@ -87,5 +95,9 @@ def get_invalid_chars(value)
# Create sorted list of unique unsupported characters
(result.unsupported_chars + additional_chars).sort.uniq
end

def analytics(user: AnonymousUser.new)
Analytics.new(user: user, request: nil, session: {}, sp: nil)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@

context 'failing transliteration' do
let(:invalid_field) { 'def' }
let(:analytics) { FakeAnalytics.new }

before do
allow(validator).to receive(:analytics).and_return(analytics)
allow(validator.transliterator).to receive(:transliterate).with('def').
and_return(
UspsInPersonProofing::Transliterator::TransliterationResult.new(
Expand All @@ -128,6 +130,15 @@
expect(error.type).to eq(:nontransliterable_field)
expect(error.options[:message]).to eq(message)
end

it 'logs nontransliterable characters' do
validator.validate(model)

expect(analytics).to have_logged_event(
'IdV: in person proofing characters submitted could not be transliterated',
nontransliterable_characters: ['*', '3', 'C'],
)
end
end

context 'with callable error message' do
Expand Down Expand Up @@ -210,13 +221,27 @@
let(:fields) { [:other_invalid_field, :valid_field, :invalid_field] }
let(:invalid_field) { '123' }
let(:other_invalid_field) { "\#@$%" }
let(:analytics) { FakeAnalytics.new }

before do
allow(validator).to receive(:analytics).and_return(analytics)
end

it 'sets multiple validation messages' do
validator.validate(model)

expect(errors).to include(:invalid_field)
expect(errors).to include(:other_invalid_field)
end

it 'logs nontransliterable characters' do
validator.validate(model)

expect(analytics).to have_logged_event(
'IdV: in person proofing characters submitted could not be transliterated',
nontransliterable_characters: ['#', '$', '%', '1', '2', '3', '@'],
)
end
end
end

Expand Down