mstdn/ent.Status.MarshalJSON()

master
Charles Iliya Krempeaux 2024-08-07 15:29:32 -07:00
parent d8b920bae5
commit 8da8d72789
2 changed files with 33 additions and 3 deletions

View File

@ -183,7 +183,20 @@ func (receiver *Status) MarshalJSON() ([]byte, error) {
//@TODO: Mentions //@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 //@TODO: Emojis

View File

@ -77,7 +77,24 @@ func TestStatus_JSON(t *testing.T) {
//@TODO: MediaAttachments //@TODO: MediaAttachments
//@TODO: Application //@TODO: Application
//@TODO: Mentions //@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 //@TODO: Emojis
@ -173,7 +190,7 @@ func TestStatus_JSON(t *testing.T) {
t.Logf("ACTUAL: %q", actual) t.Logf("ACTUAL: %q", actual)
t.Logf("EXPECTED:\n%s", expected) t.Logf("EXPECTED:\n%s", expected)
t.Logf("ACTUAL:\n%s", actual) t.Logf("ACTUAL:\n%s", actual)
t.Logf("STATUS:\n%v", test.Status) t.Logf("STATUS:\n%#v", test.Status)
continue continue
} }
} }