diff --git a/journal_api_authors_test.go b/journal_api_authors_test.go index 83a2733..046ef6e 100644 --- a/journal_api_authors_test.go +++ b/journal_api_authors_test.go @@ -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")