- Public and write groups under /_journal/api/v1 with journal-public-api and journal-api buckets (Max 120)
- Index omits drafts and future published_at; per_page default 9 max 30
- Optional backend JWT on GET; missing Bearer on writes returns PHP {error:Authentication required}
Co-authored-by: Cursor <cursoragent@cursor.com>
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package journal
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|