Files
summercms/docs/examples/blog/console/publish_test.go
Jakub Zych dd82b8a2ad feat(11.1-05): add the walkthrough's admin controller, publish command and published_at migration
- make:admin-controller, make:command and make:migration output, finished:
  the Posts controller serves models.Post behind acme.blog.access_posts,
  WinterCMS-style form and list YAML embedded through pact.AdminAssets,
  blog:publish sets published_at by slug with a bound parameter
- the posts route lists published posts only, newest first
- Docker tests migrate an ICU pl-PL database, roll back published_at, serve
  the route and run blog:publish with a published and an opened database
- the page gains the admin controller, console command and added-column
  sections
2026-09-30 23:35:44 +02:00

45 lines
1.2 KiB
Go

package console_test
import (
"bytes"
"context"
"errors"
"testing"
"git.golem15.com/golem15/summercms/docs/examples/blog/console"
"git.golem15.com/golem15/summercms/modules/bonfire"
"gorm.io/gorm"
)
func TestPublishCommandShape(t *testing.T) {
called := false
withDB := func(ctx context.Context, fn func(*gorm.DB) error) error {
called = true
return errors.New("no database in this test")
}
cmd := console.PublishCommand(withDB)
if cmd.Name != "blog:publish" {
t.Errorf("Name = %q, want blog:publish", cmd.Name)
}
if len(cmd.Args) != 1 || cmd.Args[0].Name != "slug" || !cmd.Args[0].Required {
t.Errorf("Args = %+v, want one required slug argument", cmd.Args)
}
if cmd.Description == "" {
t.Error("Description is empty")
}
cmds := []bonfire.Command{cmd}
var out bytes.Buffer
if err := bonfire.Call(context.Background(), cmds, "blog:publish", nil, &out); err == nil {
t.Error("blog:publish without a slug returned no error")
}
if called {
t.Error("blog:publish without a slug reached the database")
}
err := bonfire.Call(context.Background(), cmds, "blog:publish", []string{"hello-world"}, &out)
if err == nil || !called {
t.Errorf("blog:publish hello-world: err = %v, called = %v; want the withDB error", err, called)
}
}