fix: dont fire reachability before number_change

Phillip Davis created

Change summary

lib/porting_step_repo.rb  |  4 ++--
test/test_porting_step.rb | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)

Detailed changes

lib/porting_step_repo.rb 🔗

@@ -159,11 +159,11 @@ class PortingStepRepo
 					next NoCustomer.for(port: port, **to_h.except(:exe)) unless form.tel
 
 					tel = Tel.new(port.tel)
-					good = GoodNumber.new(**to_h).find(port)
+					good = GoodNumber.new(**to_h)
 					wrong = WrongNumber.new(
 						right_number: tel, execution: @exe, new_backend: port.backend_sgx
 					)
-					tel == Tel.new(form.tel) ? good : wrong
+					tel == Tel.new(form.tel) ? good.find(port) : wrong
 				end
 			end
 

test/test_porting_step.rb 🔗

@@ -213,6 +213,46 @@ class PortingStepTest < Minitest::Test
 	end
 	em :test_change_number
 
+	def test_change_number_does_not_invoke_reachability
+		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", "+19998881111").form
+		)
+		notify.expect(:command_execution, nil) do |_server, node|
+			if node == "reachability"
+				raise(
+					Minitest::Assertion,
+					"reachability must not be invoked before backend 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",
+			"9998887777",
+			Blather::JID.new("testroute")
+		)).sync
+
+		assert_kind_of(
+			PortingStepRepo::Complete::AdminCommand::WrongNumber, step
+		)
+	end
+	em :test_change_number_does_not_invoke_reachability
+
 	def test_unknown_customer
 		redis = Minitest::Mock.new
 		redis.expect(:exists, EMPromise.resolve(0), ["jmp_port_freeze-01"])