test(webhook): group stanza has addresses element

Phillip Davis created

Change summary

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

Detailed changes

test/test_webhook_handler.rb 🔗

@@ -295,4 +295,47 @@ class WebhookHandlerTest < Minitest::Test
 		assert_equal 0, entries.length
 	end
 	em :test_message_received_zero_recipients_writes_no_stanza
+
+	def test_message_received_group_stanza_has_addresses
+		payload = {
+			"type" => "message-received",
+			"to" => "+15550000000",
+			"message" => {
+				"id" => "bw-in-grp-001",
+				"direction" => "in",
+				"owner" => "+15550000000",
+				"from" => "+15551234567",
+				"to" => ["+15550000000", "+15559999999"],
+				"time" => "2025-01-13T10:00:00Z",
+				"text" => "Hello group"
+			}
+		}
+
+		invoke_webhook(payload)
+
+		assert_equal 1, written.length
+		msg = written.first
+		assert_equal "example.com", msg.to.to_s
+		assert_equal "+15551234567@component", msg.from.to_s
+		assert_equal "Hello group", msg.body
+
+		addrs = msg.find_first("addresses")
+		refute_nil addrs
+		assert_equal(
+			"http://jabber.org/protocol/address", addrs['xmlns']
+		)
+
+		address_nodes = addrs.find("address")
+		assert_equal 2, address_nodes.length
+
+		jid_addr = address_nodes.detect { |a| a['jid'] }
+		assert_equal "to", jid_addr['type']
+		assert_equal "test@example.com", jid_addr['jid']
+
+		uri_addr = address_nodes.detect { |a| a['uri'] }
+		assert_equal "to", uri_addr['type']
+		assert_equal "sms:+15559999999", uri_addr['uri']
+		assert_equal "true", uri_addr['delivered']
+	end
+	em :test_message_received_group_stanza_has_addresses
 end