Fix typo, add test

Stephen Paul Weber created

Change summary

lib/low_balance.rb       |  2 +-
test/test_low_balance.rb | 23 ++++++++++++++++++++++-
2 files changed, 23 insertions(+), 2 deletions(-)

Detailed changes

lib/low_balance.rb 🔗

@@ -70,7 +70,7 @@ class LowBalance
 			}.catch { |e|
 				@message.body =
 					"Automatic top-up transaction for " \
-					"$#{customer.auto_top_up_amount} failed: #{e.message}"
+					"$#{@customer.auto_top_up_amount} failed: #{e.message}"
 			}.then { @customer.stanza_to(@message) }
 		end
 	end

test/test_low_balance.rb 🔗

@@ -65,7 +65,7 @@ class LowBalanceTest < Minitest::Test
 		LowBalance::AutoTopUp::Transaction = Minitest::Mock.new
 
 		def setup
-			@customer = customer(auto_top_up_amount: 100)
+			@customer = Minitest::Mock.new(customer(auto_top_up_amount: 100))
 			@auto_top_up = LowBalance::AutoTopUp.new(@customer)
 		end
 
@@ -81,5 +81,26 @@ class LowBalanceTest < Minitest::Test
 			assert_mock tx
 		end
 		em :test_notify!
+
+		def test_decline_notify!
+			@customer.expect(
+				:stanza_to,
+				nil,
+				[Matching.new { |m|
+					assert_equal(
+						"Automatic top-up transaction for $100 failed: test",
+						m.body
+					)
+				}]
+			)
+			LowBalance::AutoTopUp::Transaction.expect(
+				:sale,
+				EMPromise.reject(RuntimeError.new("test")),
+				[@customer, { amount: 100 }]
+			)
+			@auto_top_up.notify!.sync
+			assert_mock @customer
+		end
+		em :test_decline_notify!
 	end
 end