From 93d6f21ccdcfcac63fe21dddee40b31feca583b9 Mon Sep 17 00:00:00 2001 From: VasilevNStas Date: Tue, 14 Jul 2026 23:11:45 +0300 Subject: [PATCH] #415: fee() must validate that tab is non-empty --- lib/baza-rb.rb | 1 + lib/baza-rb/fake.rb | 1 + test/test_baza_edge.rb | 7 +++++++ test/test_fake.rb | 7 +++++++ 4 files changed, 16 insertions(+) diff --git a/lib/baza-rb.rb b/lib/baza-rb.rb index 95001d0..65757ab 100644 --- a/lib/baza-rb.rb +++ b/lib/baza-rb.rb @@ -476,6 +476,7 @@ def transfer(recipient, amount, summary, job: nil, badge: nil) # @raise [ServerFailure] If the payment fails def fee(tab, amount, summary, job) raise(RuntimeError, 'The "tab" is nil') if tab.nil? + raise(RuntimeError, 'The "tab" may not be empty') if tab.empty? raise(RuntimeError, 'The "amount" is nil') if amount.nil? unless amount.is_a?(Float) || amount.is_a?(BigDecimal) raise(RuntimeError, 'The "amount" must be Float or BigDecimal') diff --git a/lib/baza-rb/fake.rb b/lib/baza-rb/fake.rb index 272a131..2eac87b 100644 --- a/lib/baza-rb/fake.rb +++ b/lib/baza-rb/fake.rb @@ -224,6 +224,7 @@ def transfer(recipient, amount, summary, job: nil, badge: nil) # @return [Integer] Always returns 42 as the fake receipt ID def fee(tab, amount, summary, job) raise(RuntimeError, 'The "tab" is nil') if tab.nil? + raise(RuntimeError, 'The "tab" may not be empty') if tab.empty? raise(RuntimeError, 'The "amount" is nil') if amount.nil? unless amount.is_a?(Float) || amount.is_a?(BigDecimal) raise(RuntimeError, 'The "amount" must be Float or BigDecimal') diff --git a/test/test_baza_edge.rb b/test/test_baza_edge.rb index 44b1242..a5e0675 100644 --- a/test/test_baza_edge.rb +++ b/test/test_baza_edge.rb @@ -813,6 +813,13 @@ def test_fee_raises_when_amount_is_not_positive end end + def test_fee_raises_when_tab_is_empty + assert_equal( + 'The "tab" may not be empty', + assert_raises(RuntimeError) { fake_baza.fee('', 1.0, 'pay', 42) }.message + ) + end + def test_fee_raises_when_summary_is_empty assert_equal( 'The summary "" is empty', diff --git a/test/test_fake.rb b/test/test_fake.rb index 1403904..1389958 100644 --- a/test/test_fake.rb +++ b/test/test_fake.rb @@ -297,6 +297,13 @@ def test_fee_raises_when_amount_is_not_positive ) end + def test_fee_raises_when_tab_is_empty + assert_equal( + 'The "tab" may not be empty', + assert_raises(RuntimeError) { BazaRb::Fake.new.fee('', 1.0, 'for fun', 44) }.message + ) + end + def test_fee_raises_when_job_is_not_positive assert_equal( 'The "job" must be positive',