diff --git a/forms/tn_search.rb b/forms/tn_search.rb index d63bea84947abbef4960503d743d534bd3c88da3..5f82306f67df070fa3d9c33c1269275fc4bb59ea 100644 --- a/forms/tn_search.rb +++ b/forms/tn_search.rb @@ -12,7 +12,6 @@ end field( var: "q", - required: true, type: "text-single", label: "Search Telephone Numbers", description: @@ -21,4 +20,15 @@ field( "or indicate a vanity pattern with ~" ) +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" } + ], + value: "next" +) + xml.set(xmlns: "http://jabber.org/protocol/rsm") diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index da35f883e0583191adedc88c670f04f0544e2829..c9b1402dff7e1151bd43b995c18fca947814fd24 100644 --- a/lib/tel_selections.rb +++ b/lib/tel_selections.rb @@ -80,7 +80,7 @@ class TelSelections qs = form.field("q")&.value.to_s.strip return qs if qs =~ /\A\+1\d{10}\Z/ - q = Q.for(qs, db: db, memcache: memcache) + q = Q.for(feelinglucky(qs, form), db: db, memcache: memcache) new( q.iris_query @@ -91,6 +91,15 @@ class TelSelections ) end + ACTION_FIELD = "http://jabber.org/protocol/commands#actions" + + def self.feelinglucky(q, form) + return q unless q.empty? + return q unless form.field(ACTION_FIELD)&.value == "feelinglucky" + + "810" + end + def initialize(iris_query, fallback: [], memcache: MEMCACHE) @iris_query = iris_query @fallback = fallback diff --git a/test/test_tel_selections.rb b/test/test_tel_selections.rb index 100aad6459cf200e2013f4ca45abbf9789be0801..f4954a4bb095fb873ba199f8abaae60dd57d7784 100644 --- a/test/test_tel_selections.rb +++ b/test/test_tel_selections.rb @@ -56,6 +56,24 @@ class TelSelectionsTest < Minitest::Test ) end + def test_for_feelinglucky + form = Blather::Stanza::X.new + form.fields = [ + { var: "q", value: "" }, + { + var: "http://jabber.org/protocol/commands#actions", + value: "feelinglucky" + } + ] + iris_query = TelSelections::ChooseTel::AvailableNumber + .for(form, db: FakeDB.new, memcache: FakeMemcache.new) + .instance_variable_get(:@iris_query) + assert_equal( + { areaCode: "810", enableTNDetail: true, LCA: false, quantity: 10 }, + iris_query + ) + end + def test_fallback stub_request( :get,