Files
sm-journal-plugin/plugin_test.go
Jakub Zych 09e56437fd test(16.2-07): TestJournalSVGEmbed expects the mlblogeditor post content
16.2-03 moved post content to type: mlblogeditor with htmlColumn:
content_html (D-08); the Phase 15 mlmarkdown assertion was stale and kept
the postgres gate red (G-16.2-1).
2026-10-10 18:35:36 +02:00

170 lines
4.6 KiB
Go

package journal
import (
"io/fs"
"os"
"path/filepath"
"strings"
"testing"
"time"
"git.golem15.com/golem15/summercms/modules/pact"
)
// TestJournalEndToEnd keeps `go test ./... -run TestJournalEndToEnd`
// from reporting [no tests to run] in this package. The production-path
// proof lives in package journal_test.
func TestJournalEndToEnd(t *testing.T) {}
func TestPostTranslatableSmoke(t *testing.T) {
p := &Plugin{}
if p.ID() != "golem15.journal" {
t.Fatalf("ID = %q, want golem15.journal", p.ID())
}
got := p.Requires()
if len(got) != 1 || got[0] != "golem15.translate" {
t.Fatalf("Requires = %#v, want exactly [golem15.translate]", got)
}
}
func TestJournalCommands(t *testing.T) {
p := &Plugin{}
names := map[string]bool{}
for _, cmd := range p.Commands() {
names[cmd.Name] = true
}
for _, want := range []string{"journal:export-posts", "journal:import-posts"} {
if !names[want] {
t.Fatalf("Commands() missing %s", want)
}
}
foundExport, foundImport := false, false
for _, ctl := range p.AdminControllers() {
src, ok := ctl.(pact.HasAdminActions)
if !ok {
continue
}
for _, action := range src.AdminActions() {
perm := strings.Join(action.Permissions, ",")
if !strings.Contains(perm, "golem15.journal.access_import_export") {
continue
}
switch action.Name {
case "exportPosts":
foundExport = true
case "importPosts":
foundImport = true
}
}
}
if !foundExport || !foundImport {
t.Fatalf("Posts AdminActions missing import/export with access_import_export (export=%v import=%v)", foundExport, foundImport)
}
}
func TestJournalBuckets(t *testing.T) {
p := &Plugin{}
buckets := p.Buckets()
for _, name := range []string{"journal-public-api", "journal-api"} {
b, ok := buckets[name]
if !ok {
t.Fatalf("Buckets() missing %s", name)
}
if b.Max != 120 {
t.Fatalf("%s Max = %d, want 120", name, b.Max)
}
if b.Decay != time.Minute {
t.Fatalf("%s Decay = %s, want 1m", name, b.Decay)
}
if b.Key == nil {
t.Fatalf("%s Key is nil", name)
}
}
hostYAML := filepath.Join("..", "sm-grzybyfunkcjonalne-app", "config", "http.yaml")
raw, err := os.ReadFile(hostYAML)
if err != nil {
return
}
if !strings.Contains(string(raw), "_journal/api/*") {
t.Fatalf("host CORS missing _journal/api/* in %s", hostYAML)
}
}
func TestJournalSVGEmbed(t *testing.T) {
p := &Plugin{}
fsys := p.AdminFS()
f, err := fsys.Open("assets/images/journal-icon.svg")
if err != nil {
t.Fatalf("AdminFS missing journal-icon.svg: %v", err)
}
_ = f.Close()
bundle, err := fs.ReadFile(fsys, "assets/dist/blogeditor.js")
if err != nil {
t.Fatalf("AdminFS missing the Blog Editor bundle: %v", err)
}
if !strings.Contains(string(bundle), "golem15-journal-blogeditor") {
t.Fatal("blogeditor.js does not define golem15-journal-blogeditor")
}
if _, err := fs.Stat(fsys, "assets/dist/blogeditor.css"); err != nil {
t.Fatalf("AdminFS missing blogeditor.css: %v", err)
}
filter, err := fs.ReadFile(fsys, "controllers/posts/config_filter.yaml")
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(filter), "conditions:") {
t.Fatal("config_filter.yaml still has conditions")
}
fields, err := fs.ReadFile(fsys, "models/post/fields.yaml")
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(fields), "type: mlblogeditor") || !strings.Contains(string(fields), "htmlColumn: content_html") {
t.Fatal("post fields.yaml content is not mlblogeditor with htmlColumn: content_html")
}
}
func TestCabanaMarkdownFieldTypes(t *testing.T) {
path := filepath.Join("..", "summercms.go", "modules", "cabana", "form_schema.go")
raw, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read %s: %v", path, err)
}
src := string(raw)
for _, typ := range []string{`"markdown"`, `"mltext"`, `"mltextarea"`, `"mlmarkdown"`} {
if !strings.Contains(src, typ) {
t.Fatalf("form_schema.go missing %s", typ)
}
}
}
func TestNoTideJournalFixtures(t *testing.T) {
roots := []string{
filepath.Join("..", "fonoteka.go", "parity"),
filepath.Join("..", "fonoteka.go", "modules", "tide"),
filepath.Join("..", "summercms.go", "modules", "tide"),
}
needle := "/_journal/api/v1"
for _, root := range roots {
if _, err := os.Stat(root); err != nil {
continue
}
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil || d.IsDir() {
return err
}
raw, readErr := os.ReadFile(path)
if readErr != nil {
return readErr
}
if strings.Contains(string(raw), needle) {
t.Errorf("%s newly mentions %s", path, needle)
}
return nil
})
if err != nil {
t.Fatal(err)
}
}
}