Allow InReplyTo to be a single item, not always an item collection

Fix tests
This commit is contained in:
Marius Orcsik 2020-12-30 14:19:02 +01:00
parent 3cc5090015
commit 22a1b093fa
No known key found for this signature in database
GPG key ID: 7970BDC7D4CB2674
2 changed files with 26 additions and 11 deletions

View file

@ -252,7 +252,7 @@ func JSONGetItem(data []byte, prop string) Item {
return i
}
case jsonparser.Array:
fallthrough
return JSONGetItems(data, prop)
case jsonparser.Object:
return JSONUnmarshalToItem(val)
case jsonparser.Number:
@ -322,9 +322,14 @@ func JSONGetItems(data []byte, prop string) ItemCollection {
}
}, prop)
case jsonparser.Object:
// this should never happen :)
it.Append(JSONGetItem(data, prop))
case jsonparser.String:
it.Append(IRI(val))
if len(val) > 0 {
it.Append(IRI(val))
}
}
if len(it) == 0 {
return nil
}
return it
}
@ -509,7 +514,7 @@ func loadObject(data []byte, o *Object) error {
o.Preview = JSONGetItem(data, "preview")
o.Image = JSONGetItem(data, "image")
o.Updated = JSONGetTime(data, "updated")
o.InReplyTo = JSONGetItems(data, "inReplyTo")
o.InReplyTo = JSONGetItem(data, "inReplyTo")
o.To = JSONGetItems(data, "to")
o.Audience = JSONGetItems(data, "audience")
o.Bto = JSONGetItems(data, "bto")

View file

@ -259,6 +259,16 @@ var allTests = testMaps{
}},
},
},
"object_no_type": testPair{
expected: true,
blank: &pub.Object{},
result: &pub.Object{
ID: pub.ID("http://www.test.example/object/1"),
Name: pub.NaturalLanguageValues{{
pub.NilLangRef, pub.Content("A Simple, non-specific object without a type"),
}},
},
},
"object_with_tags": testPair{
expected: true,
blank: &pub.Object{},
@ -333,7 +343,7 @@ var allTests = testMaps{
ID: pub.ID("http://example.com/accounts/ana"),
Type: pub.PersonType,
Name: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("ana")}},
PreferredUsername: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("ana")}},
PreferredUsername: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("Ana")}},
URL: pub.IRI("http://example.com/accounts/ana"),
Outbox: &pub.OrderedCollection{
ID: "http://example.com/accounts/ana/outbox",
@ -377,6 +387,7 @@ var allTests = testMaps{
URL: pub.IRI("http://example.com/outbox?page=2"),
Current: pub.IRI("http://example.com/outbox?page=2"),
TotalItems: 1,
StartIndex: 100,
OrderedItems: pub.ItemCollection{
&pub.Object{
ID: pub.ID("http://example.com/outbox/53c6fb47"),
@ -394,12 +405,11 @@ var allTests = testMaps{
},
"natural_language_values": {
expected: true,
blank: &pub.NaturalLanguageValues{},
blank: &pub.NaturalLanguageValues{},
result: &pub.NaturalLanguageValues{
{
pub.NilLangRef, pub.Content(`
`)},
pub.NilLangRef, pub.Content([]byte{'\n','\t', '\t', '\n'}),
},
{pub.LangRef("en"), pub.Content("Ana got apples ⓐ")},
{pub.LangRef("fr"), pub.Content("Aná a des pommes ⒜")},
{pub.LangRef("ro"), pub.Content("Ana are mere")},
@ -414,7 +424,7 @@ var allTests = testMaps{
Object: &pub.Object{
Type: pub.NoteType,
AttributedTo: pub.IRI("https://littr.git/api/accounts/anonymous"),
InReplyTo: pub.ItemCollection{pub.IRI("https://littr.git/api/accounts/system/outbox/7ca154ff")},
InReplyTo: pub.IRI("https://littr.git/api/accounts/system/outbox/7ca154ff"),
Content: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("<p>Hello world</p>")}},
To: pub.ItemCollection{pub.IRI("https://www.w3.org/ns/activitystreams#Public")},
},
@ -430,7 +440,7 @@ var allTests = testMaps{
&pub.Object{
Type: pub.NoteType,
AttributedTo: pub.IRI("https://littr.git/api/accounts/anonymous"),
InReplyTo: pub.ItemCollection{pub.IRI("https://littr.git/api/accounts/system/outbox/7ca154ff")},
InReplyTo: pub.IRI("https://littr.git/api/accounts/system/outbox/7ca154ff"),
Content: pub.NaturalLanguageValues{{pub.NilLangRef, pub.Content("<p>Hello world</p>")}},
To: pub.ItemCollection{pub.IRI("https://www.w3.org/ns/activitystreams#Public")},
},