what if the network requests fail?

Phillip Davis created

Change summary

test/test_bandwidth_tn_repo.rb | 36 ++++++++++--------------------------
1 file changed, 10 insertions(+), 26 deletions(-)

Detailed changes

test/test_bandwidth_tn_repo.rb 🔗

@@ -109,7 +109,15 @@ class BandwidthTnRepoTest < Minitest::Test
 			[nil,   nil,      "CA",   nil,     "NY", "NYC", "CA", "NYC"],
 			[nil,   "Austin", nil,    "LA",    "NY", "NYC", "NY", "Austin"],
 			[nil,   nil,      nil,    "LA",    "NY", "NYC", "NY", "LA"],
-			[nil,   nil,      nil,    nil,     "NY", "NYC", "NY", "NYC"]
+			[nil,   nil,      nil,    nil,     "NY", "NYC", "NY", "NYC"],
+			[:error, :error, "CA",   "LA",    "NY", "NYC", "CA", "LA"],
+			[:error, :error, "CA",   "2City", "NY", "NYC", "CA", "NYC"],
+			[:error, :error, "2ST",  "2City", "NY", "NYC", "NY", "NYC"],
+			["TX",  "1City",  :error, :error, "NY", "NYC", "TX", "NYC"],
+			["1ST", "Austin", :error, :error, "NY", "NYC", "NY", "Austin"],
+			["1ST", "1City",  :error, :error, "NY", "NYC", "NY", "NYC"],
+			[nil,   nil,      :error, :error, "NY", "NYC", "NY", "NYC"],
+			[:error, :error,  :error, :error, "NY", "NYC", "NY", "NYC"]
 		].each do |bw_r, bw_l, geo_r, geo_l, lcg_r, lcg_l, exp_r, exp_l|
 			WebMock.reset!
 			stub_bw_oauth_token
@@ -126,36 +134,12 @@ class BandwidthTnRepoTest < Minitest::Test
 				}
 			}.to_xml
 
-			geo_json = {
-				"latt" => "30.267153",
-				"longt" => "-97.743061"
-			}
-			geo_json["prov"] = geo_r if geo_r
-			geo_json["city"] = geo_l if geo_l
-
-			stub_request(
-				:get,
-				"https://dashboard.bandwidth.com/v1.0/tns/5565555555/tndetails"
-			)
-				.with(
-					headers: {
-						"Accept" => "application/xml",
-						"Accept-Encoding" => "gzip, compressed",
-						"Authorization" =>
-							"Basic dGVzdF9id191c2VyOnRlc3RfYndfcGFzc3dvcmQ=",
-						"User-Agent" => "Ruby-Bandwidth-Iris"
-					}
-				).to_return(status: 200, body: bw_body, headers: {})
-
 			stub_request(
 				:get,
 				"https://localcallingguide.com/xmlprefix.php?npa=556&nxx=555"
 			).to_return(status: 200, body: lcg_body)
 
-			stub_request(
-				:get,
-				"https://geocoder.ca/?json=1&latt=30.267153&longt=-97.743061"
-			).to_return(status: 200, body: geo_json.to_json)
+			stub_geocoder(geo_r, geo_l)
 
 			BandwidthTnRepo::DB.expect(
 				:exec,