make invisible separator tests less dumb and pass

Phillip Davis created

Change summary

test/property/test_invisible_separator.rb | 33 ++++++++++++------------
1 file changed, 16 insertions(+), 17 deletions(-)

Detailed changes

test/property/test_invisible_separator.rb 🔗

@@ -12,8 +12,12 @@ class InvisibleSeparatorPropertyTest < Minitest::Test
 	def setup
 		reset_stanzas!
 		reset_redis!
+		WebMock.reset!
 	end
 
+	BW_MESSAGES_URL =
+		"https://messaging.bandwidth.com/api/v2/users/account/messages"
+
 	def test_message_containing_invisible_separator_is_rejected
 		property_of {
 			words = array(range(1, 6)) { sized(range(3, 10)) { string(:alnum) } }
@@ -28,11 +32,7 @@ class InvisibleSeparatorPropertyTest < Minitest::Test
 		}.check { |body, dest|
 			reset_stanzas!
 			reset_redis!
-
-			stub_request(:post, BW_MESSAGES_URL).to_return(
-				status: 201,
-				body: JSON.dump(id: "bw-msg-stub")
-			)
+			WebMock.reset!
 
 			m = Blather::Stanza::Message.new("#{dest}@component", body)
 			m.from = "test@example.com"
@@ -65,8 +65,14 @@ class InvisibleSeparatorPropertyTest < Minitest::Test
 		}.check { |body, dest|
 			reset_stanzas!
 			reset_redis!
-
-			stub_request(:post, BW_MESSAGES_URL).to_return(
+			WebMock.reset!
+
+			bw_req = stub_request(:post, BW_MESSAGES_URL).with(
+				body: hash_including(
+					to: dest,
+					text: body
+				)
+			).to_return(
 				status: 201,
 				body: JSON.dump(id: "bw-msg-stub")
 			)
@@ -75,16 +81,9 @@ class InvisibleSeparatorPropertyTest < Minitest::Test
 			m.from = "test@example.com"
 			process_stanza(m)
 
-			written.each do |response|
-				stanza = Blather::XMPPNode.parse(response.to_xml)
-				next unless stanza.error?
-
-				error = stanza.find_first("error")
-				msg = "Clean message rejected as " \
-					"recipient-unavailable: #{body.inspect}"
-				refute_equal "recipient-unavailable",
-				             xmpp_error_name(error), msg
-			end
+			assert_empty written,
+			             "Expected no error stanzas for body: #{body.inspect}"
+			assert_requested bw_req
 		}
 	end
 	em :test_message_without_invisible_separator_is_not_rejected_as_unavailable