feat(api): anonymous author profile at /_journal/api/v1/authors/{author}
- Resolve {author} by golem15_bloghub_author_slug, then by login for users with a published post
- Project only id, names, login and author slug from backend_users; payload is id, slug, first_name, last_name
- JSON 404 {"error":"Author not found"} for unknown, soft-deleted and malformed values
- Document the route in README
This commit is contained in:
34
controllers/api/authors_test.go
Normal file
34
controllers/api/authors_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidAuthorParam(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
in string
|
||||
want bool
|
||||
}{
|
||||
{"slug", "jane-doe", true},
|
||||
{"dotted login", "jan.kowalski", true},
|
||||
{"at sign", "a@b", true},
|
||||
{"max bytes", strings.Repeat("a", 255), true},
|
||||
{"multibyte", "zażółć", true},
|
||||
{"empty", "", false},
|
||||
{"whitespace only", strings.TrimSpace(" \t "), false},
|
||||
{"over max bytes", strings.Repeat("a", 256), false},
|
||||
{"nul byte", "a\x00b", false},
|
||||
{"newline", "a\nb", false},
|
||||
{"tab", "a\tb", false},
|
||||
{"invalid utf8", "\xff", false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := validAuthorParam(tc.in); got != tc.want {
|
||||
t.Fatalf("validAuthorParam(%q) = %v, want %v", tc.in, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user