~singpolyma/sgx-jmp

3b4e787b02f28c003851c735eeca148f72f22167 — Stephen Paul Weber 1 year, 4 months ago 3b07712 + eecf454
Merge branch 'set-forwarding-on-finish'

* set-forwarding-on-finish:
  Configure number for inbound calls
3 files changed, 43 insertions(+), 2 deletions(-)

M .rubocop.yml
M lib/registration.rb
M test/test_registration.rb
M .rubocop.yml => .rubocop.yml +4 -0
@@ 14,6 14,10 @@ Metrics/MethodLength:
  Exclude:
    - test/*

Metrics/ClassLength:
  Exclude:
    - test/*

Metrics/AbcSize:
  Exclude:
    - test/*

M lib/registration.rb => lib/registration.rb +21 -1
@@ 1,5 1,7 @@
# frozen_string_literal: true

require "erb"

require_relative "./oob"

class Registration


@@ 298,7 300,7 @@ class Registration

		def write
			BandwidthTNOrder.create(@tel).then(&:poll).then(
				->(_) { @customer.register!(@tel).then { BLATHER << @reply } },
				->(_) { customer_active_tel_purchased },
				lambda do |_|
					@reply.note_type = :error
					@reply.note_text =


@@ 308,5 310,23 @@ class Registration
				end
			)
		end

	protected

		def cheogram_sip_addr
			"sip:#{ERB::Util.url_encode(@reply.to.stripped.to_s)}@sip.cheogram.com"
		end

		def customer_active_tel_purchased
			@customer.register!(@tel).then {
				EMPromise.all([
					REDIS.set("catapult_fwd-#{@tel}", cheogram_sip_addr),
					REDIS.set(
						"catapult_fwd_timeout-#{@reply.to.stripped}",
						25 # ~5 seconds / ring, 5 rings
					)
				])
			}.then { BLATHER << @reply }
		end
	end
end

M test/test_registration.rb => test/test_registration.rb +18 -1
@@ 339,10 339,13 @@ class RegistrationTest < Minitest::Test

	class FinishTest < Minitest::Test
		Registration::Finish::BLATHER = Minitest::Mock.new
		Registration::Finish::REDIS = Minitest::Mock.new

		def setup
			iq = Blather::Stanza::Iq::Command.new
			iq.from = "test\\40example.com@cheogram.com"
			@finish = Registration::Finish.new(
				Blather::Stanza::Iq::Command.new,
				iq,
				Customer.new("test"),
				"+15555550000"
			)


@@ 387,6 390,19 @@ class RegistrationTest < Minitest::Test
				EMPromise.resolve(OpenStruct.new(error?: false)),
				["test", "+15555550000"]
			)
			Registration::Finish::REDIS.expect(
				:set,
				nil,
				[
					"catapult_fwd-+15555550000",
					"sip:test%5C40example.com%40cheogram.com@sip.cheogram.com"
				]
			)
			Registration::Finish::REDIS.expect(
				:set,
				nil,
				["catapult_fwd_timeout-test\\40example.com@cheogram.com", 25]
			)
			Registration::Finish::BLATHER.expect(
				:<<,
				nil,


@@ 402,6 418,7 @@ class RegistrationTest < Minitest::Test
			@finish.write.sync
			assert_requested create_order
			BACKEND_SGX.verify
			Registration::Finish::REDIS.verify
			Registration::Finish::BLATHER.verify
		end
		em :test_write