From 4c26d8055bf804d55f0a382240817ddf09585e64 Mon Sep 17 00:00:00 2001 From: Viktor Date: Thu, 9 Nov 2023 12:54:23 +0200 Subject: [PATCH] Fix code and specs --- lib/cfonb/operation_detail/mmo.rb | 3 ++- spec/cfonb/operation_spec.rb | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/cfonb/operation_detail/mmo.rb b/lib/cfonb/operation_detail/mmo.rb index 07412bc..d461df1 100644 --- a/lib/cfonb/operation_detail/mmo.rb +++ b/lib/cfonb/operation_detail/mmo.rb @@ -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) diff --git a/spec/cfonb/operation_spec.rb b/spec/cfonb/operation_spec.rb index 6a92d36..24d3ab0 100644 --- a/spec/cfonb/operation_spec.rb +++ b/spec/cfonb/operation_spec.rb @@ -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