@@ -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
@@ -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(