fix undefined symbol error

Phillip Davis created

Change summary

lib/registration.rb       |  2 
lib/tel_selections.rb     |  2 
test/test_helper.rb       |  4 ++
test/test_registration.rb | 71 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 77 insertions(+), 2 deletions(-)

Detailed changes

lib/registration.rb 🔗

@@ -145,7 +145,7 @@ class Registration
 				tel_selections[customer]
 			}.then { |choose|
 				choose.choose_tel_or_data(
-					error: "The JMP number #{tel} is no longer available."
+					error: "The JMP number #{product} is no longer available."
 				)
 			}.then { |n_tel| reserve_and_continue(tel_selections, customer, n_tel) }
 		end

lib/tel_selections.rb 🔗

@@ -59,7 +59,7 @@ class TelSelections
 			@tel = ChooseTel::Tn.for_pending_value(tel)
 		end
 
-		def choose_tel_or_data
+		def choose_tel_or_data(**)
 			EMPromise.resolve(@tel)
 		end
 	end

test/test_helper.rb 🔗

@@ -383,6 +383,10 @@ class FakeRedis
 			set(key, n).then { n }
 		}
 	end
+
+	def reset!
+		@values = {}
+	end
 end
 
 class FakeDB

test/test_registration.rb 🔗

@@ -10,6 +10,11 @@ require "sim_order"
 BandwidthTnReservationRepo::REDIS = FakeRedis.new
 
 class RegistrationTest < Minitest::Test
+	def teardown
+		BandwidthTnReservationRepo::REDIS.reset!
+		WebMock.reset!
+	end
+
 	def test_for_registered
 		sgx = OpenStruct.new(
 			registered?: OpenStruct.new(phone: "+15555550000")
@@ -141,6 +146,72 @@ class RegistrationTest < Minitest::Test
 	end
 	em :test_for_not_activated_with_customer_id
 
+	def test_reserve_and_continue_retries_on_reserve_failure
+		redis = Minitest::Mock.new
+		redis.expect(:del, EMPromise.resolve(1), [String])
+		redis.expect(:get, EMPromise.resolve("+15555551111"), [String])
+		first_res = stub_request(
+			:post,
+			"https://dashboard.bandwidth.com/v1.0/accounts//tnreservation"
+		).with(
+			body: '<?xml version="1.0" encoding="UTF-8"?>' \
+				"<Reservation><ReservedTn>+15555550000</ReservedTn></Reservation>",
+			headers: {
+				"Accept" => "application/xml",
+				"Authorization" => "Basic Og==",
+				"Content-Type" => "application/xml",
+				"User-Agent" => "Ruby-Bandwidth-Iris"
+			}
+		).to_return(status: 400, body: "", headers: {})
+		second_res = stub_request(
+			:post,
+			"https://dashboard.bandwidth.com/v1.0/accounts//tnreservation"
+		).with(
+			body: '<?xml version="1.0" encoding="UTF-8"?>' \
+				"<Reservation><ReservedTn>+15555551111</ReservedTn></Reservation>",
+			headers: {
+				"Accept" => "application/xml",
+				"Authorization" => "Basic Og==",
+				"Content-Type" => "application/xml",
+				"User-Agent" => "Ruby-Bandwidth-Iris"
+			}
+		).to_return(
+			status: 201,
+			headers: {
+				location: "https://dashboard.bandwidth.com/api/accounts//TnReservation/retry-test-reservation"
+			}
+		)
+		check_res = stub_request(
+			:get, "https://dashboard.bandwidth.com/v1.0/accounts//tnreservation/retry-test-reservation"
+		).to_return(status: 200, body: <<~RESPONSE)
+			<ReservationResponse>
+				<Reservation>
+					<ReservationId>retry-test-reservation</ReservationId>
+					<AccountId>12346099</AccountId>
+					<ReservationExpires>1492</ReservationExpires>
+					<ReservedTn>5555551111</ReservedTn>
+				</Reservation>
+			</ReservationResponse>
+		RESPONSE
+
+		tel_selections = TelSelections.new(
+			redis: redis, db: Minitest::Mock.new, memcache: FakeMemcache.new
+		)
+
+		cust = customer(sgx: OpenStruct.new(registered?: false))
+		first_tel = TelSelections::ChooseTel::Tn.for_pending_value("+15555550000")
+
+		execute_command do
+			Registration.reserve_and_continue(tel_selections, cust, first_tel)
+		end
+
+		[first_res, second_res, check_res].each do |req|
+			assert_requested req
+		end
+		assert_mock redis
+	end
+	em :test_reserve_and_continue_retries_on_reserve_failure
+
 	class ActivationTest < Minitest::Test
 		Registration::Activation::DB = Minitest::Mock.new
 		Registration::Activation::REDIS = FakeRedis.new(