-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate IgnoredEventHandler behavior for connect and platform events.
- Loading branch information
Showing
3 changed files
with
79 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 30 additions & 13 deletions
43
test/lib/code_corps/stripe_service/webhook_processing/ignored_event_handler_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,47 @@ | ||
defmodule CodeCorps.StripeService.WebhookProcessing.IgnoredEventHandlerTest do | ||
use CodeCorps.ModelCase | ||
|
||
alias CodeCorps.StripeService.WebhookProcessing.IgnoredEventHandler | ||
alias CodeCorps.StripeService.WebhookProcessing.{ | ||
ConnectEventHandler, IgnoredEventHandler, PlatformEventHandler | ||
} | ||
|
||
defp ignored?(type) do | ||
@spec ignored?(String.t, Module.t) :: boolean | ||
defp ignored?(type, handler) do | ||
event = insert(:stripe_event, type: type) | ||
{:ok, event} = IgnoredEventHandler.handle(event) | ||
{:ok, event} = IgnoredEventHandler.handle(event, handler ) | ||
|
||
event.ignored_reason && event.status == "ignored" | ||
end | ||
|
||
describe "handle/1" do | ||
test "ignores events from the ignored events list" do | ||
IgnoredEventHandler.ignored_event_types | ||
|> Enum.each(fn(type) -> assert ignored?(type) end) | ||
describe "handle/2" do | ||
test "ignores events from the ignored platform events list" do | ||
IgnoredEventHandler.ignored_event_types(PlatformEventHandler) | ||
|> Enum.each(fn(type) -> assert ignored?(type, PlatformEventHandler) end) | ||
|
||
assert_raise(FunctionClauseError, fn -> ignored?("some.other.type") end) | ||
assert_raise(FunctionClauseError, fn -> ignored?("some.other.type", PlatformEventHandler) end) | ||
end | ||
|
||
test "ignores events from the ignored connect events list" do | ||
IgnoredEventHandler.ignored_event_types(ConnectEventHandler) | ||
|> Enum.each(fn(type) -> assert ignored?(type, ConnectEventHandler) end) | ||
|
||
assert_raise(FunctionClauseError, fn -> ignored?("some.other.type", ConnectEventHandler) end) | ||
end | ||
end | ||
|
||
describe "should_handle?/1" do | ||
test "returns true for types from the ignored list" do | ||
IgnoredEventHandler.ignored_event_types | ||
|> Enum.each(fn(type) -> assert IgnoredEventHandler.should_handle?(type) end) | ||
describe "should_handle?/2" do | ||
test "returns true for types from the ignored platform events list" do | ||
IgnoredEventHandler.ignored_event_types(PlatformEventHandler) | ||
|> Enum.each(fn(type) -> assert IgnoredEventHandler.should_handle?(type, PlatformEventHandler) end) | ||
|
||
refute IgnoredEventHandler.should_handle?("some.other.type", PlatformEventHandler) | ||
end | ||
|
||
test "returns true for types from the ignored connect events list" do | ||
IgnoredEventHandler.ignored_event_types(ConnectEventHandler) | ||
|> Enum.each(fn(type) -> assert IgnoredEventHandler.should_handle?(type, ConnectEventHandler) end) | ||
|
||
refute IgnoredEventHandler.should_handle?("some.other.type") | ||
refute IgnoredEventHandler.should_handle?("some.other.type", ConnectEventHandler) | ||
end | ||
end | ||
end |