Fixa already broken test + 1 new test fix

Phillip Davis created

- The first commit was broken since it didn't include the `with_stubs`
  helper

- The second one was included in a previous patchset but I'm including
  it as a standalone to get upstream tests 'fixed.' Apparnetly this test
  reliably passed without stubbing TnOptiions.get, but clearly it should
  be stubbed or mocked.

The following changes since commit 710dfae450ea52a53a46f92776451e9e3f1afa19:

  Merge branch '380-conditionally-show-command' of https://git.secluded.site/sgx-bwmsgsv2 (2025-10-22 09:49:51 -0500)

are available in the Git repository at:

  test_fixes

for you to fetch changes up to 23cca00d8274c7f8bf808d5f0af6993369c7a76d:

  fix `test_port_out_pin` (2026-01-31 10:17:03 -0500)

----------------------------------------------------------------
Phillip Davis (2):
      fix: handle 404 in tn_eligible_for_port_out_pin?
      fix `test_port_out_pin`

 lib/bandwidth_tn_options.rb       |  8 +++++++-
 test/test_bandwidth_tn_options.rb | 19 +++++++++++++++++++
 test/test_component.rb            | 34 ++++++++++++++++++++++++----------
 test/test_helper.rb               | 11 +++++++++++
 4 files changed, 61 insertions(+), 11 deletions(-)
 create mode 100644 test/test_bandwidth_tn_options.rb

Change summary

test/test_component.rb | 34 ++++++++++++++++++++++++----------
test/test_helper.rb    | 11 +++++++++++
2 files changed, 35 insertions(+), 10 deletions(-)

Detailed changes

test/test_component.rb 🔗

@@ -424,18 +424,32 @@ class ComponentTest < Minitest::Test
 			]
 		end
 
-		BandwidthIris::TnOptions.stub :create_tn_option_order,
-			->(client, data) { {order_id: 'test-order-123', processing_status: 'RECEIVED', error_list: {}} } do
-			BandwidthIris::TnOptions.stub :get_tn_option_order,
-				->(client, order_id) { {order_id: order_id, order_status: 'COMPLETE', error_list: {}} } do
-
-				process_stanza(iq)
+		tn_mock = Minitest::Mock.new
+		tn_mock.expect(:get_details, { tier: 0.0, on_net_vendor: true })
+		with_stubs([
+			[
+				BandwidthIris::TnOptions,
+				:create_tn_option_order,
+				->(client, data) { {order_id: 'test-order-123', processing_status: 'RECEIVED', error_list: {}} }
+			],
+			[
+				BandwidthIris::TnOptions,
+				:get_tn_option_order,
+				->(client, order_id) { {order_id: order_id, order_status: 'COMPLETE', error_list: {}} }
+			],
+			[
+				BandwidthIris::Tn,
+				:get,
+				tn_mock
+			]
+		]) do
+			process_stanza(iq)
 
-				assert_equal 1, written.length
+			assert_equal 1, written.length
 
-				stanza = Blather::XMPPNode.parse(written.first.to_xml)
-				refute stanza.error?
-			end
+			stanza = Blather::XMPPNode.parse(written.first.to_xml)
+			refute stanza.error?
+			assert_mock tn_mock
 		end
 	end
 	em :test_port_out_pin

test/test_helper.rb 🔗

@@ -138,6 +138,17 @@ REDIS = FakeRedis.new
 
 module Minitest
 	class Test
+		def with_stubs(stubs, &block)
+			if stubs.empty?
+				block.call
+			else
+				obj, method, value = stubs.first
+				obj.stub(method, value) do
+					with_stubs(stubs[1..], &block)
+				end
+			end
+		end
+
 		def self.em(m)
 			alias_method "raw_#{m}", m
 			define_method(m) do