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
10 changes: 7 additions & 3 deletions app/services/doc_auth/lexis_nexis/responses/true_id_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,13 @@ def transform_metrics(img_metrics)
end

def parse_date(year:, month:, day:)
if year.to_i.positive? && month.to_i.positive? && day.to_i.positive?
Date.new(year.to_i, month.to_i, day.to_i).to_s
end
Date.new(year.to_i, month.to_i, day.to_i).to_s if year.to_i.positive?
rescue ArgumentError
message = {
event: 'Failure to parse TrueID date',
}.to_json
Rails.logger.info(message)
nil
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,25 @@
end
end

describe '#parse_date' do
let(:response) { described_class.new(success_response, false, config) }

it 'handles an invalid month' do
expect(Rails.logger).to receive(:info)
expect(response.send(:parse_date, year: 2022, month: 13, day: 1)).to eq(nil)
end

it 'handles an invalid leap day' do
expect(Rails.logger).to receive(:info)
expect(response.send(:parse_date, year: 2022, month: 2, day: 29)).to eq(nil)
end

it 'handles a day past the end of the month' do
expect(Rails.logger).to receive(:info)
expect(response.send(:parse_date, year: 2022, month: 4, day: 31)).to eq(nil)
end
end

describe '#attention_with_barcode?' do
let(:response) { described_class.new(success_response, false, config) }
subject(:attention_with_barcode) { response.attention_with_barcode? }
Expand Down