diff --git a/test/property/test_webhook_handler.rb b/test/property/test_webhook_handler.rb index 1b7046e0d796c86f8f419349fa2694ca1f28df4f..dbb649a5b4be53944df7e2b7962a34370509f867 100644 --- a/test/property/test_webhook_handler.rb +++ b/test/property/test_webhook_handler.rb @@ -355,4 +355,54 @@ class WebhookPropertyTest < Minitest::Test } end em :test_inbound_empty_text_no_media_returns_400 + + def test_inbound_unknown_type_sends_notification + property_of { + Webhook + .new(REDIS) + .type { "unknown" } + .direction { "in" } + .message { |registered, jid, dir, top_level_to| + Message + .new(REDIS) + .to { [nanpa_phone] } + .generate(registered, jid, dir) + } + .generate + }.check { |metadata, example| + result = invoke_webhook(example) + assert_equal 200, result[0] + assert_equal 1, written.length + + msg = written.shift + assert_kind_of Blather::Stanza::Message, msg + assert_equal( + metadata["jid"], + msg.to.to_s, + "Notification should be sent to customer's jid" + ) + + expected_from = example["message"]["from"] + unless expected_from.start_with?("+") + expected_from += ";phone-context=ca-us.phone-context.soprani.ca" + end + assert_equal( + "#{expected_from}@#{ARGV[0]}", + msg.from.to_s, + "Notification should be from sender's Cheogram jid" + ) + + expected_text = "unknown type (unknown)" \ + " with text: #{example["message"]["text"]}" + assert_equal( + expected_text, + msg.body, + "Body should contain the unknown type and original text" + ) + + entries = REDIS.stream_entries("messages").sync + assert_empty entries, "Unknown inbound type should not emit a stream event" + } + end + em :test_inbound_unknown_type_sends_notification end