mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-28 01:51:39 +00:00
models/webhook: use db.Insert in tests, merge fixture setup into prepareWebhookTestData
Agent-Logs-Url: https://github.com/go-gitea/gitea/sessions/d187e3a5-2c68-4115-a4d1-d2bda8f54004 Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
66e0e1e2c9
commit
8bb79e76fa
@@ -6,52 +6,33 @@ package webhook
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestListSystemWebhookOptions(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
systemHook := &Webhook{
|
||||
URL: "https://www.example.com/system",
|
||||
ContentType: ContentTypeJSON,
|
||||
Events: `{"push_only":true}`,
|
||||
IsActive: true,
|
||||
IsSystemWebhook: true,
|
||||
}
|
||||
assert.NoError(t, CreateWebhook(t.Context(), systemHook))
|
||||
|
||||
defaultHook := &Webhook{
|
||||
URL: "https://www.example.com/default",
|
||||
ContentType: ContentTypeJSON,
|
||||
Events: `{"push_only":true}`,
|
||||
IsActive: true,
|
||||
IsSystemWebhook: false,
|
||||
}
|
||||
assert.NoError(t, CreateWebhook(t.Context(), defaultHook))
|
||||
fixture := prepareWebhookTestData(t)
|
||||
|
||||
opts := ListSystemWebhookOptions{IsSystem: optional.None[bool]()}
|
||||
hooks, _, err := GetGlobalWebhooks(t.Context(), &opts)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, hooks, 2) {
|
||||
assert.Equal(t, systemHook.ID, hooks[0].ID)
|
||||
assert.Equal(t, defaultHook.ID, hooks[1].ID)
|
||||
assert.Equal(t, fixture.HookSystem.ID, hooks[0].ID)
|
||||
assert.Equal(t, fixture.HookDefault.ID, hooks[1].ID)
|
||||
}
|
||||
|
||||
opts.IsSystem = optional.Some(true)
|
||||
hooks, _, err = GetGlobalWebhooks(t.Context(), &opts)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, hooks, 1) {
|
||||
assert.Equal(t, systemHook.ID, hooks[0].ID)
|
||||
assert.Equal(t, fixture.HookSystem.ID, hooks[0].ID)
|
||||
}
|
||||
|
||||
opts.IsSystem = optional.Some(false)
|
||||
hooks, _, err = GetGlobalWebhooks(t.Context(), &opts)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, hooks, 1) {
|
||||
assert.Equal(t, defaultHook.ID, hooks[0].ID)
|
||||
assert.Equal(t, fixture.HookDefault.ID, hooks[0].ID)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user