TelSelections prod hotfixes

Stephen Paul Weber created

Change summary

lib/tel_selections.rb       | 24 +++++++++++++-----------
test/test_tel_selections.rb | 25 +++++++++++++------------
2 files changed, 26 insertions(+), 23 deletions(-)

Detailed changes

lib/tel_selections.rb 🔗

@@ -26,7 +26,7 @@ class TelSelections
 		ChooseTel::Tn::LocalInventory.fetch(tel).then do |local_inv|
 			set(
 				jid,
-				local_inv || ChooseTel::Tn::Bandwidth.new(tel)
+				local_inv || ChooseTel::Tn::Bandwidth.new(ChooseTel::Tn.new(tel))
 			)
 		end
 	end
@@ -92,7 +92,7 @@ class TelSelections
 		class AvailableNumber
 			def self.for(form, db: DB, memcache: MEMCACHE)
 				qs = form.field("q")&.value.to_s.strip
-				return qs if qs =~ /\A\+1\d{10}\Z/
+				return Tn.for_pending_value(qs) if qs =~ /\A\+1\d{10}\Z/
 
 				q = Q.for(feelinglucky(qs, form), db: db, memcache: memcache)
 
@@ -196,7 +196,7 @@ class TelSelections
 				end
 
 				def iris_query
-					{ quantity: @quantity }
+					{ quantity: [@quantity, 100].min }
 				end
 
 				# NOTE: Gajim sends back the whole list on submit, so big
@@ -311,10 +311,12 @@ class TelSelections
 					EMPromise.resolve(nil)
 				end
 
-				def order(db, customer)
-					BandwidthTnRepo.new.move(
-						tel, customer.customer_id, @bandwidth_account_id
-					)
+				def order(db, _customer)
+					# Move always moves to wrong account, oops
+					# Also probably can't move from/to same account
+					# BandwidthTnRepo.new.move(
+					# 	tel, customer.customer_id, @bandwidth_account_id
+					# )
 					db.exec_defer("DELETE FROM tel_inventory WHERE tel = $1", [tel])
 						.then { |r| raise unless r.cmd_tuples.positive? }
 				end
@@ -372,7 +374,7 @@ class TelSelections
 						define_method(:sql_query) do
 							[
 								"SELECT * FROM tel_inventory " \
-								"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
+								"WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
 								"+1#{@q}%"
 							]
 						end
@@ -406,7 +408,7 @@ class TelSelections
 				def sql_query
 					[
 						"SELECT * FROM tel_inventory " \
-						"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
+						"WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
 						"%#{q_digits}%"
 					]
 				end
@@ -446,7 +448,7 @@ class TelSelections
 				def sql_query
 					[
 						"SELECT * FROM tel_inventory " \
-						"WHERE available_after < LOCALTIMESTAMP AND region = ?",
+						"WHERE available_after < LOCALTIMESTAMP AND region = $1",
 						@state
 					]
 				end
@@ -498,7 +500,7 @@ class TelSelections
 					[
 						"SELECT * FROM tel_inventory " \
 						"WHERE available_after < LOCALTIMESTAMP " \
-						"AND region = ? AND locality = ?",
+						"AND region = $1 AND locality = $2",
 						@state.to_s, @city
 					]
 				end

test/test_tel_selections.rb 🔗

@@ -56,8 +56,9 @@ class TelSelectionsTest < Minitest::Test
 			iris_query = TelSelections::ChooseTel::AvailableNumber
 				.for(form, db: FakeDB.new, memcache: FakeMemcache.new)
 				.instance_variable_get(:@iris_query)
+			# quantity should be 100 due to max inside tel selections
 			assert_equal(
-				{ areaCode: "226", enableTNDetail: true, LCA: false, quantity: 500 },
+				{ areaCode: "226", enableTNDetail: true, LCA: false, quantity: 100 },
 				iris_query
 			)
 		end
@@ -208,7 +209,7 @@ class TelSelectionsTest < Minitest::Test
 			assert_equal(
 				[
 					"SELECT * FROM tel_inventory " \
-					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
+					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
 					"+1226%"
 				],
 				q.sql_query
@@ -225,7 +226,7 @@ class TelSelectionsTest < Minitest::Test
 			assert_equal(
 				[
 					"SELECT * FROM tel_inventory " \
-					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
+					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
 					"+1226666%"
 				],
 				q.sql_query
@@ -242,7 +243,7 @@ class TelSelectionsTest < Minitest::Test
 			assert_equal(
 				[
 					"SELECT * FROM tel_inventory " \
-					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
+					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
 					"+12266667%"
 				],
 				q.sql_query
@@ -269,7 +270,7 @@ class TelSelectionsTest < Minitest::Test
 			assert_equal(
 				[
 					"SELECT * FROM tel_inventory " \
-					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
+					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE $1",
 					"%6262%"
 				],
 				q.sql_query
@@ -286,7 +287,7 @@ class TelSelectionsTest < Minitest::Test
 			assert_equal(
 				[
 					"SELECT * FROM tel_inventory " \
-					"WHERE available_after < LOCALTIMESTAMP AND region = ?",
+					"WHERE available_after < LOCALTIMESTAMP AND region = $1",
 					"ON"
 				],
 				q.sql_query
@@ -303,7 +304,7 @@ class TelSelectionsTest < Minitest::Test
 			assert_equal(
 				[
 					"SELECT * FROM tel_inventory " \
-					"WHERE available_after < LOCALTIMESTAMP AND region = ?",
+					"WHERE available_after < LOCALTIMESTAMP AND region = $1",
 					"ON"
 				],
 				q.sql_query
@@ -320,7 +321,7 @@ class TelSelectionsTest < Minitest::Test
 			assert_equal(
 				[
 					"SELECT * FROM tel_inventory " \
-					"WHERE available_after < LOCALTIMESTAMP AND region = ?",
+					"WHERE available_after < LOCALTIMESTAMP AND region = $1",
 					"NY"
 				],
 				q.sql_query
@@ -346,7 +347,7 @@ class TelSelectionsTest < Minitest::Test
 				[
 					"SELECT * FROM tel_inventory " \
 					"WHERE available_after < LOCALTIMESTAMP " \
-					"AND region = ? AND locality = ?",
+					"AND region = $1 AND locality = $2",
 					"NY", "New York City"
 				],
 				q.sql_query
@@ -372,7 +373,7 @@ class TelSelectionsTest < Minitest::Test
 				[
 					"SELECT * FROM tel_inventory " \
 					"WHERE available_after < LOCALTIMESTAMP " \
-					"AND region = ? AND locality = ?",
+					"AND region = $1 AND locality = $2",
 					"NY", "New York City"
 				],
 				q.sql_query
@@ -398,7 +399,7 @@ class TelSelectionsTest < Minitest::Test
 				[
 					"SELECT * FROM tel_inventory " \
 					"WHERE available_after < LOCALTIMESTAMP " \
-					"AND region = ? AND locality = ?",
+					"AND region = $1 AND locality = $2",
 					"ON", "Toronto"
 				],
 				q.sql_query
@@ -424,7 +425,7 @@ class TelSelectionsTest < Minitest::Test
 				[
 					"SELECT * FROM tel_inventory " \
 					"WHERE available_after < LOCALTIMESTAMP " \
-					"AND region = ? AND locality = ?",
+					"AND region = $1 AND locality = $2",
 					"ON", "Toronto"
 				],
 				q.sql_query