Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
vnovitskyi committed Nov 17, 2023
1 parent 87a40f2 commit 8b03d14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cfonb/operation_detail/mmo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def self.apply(operation, line)

operation.original_amount = sign * BigDecimal(line.detail[4..17]) / (10**scale)
exchange_rate_value = line.detail[26..29]
return if exchange_rate_value.nil? || exchange_rate_value.empty?

return if exchange_rate_value.nil? || exchange_rate_value.strip.empty?

exchange_rate_scale = line.detail[18]
operation.exchange_rate = BigDecimal(exchange_rate_value) / (10**BigDecimal(exchange_rate_scale))
Expand Down
14 changes: 14 additions & 0 deletions spec/cfonb/operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@
)
end
end

context 'when exchange rate is missing' do
let(:detail) { OpenStruct.new(body: '', detail_code: 'MMO', detail: 'EUR200000001875625 04') }

it 'Adds the original currency information' do
operation.merge_detail(detail)

expect(operation).to have_attributes(
original_currency: 'EUR',
original_amount: -18_756.25,
exchange_rate: nil,
)
end
end
end

context 'with a NPY detail' do
Expand Down

0 comments on commit 8b03d14

Please sign in to comment.