Detailed changes
@@ -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"
)
@@ -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
@@ -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)
@@ -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
@@ -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)
+ <OrderResponse>
+ <Order>
+ <id>test_order</id>
+ </Order>
+ </OrderResponse>
+ RESPONSE
+ stub_request(
+ :get,
+ "https://dashboard.bandwidth.com/v1.0/accounts//orders/test_order"
+ ).to_return(status: 201, body: <<~RESPONSE)
+ <OrderResponse>
+ <OrderStatus>FAILED</OrderStatus>
+ </OrderResponse>
+ 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