diff --git a/.rubocop.yml b/.rubocop.yml index 4546d8fbc1211bbd9e1d595eddefc0f41c60d918..b3d81c8b9e0e82064618fa8955ee81880159e7d3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,6 +14,10 @@ Metrics/MethodLength: Exclude: - test/* +Metrics/ClassLength: + Exclude: + - test/* + Metrics/AbcSize: Exclude: - test/* diff --git a/lib/registration.rb b/lib/registration.rb index fd82857f4687ef9047103c197e89b3e1fad80fb0..fc530500f82079b6bbf814f8b6d5e57c4a4a887b 100644 --- a/lib/registration.rb +++ b/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 diff --git a/test/test_registration.rb b/test/test_registration.rb index b49e32c8096ac496166f52fc81c8c1949d203f9e..c1a017bb06e550424f4ef54f57ff1c7dede56343 100644 --- a/test/test_registration.rb +++ b/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