test: add repository tests to improve coverage from 46.6% to 74%
New test files: - custom_field_repository_test.go: 10 tests for CustomFieldRepository & UserCustomFieldValueRepository - login_log_repository_test.go: 3 tests for ListCursor, ListByUserIDCursor, ListAllForExport - operation_log_repository_test.go: 1 test for ListCursor - role_repository_test.go: 2 tests for GetAncestorIDs, GetAncestors - social_account_repository_test.go: 8 CRUD tests - theme_repository_test.go: 10 tests for ThemeConfigRepository - user_role_repository_test.go: 1 test for DeleteByUserAndRole Modified test files: - device_repository_test.go: Added ListAllCursor tests - user_repository_test.go: Added AdvancedSearch tests - webhook_repository_test.go: Added ListByCreatorPaginated test Updated documentation with new coverage status.
This commit is contained in:
@@ -188,3 +188,40 @@ func TestWebhookRepositoryCreateAndListDeliveries(t *testing.T) {
|
||||
t.Fatal("expected deliveries to be returned in reverse created_at order")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebhookRepositoryListByCreatorPaginated(t *testing.T) {
|
||||
repo := setupWebhookRepository(t)
|
||||
ctx := context.Background()
|
||||
|
||||
// 创建多个webhook
|
||||
for i := 0; i < 5; i++ {
|
||||
if err := repo.Create(ctx, newWebhookFixture("wh-creator1-"+string(rune('a'+i)), 1, domain.WebhookStatusActive)); err != nil {
|
||||
t.Fatalf("Create failed: %v", err)
|
||||
}
|
||||
}
|
||||
// 另一个用户的webhook
|
||||
if err := repo.Create(ctx, newWebhookFixture("wh-creator2", 2, domain.WebhookStatusActive)); err != nil {
|
||||
t.Fatalf("Create failed: %v", err)
|
||||
}
|
||||
|
||||
// 测试分页查询创建者1的webhook
|
||||
webhooks, total, err := repo.ListByCreatorPaginated(ctx, 1, 0, 3)
|
||||
if err != nil {
|
||||
t.Fatalf("ListByCreatorPaginated failed: %v", err)
|
||||
}
|
||||
if len(webhooks) != 3 {
|
||||
t.Errorf("len(webhooks) = %d, want 3", len(webhooks))
|
||||
}
|
||||
if total != 5 {
|
||||
t.Errorf("total = %d, want 5", total)
|
||||
}
|
||||
|
||||
// 测试第二页
|
||||
webhooks2, _, err := repo.ListByCreatorPaginated(ctx, 1, 3, 3)
|
||||
if err != nil {
|
||||
t.Fatalf("ListByCreatorPaginated page 2 failed: %v", err)
|
||||
}
|
||||
if len(webhooks2) != 2 {
|
||||
t.Errorf("len(webhooks2) = %d, want 2", len(webhooks2))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user