~singpolyma/sgx-jmp

6fb4b01a1a389c4d761f35d1b9a872ec647e5a9b — Stephen Paul Weber 1 year, 6 months ago 9401086 + 56403f9
Merge branch 'show-ratecenter-during-signup'

* show-ratecenter-during-signup:
  Show rate center during signup
2 files changed, 46 insertions(+), 10 deletions(-)

M lib/registration.rb
M test/test_registration.rb
M lib/registration.rb => lib/registration.rb +20 -9
@@ 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


M test/test_registration.rb => test/test_registration.rb +26 -1
@@ 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)
				<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