diff --git a/lib/registration.rb b/lib/registration.rb
index 2f5d789736db1153c06d46522baa09f87b2a1ddd..fd82857f4687ef9047103c197e89b3e1fad80fb0 100644
--- a/lib/registration.rb
+++ b/lib/registration.rb
@@ -94,15 +94,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 be315bf686dee6758d3a7574b8ae77108c31a24f..24abf237248929699e3eb7e0064d70ab3d2b318a 100644
--- a/test/test_registration.rb
+++ b/test/test_registration.rb
@@ -70,13 +70,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