test(webhook): delivery sends one receipt

Phillip Davis created

Change summary

test/property/test_webhook_handler.rb | 51 +++++++++++++++++++++++++++++
test/test_helper.rb                   |  2 +
2 files changed, 53 insertions(+)

Detailed changes

test/property/test_webhook_handler.rb 🔗

@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+require "test_helper"
+require_relative "../../sgx-bwmsgsv2"
+require "rantly/minitest_extensions"
+require_relative "generators/webhook"
+require_relative "generators/message"
+
+def panic(e)
+	$panic = e
+end
+
+MMS_PROXY = "https://proxy.test.example.com/"
+
+class WebhookPropertyTest < Minitest::Test
+	def setup
+		reset_stanzas!
+		reset_redis!
+	end
+
+	def test_single_recipient_message_delivered_sends_one_receipt
+		property_of {
+			Webhook
+				.new(REDIS)
+				.type { "message-delivered" }
+				.message { |registered, jid, dir, top_level_to|
+					Message
+						.new(REDIS)
+						.to { [top_level_to] }
+						.generate(registered, jid, dir)
+				}
+				.generate
+		}.check { |metadata, example|
+			result = invoke_webhook(example)
+			assert_equal 200, result[0]
+			assert_equal 1, written.length, "Should only send the delivery receipt"
+			receipt = written.shift
+			assert_equal(
+				receipt.to,
+				metadata["jid"],
+				"Should send receipt to customer's jid"
+			)
+			assert_equal(
+				receipt.from.to_s,
+				"#{example["to"]}@#{ARGV[0]}",
+				"Should send receipt from sender's Cheogram jid"
+			)
+		}
+	end
+	em :test_single_recipient_message_delivered_sends_one_receipt
+end

test/test_helper.rb 🔗

@@ -4,6 +4,7 @@ require "simplecov"
 SimpleCov.start do
 	add_filter "/test/"
 	enable_coverage :branch
+	command_name ENV.fetch("COVERAGE_NAME", "tests")
 end
 
 require "minitest/autorun"
@@ -12,6 +13,7 @@ require "webmock/minitest"
 MMS_PROXY = "https://proxy.test.example.com/"
 
 _saved_argv = ARGV.dup
+
 ARGV[0] = "component"
 ARGV[6] = MMS_PROXY