diff --git a/lib/noticed/bulk_delivery_method.rb b/lib/noticed/bulk_delivery_method.rb index 4ba1591..f6961c1 100644 --- a/lib/noticed/bulk_delivery_method.rb +++ b/lib/noticed/bulk_delivery_method.rb @@ -7,10 +7,10 @@ class BulkDeliveryMethod < ApplicationJob attr_reader :config, :event - def perform(delivery_method_name, event, recipients: nil, params: {}, overrides: {}) + def perform(delivery_method_name, event, recipient: nil, params: {}, overrides: {}) # Ephemeral notifications if event.is_a? String - @event = @notification.event + @event = event.constantize.new_with_params(recipient, params) @config = overrides else @event = event diff --git a/lib/noticed/bulk_delivery_methods/test.rb b/lib/noticed/bulk_delivery_methods/test.rb index 2c62945..c4448b7 100644 --- a/lib/noticed/bulk_delivery_methods/test.rb +++ b/lib/noticed/bulk_delivery_methods/test.rb @@ -1,10 +1,10 @@ module Noticed module BulkDeliveryMethods - class Test < DeliveryMethod + class Test < BulkDeliveryMethod class_attribute :delivered, default: [] def deliver - delivered << notification + delivered << event end end end diff --git a/test/bulk_delivery_methods/webhook_test.rb b/test/bulk_delivery_methods/webhook_test.rb index 0a1196d..2bc973c 100644 --- a/test/bulk_delivery_methods/webhook_test.rb +++ b/test/bulk_delivery_methods/webhook_test.rb @@ -1,10 +1,19 @@ require "test_helper" class WebhookBulkDeliveryMethodTest < ActiveSupport::TestCase + include ActiveJob::TestHelper + setup do @delivery_method = Noticed::BulkDeliveryMethods::Webhook.new end + test "end to end" do + stub_request(:post, "https://example.org/bulk") + perform_enqueued_jobs do + BulkNotifier.deliver + end + end + test "webhook with json payload" do set_config( url: "https://example.org/webhook", diff --git a/test/notifier_test.rb b/test/notifier_test.rb index a6678d9..96d1417 100644 --- a/test/notifier_test.rb +++ b/test/notifier_test.rb @@ -142,6 +142,16 @@ def recipients end end + test "creates jobs for bulk ephemeral deliveries" do + assert_enqueued_jobs 1, only: Noticed::BulkDeliveryMethods::Test do + EphemeralNotifier.deliver + end + + assert_difference("Noticed::BulkDeliveryMethods::Test.delivered.length" => 1) do + perform_enqueued_jobs + end + end + test "deliver wait" do freeze_time assert_enqueued_with job: Noticed::EventJob, at: 5.minutes.from_now do