diff --git a/lib/port_repo.rb b/lib/port_repo.rb index e738fde788581f3f835ed7b5eaa9c8fdcae0add0..af63679c4c2cc8a26c8258582f2bc3e44730c1e5 100644 --- a/lib/port_repo.rb +++ b/lib/port_repo.rb @@ -39,7 +39,7 @@ class PortRepo end def tel - self[:billing_telephone_number] + "+1#{self[:billing_telephone_number].sub(/^\+?1?/, '')}" end def updated_at diff --git a/lib/porting_step_repo.rb b/lib/porting_step_repo.rb index 9f3d4c15d36804eab33155704e0506ee163491f1..b9f15adeabbf1087c80b4c8314c60ce18c961444 100644 --- a/lib/porting_step_repo.rb +++ b/lib/porting_step_repo.rb @@ -8,24 +8,6 @@ require_relative "blather_notify" require_relative "utils" class PortingStepRepo - class Tel - def initialize(str) - @tel = if str.is_a? Tel - str.to_s - else - "+1#{str.sub(/^\+?1?/, '')}" - end - end - - def to_s - @tel - end - - def ==(other) - to_s == other.to_s - end - end - # Any thing that debounces messages must happen inside this. # The porting logic will pass everything in every time. class Outputs @@ -158,12 +140,11 @@ class PortingStepRepo @exe.fetch_and_submit(q: port.customer_id).then do |form| next NoCustomer.for(port: port, **to_h.except(:exe)) unless form.tel - tel = Tel.new(port.tel) - good = GoodNumber.new(**to_h) - wrong = WrongNumber.new( - right_number: tel, execution: @exe, new_backend: port.backend_sgx - ) - tel == Tel.new(form.tel) ? good.find(port) : wrong + if port.tel == form.tel + GoodNumber.new(**to_h).find(port) + else + WrongNumber.new(port: port, execution: @exe) + end end end @@ -295,13 +276,9 @@ class PortingStepRepo class WrongNumber attr_reader :new_backend - def initialize( - right_number:, - execution:, - new_backend: - ) - @new_backend = new_backend - @right_number = right_number + def initialize(port:, execution:) + @new_backend = port.backend_sgx + @right_number = port.tel @exe = execution end diff --git a/test/test_port_repo.rb b/test/test_port_repo.rb index b357e9f2d7e219126e72f93795c0bb4bfcdfb360..cba8a047051b23c9218d56f3b36a9b8c73a1d106 100644 --- a/test/test_port_repo.rb +++ b/test/test_port_repo.rb @@ -102,7 +102,7 @@ class PortRepoBandwidthTest < Minitest::Test assert_kind_of PortRepo::Bandwidth::PortWithBackend, port assert_equal "abc123", port.id assert_equal "cust456", port.customer_id - assert_equal "5551234567", port.tel + assert_equal "+15551234567", port.tel assert_equal CONFIG[:sgx], port.backend_sgx end end diff --git a/test/test_porting_step.rb b/test/test_porting_step.rb index f7929de64e0857065aadccee96ced23ee7f26197..d04a8a9c9bf0126159ede9788c2062c9985a0a0c 100644 --- a/test/test_porting_step.rb +++ b/test/test_porting_step.rb @@ -299,7 +299,7 @@ class PortingStepTest < Minitest::Test notify.expect_execution( "sgx", "reachability", - { tel: "9998887777", type: "voice" }, + { tel: "+19998887777", type: "voice" }, FormTemplate.render("reachability_result", count: 0) ) @@ -313,7 +313,7 @@ class PortingStepTest < Minitest::Test DateTime.now - 25 * MINS, DateTime.now - 1 * MINS, "starting", - "9998887777", + "+19998887777", Blather::JID.new("testroute") )).sync @@ -341,13 +341,13 @@ class PortingStepTest < Minitest::Test notify.expect_execution( "sgx", "reachability", - { tel: "9998887777", type: "voice" }, + { tel: "+19998887777", type: "voice" }, FormTemplate.render("reachability_result", count: 1) ) notify.expect_execution( "sgx", "reachability", - { tel: "9998887777", type: "sms" }, + { tel: "+19998887777", type: "sms" }, FormTemplate.render("reachability_result", count: 0) ) @@ -361,7 +361,7 @@ class PortingStepTest < Minitest::Test DateTime.now - 25 * MINS, DateTime.now - 1 * MINS, "starting", - "9998887777", + "+19998887777", Blather::JID.new("testroute") )).sync @@ -389,13 +389,13 @@ class PortingStepTest < Minitest::Test notify.expect_execution( "sgx", "reachability", - { tel: "9998887777", type: "voice" }, + { tel: "+19998887777", type: "voice" }, FormTemplate.render("reachability_result", count: 1) ) notify.expect_execution( "sgx", "reachability", - { tel: "9998887777", type: "sms" }, + { tel: "+19998887777", type: "sms" }, FormTemplate.render("reachability_result", count: 1) ) @@ -409,7 +409,7 @@ class PortingStepTest < Minitest::Test DateTime.now - 25 * MINS, DateTime.now - 1 * MINS, "starting", - "9998887777", + "+19998887777", Blather::JID.new("testroute") )).sync @@ -435,7 +435,7 @@ class PortingStepTest < Minitest::Test notify.expect_execution( "sgx", "reachability", - { tel: "9998887777", type: "voice" }, + { tel: "+19998887777", type: "voice" }, FormTemplate.render("reachability_result", count: 0) ) @@ -449,7 +449,7 @@ class PortingStepTest < Minitest::Test DateTime.now - 55 * MINS, DateTime.now - 50 * MINS, "starting", - "9998887777", + "+19998887777", Blather::JID.new("testroute") )).sync @@ -474,7 +474,7 @@ class PortingStepTest < Minitest::Test nil, DateTime.now - 1 * MINS, "ignored", - "9998887777", + "+19998887777", Blather::JID.new("testroute") ), Port.new( @@ -483,7 +483,7 @@ class PortingStepTest < Minitest::Test DateTime.now - 300 * MINS, DateTime.now - 300 * MINS, "ignored", - "9998887777", + "+19998887777", Blather::JID.new("testroute") ), Port.new( @@ -492,7 +492,7 @@ class PortingStepTest < Minitest::Test DateTime.now - 10 * MINS, DateTime.now - 10 * MINS, "ignored", - "9998887777", + "+19998887777", Blather::JID.new("testroute") ), Port.new( @@ -501,7 +501,7 @@ class PortingStepTest < Minitest::Test DateTime.now - 300 * MINS, DateTime.now - 300 * MINS, "ignored", - "9998887777", + "+19998887777", Blather::JID.new("testroute") ) ].each do |port| @@ -527,7 +527,7 @@ class PortingStepTest < Minitest::Test notify.expect_execution( "sgx", "reachability", - { tel: "9998887777", type: "voice" }, + { tel: "+19998887777", type: "voice" }, RuntimeError.new("Sender not in whitelist") ) @@ -541,7 +541,7 @@ class PortingStepTest < Minitest::Test DateTime.now - 25 * MINS, DateTime.now - 1 * MINS, "starting", - "9998887777", + "+19998887777", Blather::JID.new("testroute") )).sync @@ -566,13 +566,13 @@ class PortingStepTest < Minitest::Test notify.expect_execution( "sgx", "reachability", - { tel: "9998887777", type: "voice" }, + { tel: "+19998887777", type: "voice" }, FormTemplate.render("reachability_result", count: 0) ) notify.expect_execution( "sgx", "reachability", - { tel: "9998887777", type: "voice", reachability_tel: "+15551234567" }, + { tel: "+19998887777", type: "voice", reachability_tel: "+15551234567" }, RuntimeError.new("Sender not in whitelist") ) @@ -594,7 +594,7 @@ class PortingStepTest < Minitest::Test DateTime.now - 25 * MINS, DateTime.now - 1 * MINS, "starting", - "9998887777", + "+19998887777", Blather::JID.new("testroute") )