2017-10-01 12:44:49 +00:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
2017-10-02 14:19:23 +00:00
|
|
|
"testing"
|
|
|
|
|
2017-10-01 12:44:49 +00:00
|
|
|
"activitypub"
|
|
|
|
"jsonld"
|
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) {
|
2017-10-03 20:46:03 +00:00
|
|
|
obj := activitypub.AcceptNew("https://localhost/myactivity", nil)
|
2017-10-02 14:19:23 +00:00
|
|
|
obj.Name = make(activitypub.NaturalLanguageValue, 1)
|
|
|
|
obj.Name["en"] = "test"
|
2018-03-26 21:15:26 +00:00
|
|
|
obj.Name["fr"] = "teste"
|
2017-10-01 12:44:49 +00:00
|
|
|
|
2017-10-01 13:04:51 +00:00
|
|
|
ctx := jsonld.Context{URL: "https://www.w3.org/ns/activitystreams"}
|
2017-10-01 12:44:49 +00:00
|
|
|
|
2017-10-02 14:19:23 +00:00
|
|
|
data, err := jsonld.Marshal(obj, &ctx)
|
2017-10-01 12:44:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error: %v", err)
|
|
|
|
}
|
2017-10-02 14:19:23 +00:00
|
|
|
if !strings.Contains(string(data), string(ctx.URL)) {
|
|
|
|
t.Errorf("Could not find context url %#v in output %s", ctx.URL, data)
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
if !strings.Contains(string(data), string(obj.Name["en"])) {
|
|
|
|
t.Errorf("Could not find name %#v in output %s", string(obj.Name["en"]), data)
|
|
|
|
}
|
2018-03-26 21:15:26 +00:00
|
|
|
if !strings.Contains(string(data), string(obj.Name["fr"])) {
|
|
|
|
t.Errorf("Could not find name %#v in output %s", string(obj.Name["fr"]), 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-01 12:44:49 +00:00
|
|
|
}
|
2017-10-01 13:04:51 +00:00
|
|
|
|
|
|
|
func TestCreateActivityHTTPSerialization(t *testing.T) {
|
2018-03-27 13:06:06 +00:00
|
|
|
id := activitypub.ObjectID("test_object")
|
2017-10-03 20:46:03 +00:00
|
|
|
obj := activitypub.AcceptNew(id, nil)
|
2017-10-02 14:19:23 +00:00
|
|
|
obj.Name["en"] = "Accept New"
|
2017-10-01 13:04:51 +00:00
|
|
|
|
2018-03-27 14:16:07 +00:00
|
|
|
baseURI := string(activitypub.ActivityBaseURI)
|
2017-10-02 14:19:23 +00:00
|
|
|
ctx := jsonld.Context{
|
2018-03-27 14:16:07 +00:00
|
|
|
URL: jsonld.Ref(baseURI + string(obj.Type)),
|
2017-10-01 13:04:51 +00:00
|
|
|
}
|
2017-10-02 14:19:23 +00:00
|
|
|
data, err := jsonld.Marshal(obj, &ctx)
|
2017-10-01 13:04:51 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2017-10-02 14:19:23 +00:00
|
|
|
if !strings.Contains(string(data), string(ctx.URL)) {
|
|
|
|
t.Errorf("Could not find context url %#v in output %s", ctx.URL, data)
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
if !strings.Contains(string(data), string(obj.Name["en"])) {
|
|
|
|
t.Errorf("Could not find name %#v in output %s", string(obj.Name["en"]), data)
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|