test: author profile with only a subtitle and with odd metadata

TestJournalAuthorProfile covers a backend user with only a subtitle and
metadata that is empty, null, not JSON or not strings: empty strings and a
null avatar, with the key set unchanged.
This commit is contained in:
Jakub Zych
2026-10-20 19:20:33 +02:00
parent fe1bbc2ba6
commit 48d6593692

View File

@@ -169,6 +169,31 @@ func TestJournalAuthorProfile(t *testing.T) {
t.Fatalf("team avatar = %v, want a URL ending in %s", data["avatar"], avatarDisk)
}
// Only a subtitle: the description stays an empty string and the
// avatar null.
subID := insertBackendUser(t, env, "Sub", "Title", "subonly", "sub-only", false)
if err := env.gdb.Exec(`UPDATE backend_users SET metadata = ? WHERE id = ?`, `{"subtitle":"Editor"}`, subID).Error; err != nil {
t.Fatal(err)
}
data, _ = authorProfileOK(t, env, "sub-only")
if data["subtitle"] != "Editor" || data["description"] != "" || data["avatar"] != nil {
t.Fatalf("sub-only profile = %v, want subtitle Editor, an empty description and a null avatar", data)
}
// Metadata that is empty, JSON null, not JSON or not strings never
// breaks the payload: empty strings and a null avatar.
for i, meta := range []string{"", "null", "{not json", `{"subtitle":7,"description":["x"]}`, `{"description":null}`} {
slug := "odd-meta-" + strconv.Itoa(i)
id := insertBackendUser(t, env, "Odd", "Meta", "oddmeta"+strconv.Itoa(i), slug, false)
if err := env.gdb.Exec(`UPDATE backend_users SET metadata = ? WHERE id = ?`, meta, id).Error; err != nil {
t.Fatal(err)
}
data, _ = authorProfileOK(t, env, slug)
if data["subtitle"] != "" || data["description"] != "" || data["avatar"] != nil {
t.Fatalf("metadata %q: profile = %v, want empty subtitle and description and a null avatar", meta, data)
}
}
// A slug is an explicit opt-in: it resolves with no posts at all.
insertBackendUser(t, env, "Fresh", "Author", "fresh", "fresh-author", false)
data, _ = authorProfileOK(t, env, "fresh-author")