2019-12-03 19:45:26 +00:00
|
|
|
package tests
|
2017-10-01 12:44:49 +00:00
|
|
|
|
|
|
|
import (
|
2017-10-02 14:19:23 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-01-22 15:37:30 +00:00
|
|
|
j "github.com/go-ap/jsonld"
|
2018-07-06 10:48:04 +00:00
|
|
|
|
2019-12-03 19:45:26 +00:00
|
|
|
pub "github.com/go-ap/activitypub"
|
2017-10-02 14:19:23 +00:00
|
|
|
"strings"
|
2017-10-01 12:44:49 +00:00
|
|
|
)
|
|
|
|
|
2017-10-01 12:55:20 +00:00
|
|
|
func TestAcceptSerialization(t *testing.T) {
|
2019-12-03 19:45:26 +00:00
|
|
|
obj := pub.AcceptNew("https://localhost/myactivity", nil)
|
|
|
|
obj.Name = make(pub.NaturalLanguageValues, 1)
|
2018-09-02 13:41:53 +00:00
|
|
|
obj.Name.Set("en", "test")
|
|
|
|
obj.Name.Set("fr", "teste")
|
2017-10-01 12:44:49 +00:00
|
|
|
|
2018-08-01 08:45:21 +00:00
|
|
|
uri := "https://www.w3.org/ns/activitystreams"
|
|
|
|
p := j.WithContext(j.IRI(uri))
|
2017-10-01 12:44:49 +00:00
|
|
|
|
2018-08-01 08:45:21 +00:00
|
|
|
data, err := p.Marshal(obj)
|
2017-10-01 12:44:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error: %v", err)
|
|
|
|
}
|
2018-07-16 11:26:26 +00:00
|
|
|
|
2018-08-01 08:45:21 +00:00
|
|
|
if !strings.Contains(string(data), uri) {
|
|
|
|
t.Errorf("Could not find context url %#v in output %s", p.Context, data)
|
2017-10-02 14:19:23 +00:00
|
|
|
}
|
2018-04-08 16:55:25 +00:00
|
|
|
if !strings.Contains(string(data), string(obj.ID)) {
|
|
|
|
t.Errorf("Could not find id %#v in output %s", string(obj.ID), data)
|
2017-10-02 14:19:23 +00:00
|
|
|
}
|
2018-09-02 13:41:53 +00:00
|
|
|
if !strings.Contains(string(data), string(obj.Name.Get("en"))) {
|
|
|
|
t.Errorf("Could not find name %#v in output %s", string(obj.Name.Get("en")), data)
|
2017-10-02 14:19:23 +00:00
|
|
|
}
|
2018-09-02 13:41:53 +00:00
|
|
|
if !strings.Contains(string(data), string(obj.Name.Get("fr"))) {
|
|
|
|
t.Errorf("Could not find name %#v in output %s", string(obj.Name.Get("fr")), data)
|
2018-03-26 21:15:26 +00:00
|
|
|
}
|
2017-10-02 14:19:23 +00:00
|
|
|
if !strings.Contains(string(data), string(obj.Type)) {
|
|
|
|
t.Errorf("Could not find activity type %#v in output %s", obj.Type, data)
|
|
|
|
}
|
2017-10-01 12:44:49 +00:00
|
|
|
}
|
2017-10-01 13:04:51 +00:00
|
|
|
|
|
|
|
func TestCreateActivityHTTPSerialization(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
id := pub.ID("test_object")
|
2019-12-03 19:45:26 +00:00
|
|
|
obj := pub.AcceptNew(id, nil)
|
2018-10-04 18:33:32 +00:00
|
|
|
obj.Name.Set("en", "Accept New")
|
2017-10-01 13:04:51 +00:00
|
|
|
|
2019-12-03 19:45:26 +00:00
|
|
|
uri := string(pub.ActivityBaseURI)
|
2018-08-01 08:45:21 +00:00
|
|
|
|
|
|
|
data, err := j.WithContext(j.IRI(uri)).Marshal(obj)
|
2017-10-01 13:04:51 +00:00
|
|
|
if err != nil {
|
2018-08-01 08:45:21 +00:00
|
|
|
t.Errorf("Error: %v", err)
|
2017-10-01 13:04:51 +00:00
|
|
|
}
|
2018-08-01 08:45:21 +00:00
|
|
|
|
|
|
|
if !strings.Contains(string(data), uri) {
|
|
|
|
t.Errorf("Could not find context url %#v in output %s", j.GetContext(), data)
|
2017-10-02 14:19:23 +00:00
|
|
|
}
|
2018-04-08 16:55:25 +00:00
|
|
|
if !strings.Contains(string(data), string(obj.ID)) {
|
|
|
|
t.Errorf("Could not find id %#v in output %s", string(obj.ID), data)
|
2017-10-02 14:19:23 +00:00
|
|
|
}
|
2020-08-25 11:45:52 +00:00
|
|
|
if !strings.Contains(string(data), obj.Name.Get("en").String()) {
|
2018-09-02 13:41:53 +00:00
|
|
|
t.Errorf("Could not find name %s in output %s", obj.Name.Get("en"), data)
|
2017-10-02 14:19:23 +00:00
|
|
|
}
|
|
|
|
if !strings.Contains(string(data), string(obj.Type)) {
|
|
|
|
t.Errorf("Could not find activity type %#v in output %s", obj.Type, data)
|
2017-10-02 09:53:09 +00:00
|
|
|
}
|
2017-10-01 13:04:51 +00:00
|
|
|
}
|