Show rate center during signup

Stephen Paul Weber created

Fetch from bandwidth so we can show it to the user, in case they happen to care.

Change summary

lib/registration.rb       | 29 ++++++++++++++++++++---------
test/test_registration.rb | 27 ++++++++++++++++++++++++++-
2 files changed, 46 insertions(+), 10 deletions(-)

Detailed changes

lib/registration.rb 🔗

@@ -92,15 +92,26 @@ class Registration
 		].freeze
 
 		def write
-			form = reply.form
-			form.type = :form
-			form.title = "Activate JMP"
-			form.instructions = "Going to activate #{tel} (TODO RATE CTR)"
-			form.fields = FORM_FIELDS
-
-			COMMAND_MANAGER.write(reply).then { |iq|
-				Payment.for(iq, customer, tel)
-			}.then(&:write)
+			rate_center.then do |center|
+				form = reply.form
+				form.type = :form
+				form.title = "Activate JMP"
+				form.instructions = "Going to activate #{tel} (#{center})"
+				form.fields = FORM_FIELDS
+
+				COMMAND_MANAGER.write(reply).then { |iq|
+					Payment.for(iq, customer, tel)
+				}.then(&:write)
+			end
+		end
+
+	protected
+
+		def rate_center
+			EM.promise_fiber do
+				center = BandwidthIris::Tn.get(tel).get_rate_center
+				"#{center[:rate_center]}, #{center[:state]}"
+			end
 		end
 	end
 

test/test_registration.rb 🔗

@@ -45,13 +45,38 @@ class RegistrationTest < Minitest::Test
 		end
 
 		def test_write
+			stub_request(
+				:get,
+				"https://dashboard.bandwidth.com/v1.0/tns/+15555550000"
+			).to_return(status: 201, body: <<~RESPONSE)
+				<TelephoneNumberResponse>
+					<TelephoneNumber>5555550000</TelephoneNumber>
+				</TelephoneNumberResponse>
+			RESPONSE
+			stub_request(
+				:get,
+				"https://dashboard.bandwidth.com/v1.0/tns/5555550000/ratecenter"
+			).to_return(status: 201, body: <<~RESPONSE)
+				<TelephoneNumberResponse>
+					<TelephoneNumberDetails>
+						<State>KE</State>
+						<RateCenter>FA</RateCenter>
+					</TelephoneNumberDetails>
+				</TelephoneNumberResponse>
+			RESPONSE
 			result = Minitest::Mock.new
 			result.expect(:then, result)
 			result.expect(:then, EMPromise.resolve(:test_result))
 			Registration::Activation::COMMAND_MANAGER.expect(
 				:write,
 				result,
-				[Blather::Stanza::Iq::Command]
+				[Matching.new do |iq|
+					assert_equal :form, iq.form.type
+					assert_equal(
+						"Going to activate +15555550000 (FA, KE)",
+						iq.form.instructions
+					)
+				end]
 			)
 			assert_equal :test_result, @activation.write.sync
 		end