From 56403f91092220c5083e79d542bc82b5f8778842 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 17 May 2021 13:45:55 -0500 Subject: [PATCH] Show rate center during signup Fetch from bandwidth so we can show it to the user, in case they happen to care. --- lib/registration.rb | 29 ++++++++++++++++++++--------- test/test_registration.rb | 27 ++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/lib/registration.rb b/lib/registration.rb index bb5d02b..dffa433 100644 --- a/lib/registration.rb +++ b/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 diff --git a/test/test_registration.rb b/test/test_registration.rb index 3b88760..fdd34de 100644 --- a/test/test_registration.rb +++ b/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) + + 5555550000 + + RESPONSE + stub_request( + :get, + "https://dashboard.bandwidth.com/v1.0/tns/5555550000/ratecenter" + ).to_return(status: 201, body: <<~RESPONSE) + + + KE + FA + + + 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 -- 2.38.5