Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when trying to bulk notify from an ephemeral notifier #486

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/noticed/bulk_delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/noticed/bulk_delivery_methods/test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/bulk_delivery_methods/webhook_test.rb
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 10 additions & 0 deletions test/notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down