forgejo/models/webhook/webhook_system_test.go
Cyborus 54b3066e45
Some checks are pending
/ release (push) Waiting to run
testing-integration / test-unit (push) Waiting to run
testing-integration / test-sqlite (push) Waiting to run
testing-integration / test-mariadb (v10.6) (push) Waiting to run
testing-integration / test-mariadb (v11.8) (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
fix: paginate GET /api/v1/admin/hooks response (#9915)
Fixes #9911

The endpoint was documented as taking `page` and `limit` parameters but did not actually use then and just returned the full list. Now it does use them!

Co-authored-by: Gusted <postmaster@gusted.xyz>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9915
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Cyborus <cyborus@cyborus.xyz>
Co-committed-by: Cyborus <cyborus@cyborus.xyz>
2025-11-06 00:08:13 +01:00

65 lines
2.1 KiB
Go

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package webhook
import (
"testing"
"forgejo.org/models/db"
"forgejo.org/models/unittest"
"github.com/stretchr/testify/require"
"xorm.io/builder"
)
func TestListSystemWebhooks(t *testing.T) {
defer unittest.OverrideFixtures("models/webhook/fixtures/TestListSystemWebhooks")()
require.NoError(t, unittest.PrepareTestDatabase())
testGetAdminWebhooks(t, true)
}
func TestListDefaultWebhooks(t *testing.T) {
defer unittest.OverrideFixtures("models/webhook/fixtures/TestListDefaultWebhooks")()
require.NoError(t, unittest.PrepareTestDatabase())
testGetAdminWebhooks(t, false)
}
func testGetAdminWebhooks(t *testing.T, systemHooks bool) {
hookCond := builder.Eq{"is_system_webhook": systemHooks}.And(builder.Eq{"repo_id": 0})
unittest.AssertCountByCond(t, "webhook", hookCond, 5)
t.Run("All hooks (Implicit)", func(t *testing.T) {
hooks, count, err := getAdminWebhooks(t.Context(), systemHooks, db.ListOptionsAll)
require.NoError(t, err)
unittest.AssertCountByCond(t, "webhook", hookCond, int(count))
require.Len(t, hooks, int(count))
require.Equal(t, 5, int(count))
for i := range hooks {
require.Equal(t, systemHooks, hooks[i].IsSystemWebhook)
}
})
t.Run("All hooks (Explicit)", func(t *testing.T) {
hooks, count, err := getAdminWebhooks(t.Context(), systemHooks, db.ListOptionsAll, false)
require.NoError(t, err)
unittest.AssertCountByCond(t, "webhook", hookCond, int(count))
require.Len(t, hooks, int(count))
require.Equal(t, 5, int(count))
for i := range hooks {
require.Equal(t, systemHooks, hooks[i].IsSystemWebhook)
}
})
t.Run("Active hooks", func(t *testing.T) {
hooks, count, err := getAdminWebhooks(t.Context(), systemHooks, db.ListOptionsAll, true)
require.NoError(t, err)
unittest.AssertCountByCond(t, "webhook", hookCond.And(builder.Eq{"is_active": true}), int(count))
require.Len(t, hooks, int(count))
require.Equal(t, 3, int(count))
for i := range hooks {
require.Equal(t, systemHooks, hooks[i].IsSystemWebhook)
require.True(t, hooks[i].IsActive)
}
})
}