Skip to content

Commit

Permalink
97295 Debt team invalid date
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaldrk committed Nov 18, 2024
1 parent b150d7c commit df19b56
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ def joined_filtered_expenses

def get_discharged_date
raw_date = @bankruptcy['date_discharged']

return '00/0000' if raw_date.blank?

date_object = Date.parse(raw_date)

"#{date_object.strftime('%m')}/#{date_object.year}"
rescue Date::Error => e
Rails.logger.error("DebtsApi AdditionalDataCalculator#get_discharge_date: #{e.message}")
Rails.logger.info(
"DebtsApi AdditionalDataCalculator#get_discharge_date input: #{@bankruptcy['date_discharged']}"
)

'00/0000'
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'rails_helper'

Check failure on line 1 in modules/debts_api/spec/lib/debt_api/v0/fsr_form_transform/additional_data_calculator_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Style/FrozenStringLiteralComment: Missing frozen string literal comment.
require 'debts_api/v0/fsr_form_transform/additional_data_calculator'

RSpec.describe DebtsApi::V0::FsrFormTransform::AdditionalDataCalculator, type: :service do
describe 'get_bankruptcy_data' do
let(:form) { get_fixture_absolute('modules/debts_api/spec/fixtures/pre_submission_fsr/pre_transform') }

it 'returns bankruptcy data' do
service = described_class.new(form)

expect(service.get_bankruptcy_data).to eq({
'hasBeenAdjudicatedBankrupt' => true,

Check failure on line 12 in modules/debts_api/spec/lib/debt_api/v0/fsr_form_transform/additional_data_calculator_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/FirstHashElementIndentation: Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
'dateDischarged' => '02/2020',
'courtLocation' => 'fdas',
'docketNumber' => 'dfasa'
})

Check failure on line 16 in modules/debts_api/spec/lib/debt_api/v0/fsr_form_transform/additional_data_calculator_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/FirstHashElementIndentation: Indent the right brace the same as the first position after the preceding left parenthesis.
end

it 'handles empty date for date discharged' do
form['additional_data']['bankruptcy']['date_discharged'] = ''
service = described_class.new(form)

expect(service.get_bankruptcy_data['dateDischarged']).to eq('00/0000')
end

it 'handles bad date for date discharged' do
form['additional_data']['bankruptcy']['date_discharged'] = 'this is not a date'
expect(Rails.logger).to receive(:error).with('DebtsApi AdditionalDataCalculator#get_discharge_date: invalid date')
expect(Rails.logger).to receive(:info).with('DebtsApi AdditionalDataCalculator#get_discharge_date input: this is not a date')

Check failure on line 29 in modules/debts_api/spec/lib/debt_api/v0/fsr_form_transform/additional_data_calculator_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/LineLength: Line is too long. [131/120]
service = described_class.new(form)

expect(service.get_bankruptcy_data['dateDischarged']).to eq('00/0000')
end
end
end

0 comments on commit df19b56

Please sign in to comment.