From aa2d836dd01c2995c18133e28aa67d83a72931f1 Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Tue, 3 Mar 2026 15:34:19 -0500 Subject: [PATCH] test(webhook): nil text with media, empty body --- sgx-bwmsgsv2.rb | 2 +- test/property/test_webhook_handler.rb | 33 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index c7f3b6baea497227936a4521da3526b04dd73c55..afdd9fc7638bddc309aaa00fbc0821f9c835b41c 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -1130,7 +1130,7 @@ class WebhookHandler < Goliath::API # If text is not empty, but there isn't a msg, # we need to construct a msg to convey that text - unless msg || text&.empty? + unless msg || text.to_s.empty? msg = Blather::Stanza::Message.new( bare_jid, # TODO: The numbers, what do they mean? diff --git a/test/property/test_webhook_handler.rb b/test/property/test_webhook_handler.rb index 68f6075697dc507519251ebecba0c24f1ece740c..4c3d7d4023dc7a66cd4f7be18233f206a0a6a388 100644 --- a/test/property/test_webhook_handler.rb +++ b/test/property/test_webhook_handler.rb @@ -491,4 +491,37 @@ class WebhookPropertyTest < Minitest::Test } end em :test_message_with_empty_to_returns_400 + + def test_inbound_nil_text_with_media_multi_recipient_writes_empty_body + property_of { + Webhook + .new(REDIS) + .type { "message-received" } + .message { |registered, jid, dir, top_level_to| + Message + .new(REDIS) + .to { + array(range(1, 3)) { nanpa_phone } + + [top_level_to] + + array(integer(2)) { nanpa_phone } + } + .text { nil } + .media { array(range(1, 3)) { media_url } } + .generate(registered, jid, dir) + } + .generate + }.check { |metadata, example| + result = invoke_webhook(example) + assert_equal 200, result[0] + assert_operator written.length, :>=, 1 + + msg = written.last + assert_kind_of Blather::Stanza::Message, msg + assert( + msg.body.to_s.empty?, + "Body should be nil/empty when text is nil" + ) + } + end + em :test_inbound_nil_text_with_media_multi_recipient_writes_empty_body end