2017-01-26 13:27:30 +01:00
|
|
|
require_relative '../spec_helper'
|
|
|
|
|
|
|
|
describe BankTransactionReference do
|
|
|
|
it 'returns nil for empty input' do
|
2022-05-27 21:57:06 +02:00
|
|
|
expect(BankTransactionReference.parse('')).to be_nil
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for invalid string' do
|
2022-05-27 21:57:06 +02:00
|
|
|
expect(BankTransactionReference.parse('invalid')).to be_nil
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for FS1A' do
|
2022-05-27 21:57:06 +02:00
|
|
|
expect(BankTransactionReference.parse('FS1A')).to be_nil
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for FS1.1A' do
|
2022-05-27 21:57:06 +02:00
|
|
|
expect(BankTransactionReference.parse('FS1.1A')).to be_nil
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for xFS1A1' do
|
2022-05-27 21:57:06 +02:00
|
|
|
expect(BankTransactionReference.parse('xFS1A1')).to be_nil
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
2021-02-08 03:39:47 +01:00
|
|
|
it 'returns nil for .FS1A1' do
|
2022-05-27 21:57:06 +02:00
|
|
|
expect(BankTransactionReference.parse('.FS1A1')).to be_nil
|
2021-02-08 03:39:47 +01:00
|
|
|
end
|
|
|
|
|
2017-01-26 13:27:30 +01:00
|
|
|
it 'returns nil for FS1A1x' do
|
2022-05-27 21:57:06 +02:00
|
|
|
expect(BankTransactionReference.parse('FS1A1x')).to be_nil
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
2021-02-08 03:39:47 +01:00
|
|
|
it 'returns nil for FS1A1.' do
|
2022-05-27 21:57:06 +02:00
|
|
|
expect(BankTransactionReference.parse('FS1A1.')).to be_nil
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS1A1' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS1A1')).to match({ group: 1, parts: { 'A' => 1 } })
|
2021-02-08 03:39:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS1.2A3' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS1.2A3')).to match({ group: 1, user: 2, parts: { 'A' => 3 } })
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
2021-02-08 03:39:47 +01:00
|
|
|
it 'returns correct value for FS1A2B3C4' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS1A2B3C4')).to match({ group: 1, parts: { 'A' => 2, 'B' => 3, 'C' => 4 } })
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS1A2B3A4' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS1A2B3A4')).to match({ group: 1, parts: { 'A' => 6, 'B' => 3 } })
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS1A2.34B5.67C8.90' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS1A2.34B5.67C8.90')).to match({ group: 1,
|
|
|
|
parts: { 'A' => 2.34, 'B' => 5.67,
|
|
|
|
'C' => 8.90 } })
|
2021-02-08 03:39:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS123A456 with comma-separated prefix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('x,FS123A456')).to match({ group: 123, parts: { 'A' => 456 } })
|
2021-02-08 03:39:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS123A456 with minus-separated prefix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('x-FS123A456')).to match({ group: 123, parts: { 'A' => 456 } })
|
2021-02-08 03:39:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS123A456 with semicolon-separated prefix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('x;FS123A456')).to match({ group: 123, parts: { 'A' => 456 } })
|
2021-02-08 03:39:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS123A456 with space-separated prefix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('x FS123A456')).to match({ group: 123, parts: { 'A' => 456 } })
|
2021-02-08 03:39:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS234A567 with comma-separated suffix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS234A567,x')).to match({ group: 234, parts: { 'A' => 567 } })
|
2021-02-08 03:39:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS234A567 with minus-separated suffix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS234A567-x')).to match({ group: 234, parts: { 'A' => 567 } })
|
2021-02-08 03:39:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS234A567 with space-separated suffix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS234A567 x')).to match({ group: 234, parts: { 'A' => 567 } })
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
2021-02-08 03:39:47 +01:00
|
|
|
it 'returns correct value for FS234A567 with semicolon-separated suffix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS234A567;x')).to match({ group: 234, parts: { 'A' => 567 } })
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
2021-02-08 03:39:47 +01:00
|
|
|
it 'returns correct value for FS234A567 with minus-separated suffix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('FS234A567-x')).to match({ group: 234, parts: { 'A' => 567 } })
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value for FS34.56A67.89 with prefix and suffix' do
|
2023-05-12 13:01:12 +02:00
|
|
|
expect(BankTransactionReference.parse('prefix FS34.56A67.89, suffix')).to match({ group: 34, user: 56,
|
|
|
|
parts: { 'A' => 67.89 } })
|
2017-01-26 13:27:30 +01:00
|
|
|
end
|
|
|
|
end
|