From 5cc35ca987dd3aadad91aa5e14cbde6074af647f Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Tue, 6 Jan 2026 10:45:53 -0500 Subject: [PATCH] fix "undefined method 'price' for SIMKind" --- forms/tn_search.rb | 14 +++++++---- lib/command.rb | 2 ++ lib/registration.rb | 26 +++++++++++++------- lib/tel_selections.rb | 12 +++++---- test/test_registration.rb | 52 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 19 deletions(-) diff --git a/forms/tn_search.rb b/forms/tn_search.rb index edca11ae116994866e35962919da1e79b20e2697..ee0e2913be528e9fa15b02dae5e66c1659746af9 100644 --- a/forms/tn_search.rb +++ b/forms/tn_search.rb @@ -20,15 +20,19 @@ field( "or indicate a vanity pattern with ~" ) +action_options = [ + { label: "Search", value: "next" }, + { label: "Just Show Me Some Numbers", value: "feelinglucky" } +] +if @allow_data_only + action_options << { label: "Just Data, Please", value: "data_only" } +end + field( label: "Action", type: "list-single", var: "http://jabber.org/protocol/commands#actions", - options: [ - { label: "Search", value: "next" }, - { label: "Just Show Me Some Numbers", value: "feelinglucky" }, - { label: "Just Data, Please", value: "data_only" } - ], + options: action_options, value: "next" ) diff --git a/lib/command.rb b/lib/command.rb index 71d35e7c1729b90daa9c16bd092c6c2298055025..6a1616889ba45609ca4f8cf01c5f2a74d423b647 100644 --- a/lib/command.rb +++ b/lib/command.rb @@ -7,6 +7,8 @@ require_relative "customer_repo" require_relative "session_manager" class Command + ACTIONS_FIELD = "http://jabber.org/protocol/commands#actions" + def self.execution Thread.current[:execution] end diff --git a/lib/registration.rb b/lib/registration.rb index 6a7c5ab26d50ec39cb249c2c66df3c1b34b3a150..07049b485069153dc3684a1c4907bc53ce3afcdd 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -134,8 +134,11 @@ class Registration end end - def self.reserve_and_continue(tel_selections, customer, tel) - tel.reserve(customer).catch do + # @param [TelSelections] tel_selections + # @param [Customer] customer + # @param [TelSelections::ChooseTel::Tn, SIMKind] + def self.reserve_and_continue(tel_selections, customer, product) + product.reserve(customer).catch do tel_selections.delete(customer.jid).then { tel_selections[customer.jid] }.then { |choose| @@ -717,6 +720,8 @@ class Registration end class Finish + TN_UNAVAILABLE = "The JMP number %s is no longer available." + def initialize(customer, tel) @customer = customer @tel = tel @@ -744,13 +749,16 @@ class Registration def number_purchase_error(e) Command.log.error "number_purchase_error", e - TEL_SELECTIONS.delete(@customer.jid).then { - TEL_SELECTIONS[@customer.jid] - }.then { |choose| - choose.choose_tel_or_data( - error: "The JMP number #{@tel} is no longer available." - ) - }.then { |tel| Finish.new(@customer, tel).write } + TEL_SELECTIONS.delete(@customer.jid) + .then { TEL_SELECTIONS[@customer.jid] } + .then { |c| + c.choose_tel_or_data( + error: TN_UNAVAILABLE % @tel, + allow_data_only: false + ) + } + .then { |p| Finish.new(@customer, p) } + .then(&:write) end def raise_setup_error(e) diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index fcbf7a3b22108dc850f7867453b1ec8ba0589c2f..aec0d6b96e9c812da6a4c84940533254580fbf6f 100644 --- a/lib/tel_selections.rb +++ b/lib/tel_selections.rb @@ -70,14 +70,16 @@ class TelSelections @memcache = memcache end - def choose_tel_or_data(error: nil) + # @param [String, NilClass] error + # @param [Boolean] allow_data_only + # @return [EMPromise] + def choose_tel_or_data(error: nil, allow_data_only: true) + form_args = { error: error, allow_data_only: allow_data_only } Command.reply { |reply| reply.allowed_actions = [:next] - reply.command << FormTemplate.render("tn_search", error: error) + reply.command << FormTemplate.render("tn_search", **form_args) }.then { |iq| - response = iq.form.field( - "http://jabber.org/protocol/commands#actions" - )&.value.to_s.strip + response = iq.form.field(Command::ACTIONS_FIELD)&.value.to_s.strip response == "data_only" ? choose_sim_kind : choose_tel(iq) } end diff --git a/test/test_registration.rb b/test/test_registration.rb index c4b54d157921786648dad69f434709d61c3c1620..90e1d1261dbf6502b1497648c2d37fb1a833e237 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -3,6 +3,9 @@ require "test_helper" require "customer" require "registration" +require "bwmsgsv2_repo" +require "transaction" +require "sim_order" BandwidthTnReservationRepo::REDIS = FakeRedis.new @@ -1838,6 +1841,55 @@ class RegistrationTest < Minitest::Test assert_requested create_order end em :test_write_tn_fail + + def test_write_tn_fail_no_data_only_option + create_order = stub_request( + :post, + "https://dashboard.bandwidth.com/v1.0/accounts//orders" + ).to_return(status: 201, body: <<~RESPONSE) + + + test_order + + + RESPONSE + stub_request( + :get, + "https://dashboard.bandwidth.com/v1.0/accounts//orders/test_order" + ).to_return(status: 201, body: <<~RESPONSE) + + FAILED + + RESPONSE + + result = execute_command do + Command::COMMAND_MANAGER.expect( + :write, + EMPromise.reject(:test_result), + [Matching.new do |iq| + assert_equal :form, iq.form.type + assert_equal( + "The JMP number (555) 555-0000 is no longer available.", + iq.form.instructions + ) + action_field = iq.form.field( + "http://jabber.org/protocol/commands#actions" + ) + refute( + action_field.options.any? { |o| o.value == "data_only" }, + "data_only option should not be present" + ) + end] + ) + + @finish.write.catch { |e| e } + end + + assert_equal :test_result, result + assert_mock Command::COMMAND_MANAGER + assert_requested create_order + end + em :test_write_tn_fail_no_data_only_option end class SnikketTest < Minitest::Test