Merge branch 'set-forwarding-on-finish'

Stephen Paul Weber created

* set-forwarding-on-finish:
  Configure number for inbound calls

Change summary

.rubocop.yml              |  4 ++++
lib/registration.rb       | 22 +++++++++++++++++++++-
test/test_registration.rb | 19 ++++++++++++++++++-
3 files changed, 43 insertions(+), 2 deletions(-)

Detailed changes

.rubocop.yml 🔗

@@ -14,6 +14,10 @@ Metrics/MethodLength:
   Exclude:
     - test/*
 
+Metrics/ClassLength:
+  Exclude:
+    - test/*
+
 Metrics/AbcSize:
   Exclude:
     - test/*

lib/registration.rb 🔗

@@ -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

test/test_registration.rb 🔗

@@ -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