Merge branch 'outbound-call-customer-not-found'

Stephen Paul Weber created

* outbound-call-customer-not-found:
  Actually handle outbound attempt from unknown customer

Change summary

test/test_web.rb                | 21 +++++++++++++++++++++
views/outbound/no_customer.slim |  3 +++
web.rb                          |  6 ++++--
3 files changed, 28 insertions(+), 2 deletions(-)

Detailed changes

test/test_web.rb 🔗

@@ -265,6 +265,27 @@ class WebTest < Minitest::Test
 	end
 	em :test_outbound_atlimit
 
+	def test_outbound_no_customer
+		post(
+			"/outbound/calls",
+			{
+				from: "no_such_customer",
+				to: "+15557654321",
+				callId: "acall"
+			}.to_json,
+			{ "CONTENT_TYPE" => "application/json" }
+		)
+
+		assert last_response.ok?
+		assert_equal(
+			"<?xml version=\"1.0\" encoding=\"utf-8\" ?><Response>" \
+			"<SpeakSentence>Your credentials are invalid, please contact support." \
+			"</SpeakSentence></Response>",
+			last_response.body
+		)
+	end
+	em :test_outbound_no_customer
+
 	def test_outbound_atlimit_digits
 		post(
 			"/outbound/calls",

web.rb 🔗

@@ -368,7 +368,7 @@ class Web < Roda
 					from = params["from"].sub(/^\+1/, "")
 					customer_repo(
 						sgx_repo: Bwmsgsv2Repo.new
-					).find_by_format(from).then do |c|
+					).find_by_format(from).then { |c|
 						call_attempt_repo.find_outbound(
 							c,
 							params["to"],
@@ -380,7 +380,9 @@ class Web < Roda
 							call_attempt_repo.starting_call(c, params["callId"])
 							render(*ca.to_render)
 						end
-					end
+					}.catch_only(CustomerRepo::NotFound) {
+						render "outbound/no_customer"
+					}
 				end
 			end
 		end