fix: no Reachability unless backend right

Phillip Davis created

Change summary

lib/porting_step_repo.rb  |  7 ++++---
test/test_porting_step.rb | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 3 deletions(-)

Detailed changes

lib/porting_step_repo.rb 🔗

@@ -137,11 +137,12 @@ class PortingStepRepo
 			end
 
 			def find(port)
+				h = to_h
 				@exe.fetch_and_submit(q: port.customer_id).then do |form|
-					next NoCustomer.for(port: port, **to_h.except(:exe)) unless form.tel
+					next NoCustomer.for(port: port, **h.except(:exe)) unless form.tel
 
-					if port.tel == form.tel
-						GoodNumber.new(**to_h).find(port)
+					if port.tel == form.tel && form.route == port.backend_sgx.to_s
+						GoodNumber.new(**h).find(port)
 					else
 						WrongNumber.new(port: port, execution: @exe)
 					end

test/test_porting_step.rb 🔗

@@ -213,6 +213,47 @@ class PortingStepTest < Minitest::Test
 	end
 	em :test_change_number
 
+	def test_change_backend_only
+		redis = Minitest::Mock.new
+		redis.expect(:exists, EMPromise.resolve(0), ["jmp_port_freeze-01"])
+		redis.expect(:exists, "0", ["jmp_port_complete-01"])
+
+		notify = BlatherNotifyMock.new
+		notify.expect_execution(
+			"sgx", "customer info",
+			{ q: "starting" }, admin_info("starting", "+19998887777").form
+		)
+		notify.expect(:command_execution, nil) do |_server, node|
+			if node == "reachability"
+				raise(
+					Minitest::Assertion,
+					"reachability must not be invoked when backend needs to change"
+				)
+			end
+			false
+		end
+
+		step = PortingStepRepo.new(
+			redis: redis,
+			blather_notify: notify,
+			admin_server: "sgx"
+		).find(Port.new(
+			"01",
+			"COMPLETE",
+			DateTime.now - 25 * MINS,
+			DateTime.now - 1 * MINS,
+			"starting",
+			"+19998887777",
+			Blather::JID.new("newroute")
+		)).sync
+
+		assert_kind_of(
+			PortingStepRepo::Complete::AdminCommand::WrongNumber, step
+		)
+		assert_equal Blather::JID.new("newroute"), step.new_backend
+	end
+	em :test_change_backend_only
+
 	def test_change_number_does_not_invoke_reachability
 		redis = Minitest::Mock.new
 		redis.expect(:exists, EMPromise.resolve(0), ["jmp_port_freeze-01"])