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(webhooks): fix HasEvent logic #1355

Merged
merged 1 commit into from
Feb 19, 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: 3 additions & 1 deletion backend/webhooks/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ type BaseWebhook struct {

func (bh *BaseWebhook) HasEvent(evt events.Event) bool {
for _, event := range bh.Events {
return strings.HasPrefix(string(evt), string(event))
if strings.HasPrefix(string(evt), string(event)) {
return true
}
}

return false
Expand Down
20 changes: 20 additions & 0 deletions backend/webhooks/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ func TestBaseWebhook_HasEvent(t *testing.T) {
require.True(t, baseHook.HasEvent(events.EmailCreate))
}

func TestWebhooks_HasEvent_WithMultipleEvents(t *testing.T) {
baseHook := BaseWebhook{
Logger: nil,
Callback: "http://ipsum.lorem",
Events: events.Events{events.UserCreate, events.UserUpdate},
}

require.True(t, baseHook.HasEvent(events.UserUpdate))
}

func TestWebhooks_HasSubEvent_WithMultipleEvents(t *testing.T) {
baseHook := BaseWebhook{
Logger: nil,
Callback: "http://ipsum.lorem",
Events: events.Events{events.UserCreate, events.UserUpdate},
}

require.True(t, baseHook.HasEvent(events.EmailCreate))
}

func TestBaseWebhook_HasSubEvent(t *testing.T) {
baseHook := BaseWebhook{
Logger: nil,
Expand Down
Loading