refac: stale test entries, failing web tests, Postgre backup bug, Hardcoded MySQL table count, Stale Postgre connection in test, own-scope visibility filter, GetAll ignoring its error, JSON tags in use-case types, 31 copies of DESKTOP_QUERY, ProfileView endpoint paths

This commit is contained in:
Florian Sylvain committed 2026-10-28 17:54:10 +01:00
1 parent efecdee200
commit 5d6f378fce
87 files changed
+696 -373

No files matched your search

@@ -0,0 +1,111 @@
package test
import (
"RenewCMS/internal/domain/article"
"RenewCMS/internal/domain/contenttype"
"RenewCMS/internal/domain/entry"
"RenewCMS/internal/infrastructure/persistence/database"
persistence "RenewCMS/internal/infrastructure/persistence/repositories"
"testing"
)
func TestArticleRepositoryVisibilityFilterOnSQLite(t *testing.T) {
db := openContractSQLite(t)
repo := persistence.NewArticleRepository(db)
defaultSite, err := persistence.NewSiteRepository(db).GetDefault()
if err != nil {
t.Fatal(err)
}
create := func(owner uint32, online bool) {
t.Helper()
record := articleOn(defaultSite.ID)
record.CreatedBy = owner
record.IsOnline = online
if _, err := repo.Create(record); err != nil {
t.Fatal(err)
}
}
create(1, true)
create(1, false)
create(2, true)
create(2, false)
create(2, false)
one := uint32(1)
t.Run("FindPage keeps online articles and the viewer's drafts", func(t *testing.T) {
found, err := repo.FindPage(article.Filters{VisibleTo: &one, Unpaged: true})
if err != nil {
t.Fatal(err)
}
if found.Total != 3 || len(found.Items) != 3 {
t.Fatalf("total = %d, items = %d, want 3", found.Total, len(found.Items))
}
for _, item := range found.Items {
if !item.IsOnline && item.CreatedBy != one {
t.Errorf("leaked draft %+v", item)
}
}
})
t.Run("FindPage pages the filtered set", func(t *testing.T) {
found, err := repo.FindPage(article.Filters{VisibleTo: &one, Page: 2, Size: 2})
if err != nil {
t.Fatal(err)
}
if found.Total != 3 || len(found.Items) != 1 {
t.Fatalf("total = %d, items = %d, want 3 and 1", found.Total, len(found.Items))
}
})
t.Run("FindPage combines the filter with the draft status", func(t *testing.T) {
found, err := repo.FindPage(article.Filters{VisibleTo: &one, Status: article.StatusDraft, Unpaged: true})
if err != nil {
t.Fatal(err)
}
if found.Total != 1 || found.Items[0].CreatedBy != one {
t.Fatalf("found = %+v", found)
}
})
t.Run("CountVisibleTo counts online articles and the viewer's drafts", func(t *testing.T) {
counts, err := repo.CountVisibleTo(one)
if err != nil {
t.Fatal(err)
}
if counts != (article.Counts{All: 3, Online: 2, Draft: 1}) {
t.Fatalf("counts = %+v", counts)
}
})
}
func TestEntryRepositoryCreatedByFilterOnSQLite(t *testing.T) {
db := openUnmigratedSQLite(t)
if err := database.Migrate(db, migrationPublicURL); err != nil {
t.Fatal(err)
}
types := persistence.NewContentTypeRepository(db)
entries := persistence.NewEntryRepository(db)
created, err := types.Create(contenttype.ContentType{Key: "notes", Name: "Notes", Fields: []contenttype.Field{{Key: "flag", Label: "Flag", Type: contenttype.TypeBoolean}}})
if err != nil {
t.Fatal(err)
}
for _, owner := range []uint32{1, 2, 1, 2, 1} {
if _, err := entries.Create(entry.Entry{ContentTypeID: created.ID, Data: map[string]any{}, CreatedBy: owner, UpdatedBy: owner}); err != nil {
t.Fatal(err)
}
}
one := uint32(1)
found, err := entries.ListPage(entry.Filters{ContentTypeID: created.ID, CreatedBy: &one, Page: 1, Size: 2, Sort: entry.Sort{Field: entry.SortByID, Direction: entry.SortAsc}})
if err != nil {
t.Fatal(err)
}
if found.Total != 3 || len(found.Items) != 2 {
t.Fatalf("total = %d, items = %d, want 3 and 2", found.Total, len(found.Items))
}
for _, item := range found.Items {
if item.CreatedBy != one {
t.Errorf("leaked entry %+v", item)
}
}
}