Skip to content

Commit

Permalink
Allow for non-existent event types in `Webhooks::Outgoing::Endpoint#e…
Browse files Browse the repository at this point in the history
…vent_types` (#983)

* Add a failing test

* another test

* Fix the failing test
  • Loading branch information
jagthedrummer authored Dec 18, 2024
1 parent 769ad04 commit eb8ef54
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def creative_concepts
end

def event_types
event_type_ids.map { |id| Webhooks::Outgoing::EventType.find(id) }
Webhooks::Outgoing::EventType.where(id: event_type_ids)
end

def touch_parent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "test_helper"

class Webhooks::Outgoing::EndpointTest < ActiveSupport::TestCase
include ActiveJob::TestHelper

setup do
@team = Team.create!(name: "test-team")
@endpoint = Webhooks::Outgoing::Endpoint.create!(url: "https://example.com/webhook", name: "test", team: @team)
end

test "#create should accept valid event_types" do
@endpoint = Webhooks::Outgoing::Endpoint.create!(
url: "https://example.com/webhook",
name: "test",
team: @team,
event_type_ids: [Webhooks::Outgoing::EventType.all.first.id]
)
assert @endpoint.persisted?
end

test "#create should accept non-existent event_types" do
@endpoint = Webhooks::Outgoing::Endpoint.create!(
url: "https://example.com/webhook",
name: "test",
team: @team,
event_type_ids: ["fake-thing.create"]
)
assert @endpoint.persisted?
end

test "#event_types should return existent EventTypes" do
valid_event_type = Webhooks::Outgoing::EventType.all.first
@endpoint = Webhooks::Outgoing::Endpoint.create!(
url: "https://example.com/webhook",
name: "test",
team: @team,
event_type_ids: [valid_event_type.id]
)
assert_equal [valid_event_type.id], @endpoint.event_types.map(&:id)
end

test "#event_types should not raise an error for non-existent event_type_ids" do
@endpoint = Webhooks::Outgoing::Endpoint.create!(
url: "https://example.com/webhook",
name: "test",
team: @team,
event_type_ids: ["fake-thing.create"]
)
assert_equal [], @endpoint.event_types
end
end

0 comments on commit eb8ef54

Please sign in to comment.