From 8da8d7278952bdd429350ffa7d27faefbff0a8bb Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 7 Aug 2024 15:29:32 -0700 Subject: [PATCH] mstdn/ent.Status.MarshalJSON() --- ent/status.go | 15 ++++++++++++++- ent/status_marshaljson_test.go | 21 +++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ent/status.go b/ent/status.go index aa5c0c6..b40d988 100644 --- a/ent/status.go +++ b/ent/status.go @@ -183,7 +183,20 @@ func (receiver *Status) MarshalJSON() ([]byte, error) { //@TODO: Mentions -//@TODO: Tags + { + vals := receiver.Tags + if 0 < len(vals) { + const name = "tags" + p = append(p, `,"tags":`...) + + bytes, err := json.Marshal(vals) + if nil != err { + return nil, erorr.Errorf("problem marshaling %q: %w", name, err) + } + + p = append(p, bytes...) + } + } //@TODO: Emojis diff --git a/ent/status_marshaljson_test.go b/ent/status_marshaljson_test.go index 91761ef..cdbf05b 100644 --- a/ent/status_marshaljson_test.go +++ b/ent/status_marshaljson_test.go @@ -77,7 +77,24 @@ func TestStatus_JSON(t *testing.T) { //@TODO: MediaAttachments //@TODO: Application //@TODO: Mentions -//@TODO: Tags + + { + Status:Status{ + ID: opt.Something("123"), + Tags: []Tag{ + Tag{ + Name:opt.Something("akkoma"), + URL:opt.Something("https://example.com/tags/akkoma"), + }, + Tag{ + Name:opt.Something("fediverse"), + URL:opt.Something("https://example.com/tags/fediverse"), + }, + }, + }, + Expected: `{"id":"123","tags":[{"name":"akkoma","url":"https://example.com/tags/akkoma"},{"name":"fediverse","url":"https://example.com/tags/fediverse"}]}`, + }, + //@TODO: Emojis @@ -173,7 +190,7 @@ func TestStatus_JSON(t *testing.T) { t.Logf("ACTUAL: %q", actual) t.Logf("EXPECTED:\n%s", expected) t.Logf("ACTUAL:\n%s", actual) - t.Logf("STATUS:\n%v", test.Status) + t.Logf("STATUS:\n%#v", test.Status) continue } }