From 73a8a95aa95d17c22730f860e5641aab0210b19c Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Tue, 3 Mar 2026 15:34:18 -0500 Subject: [PATCH] test(webhook): failed emits correct stream event --- test/property/test_webhook_handler.rb | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/property/test_webhook_handler.rb b/test/property/test_webhook_handler.rb index a88993e7264823cfd7f594b0cb455115ff9c86ce..8b1cd7ced84d83660047bbc181e1971ef4433a3b 100644 --- a/test/property/test_webhook_handler.rb +++ b/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