Skip to content

Commit

Permalink
Fix code and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
vnovitskyi committed Nov 9, 2023
1 parent 1f7b6b9 commit 4c26d80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/cfonb/operation_detail/mmo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def self.apply(operation, line)
sign = operation.amount <=> 0 # the detail amount is unsigned

operation.original_amount = sign * BigDecimal(line.detail[4..17]) / (10**scale)
operation.exchange_rate = BigDecimal(line.detail[-4..-1]) / 1000
exchange_rate_value = line.detail[26..29]
operation.exchange_rate = BigDecimal(exchange_rate_value) / 1000 if exchange_rate_value
end

CFONB::OperationDetail.register('MMO', self)
Expand Down
20 changes: 17 additions & 3 deletions spec/cfonb/operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,31 @@
end

context 'with a MMO detail' do
let(:detail) { OpenStruct.new(body: '', detail_code: 'MMO', detail: 'USD000000000008358300000001077') }
let(:detail) { OpenStruct.new(body: '', detail_code: 'MMO', detail: 'USD200000000001234') }

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

expect(operation).to have_attributes(
original_currency: 'USD',
original_amount: -8358,
exchange_rate: 1.077,
original_amount: -12.34,
exchange_rate: nil,
)
end

context 'with exchange rate' do
let(:detail) { OpenStruct.new(body: '', detail_code: 'MMO', detail: 'USD000000000008358300000001077') }

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

expect(operation).to have_attributes(
original_currency: 'USD',
original_amount: -8358,
exchange_rate: 1.077,
)
end
end
end

context 'with a NPY detail' do
Expand Down

0 comments on commit 4c26d80

Please sign in to comment.