From 484bb555eec6bcdea5eda7441457f601d8390ae9 Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Sat, 31 Jan 2026 10:32:37 -0500 Subject: [PATCH] Fixa already broken test + 1 new test fix - 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 --- test/test_component.rb | 34 ++++++++++++++++++++++++---------- test/test_helper.rb | 11 +++++++++++ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/test/test_component.rb b/test/test_component.rb index 9ee3d95cd50b270b6f36f072635bf5012366d7ae..c7c2d9e01b90b6e0caa7f948d46abe4f970d52bb 100644 --- a/test/test_component.rb +++ b/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 diff --git a/test/test_helper.rb b/test/test_helper.rb index fabafe4e331883c548591a19a9c7b1e50cdb5991..1d7dcb4b728d4244e6c388d11b5bf5d7071220f0 100644 --- a/test/test_helper.rb +++ b/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