test(webhook): failed emits correct stream event

Phillip Davis created

Change summary

test/property/test_webhook_handler.rb | 33 +++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)

Detailed changes

test/property/test_webhook_handler.rb 🔗

@@ -209,4 +209,37 @@ class WebhookPropertyTest < Minitest::Test
 		}
 	end
 	em :test_delivered_emits_correct_stream_event
+
+	def test_failed_emits_correct_stream_event
+		property_of {
+			Webhook
+				.new(REDIS)
+				.type { "message-failed" }
+				.generate
+		}.check { |metadata, example|
+			invoke_webhook(example)
+
+			entries = REDIS.stream_entries("messages").sync
+			assert_equal 1, entries.length
+
+			fields = entries.first[:fields]
+			expected_keys = %w[
+				event source timestamp stanza_id bandwidth_id
+				error_code error_description
+			].sort
+			assert_equal expected_keys, fields.keys.sort
+
+			assert_equal "failed", fields["event"]
+			assert_equal "bwmsgsv2", fields["source"]
+
+			tag_parts = example["message"]["tag"].split(/ /, 2)
+			expected_stanza_id = WEBrick::HTTPUtils.unescape(tag_parts[0])
+			assert_equal expected_stanza_id, fields["stanza_id"]
+			assert_equal example["message"]["id"], fields["bandwidth_id"]
+			assert_equal example["message"]["time"], fields["timestamp"]
+			assert_equal example["message"]["errorCode"].to_s, fields["error_code"]
+			assert_equal example["message"]["description"].to_s, fields["error_description"]
+		}
+	end
+	em :test_failed_emits_correct_stream_event
 end