Debian Codegraph @

tests/integration_test.go

raw symbols SCIP
1 package tests
2
3 import (
4 "strings"
5 "testing"
6
7 j "github.com/go-ap/jsonld"
8
9 pub "github.com/go-ap/activitypub"
10 )
11
12 func TestAcceptSerialization(t *testing.T) {
13 obj := pub.AcceptNew("https://localhost/myactivity", nil)
14 obj.Name = make(pub.NaturalLanguageValues)
15 obj.Name[pub.English] = pub.Content("test")
16 obj.Name[pub.French] = pub.Content("test")
17
18 uri := "https://www.w3.org/ns/activitystreams"
19 p := j.WithContext(j.IRI(uri))
20
21 data, err := p.Marshal(obj)
22 if err != nil {
23 t.Errorf("Error: %v", err)
24 }
25
26 if !strings.Contains(string(data), uri) {
27 t.Errorf("Could not find context url %#v in output %s", p.Context, data)
28 }
29 if !strings.Contains(string(data), string(obj.ID)) {
30 t.Errorf("Could not find id %#v in output %s", string(obj.ID), data)
31 }
32 if !strings.Contains(string(data), string(obj.Name.Get(pub.English))) {
33 t.Errorf("Could not find name %#v in output %s", string(obj.Name.Get(pub.English)), data)
34 }
35 if !strings.Contains(string(data), string(obj.Name.Get(pub.French))) {
36 t.Errorf("Could not find name %#v in output %s", string(obj.Name.Get(pub.French)), data)
37 }
38 rawType, _ := j.Marshal(obj.Type)
39 if !strings.Contains(string(data), string(rawType)) {
40 t.Errorf("Could not find activity type %#v in output %s", obj.Type, data)
41 }
42 }
43
44 func TestCreateActivityHTTPSerialization(t *testing.T) {
45 id := pub.ID("test_object")
46 obj := pub.AcceptNew(id, nil)
47 obj.Name[pub.English] = pub.Content("Accept New")
48
49 uri := string(pub.ActivityBaseURI)
50
51 data, err := j.WithContext(j.IRI(uri)).Marshal(obj)
52 if err != nil {
53 t.Errorf("Error: %v", err)
54 }
55
56 if !strings.Contains(string(data), uri) {
57 t.Errorf("Could not find context url %#v in output %s", j.GetContext(), data)
58 }
59 if !strings.Contains(string(data), string(obj.ID)) {
60 t.Errorf("Could not find id %#v in output %s", string(obj.ID), data)
61 }
62 if !strings.Contains(string(data), obj.Name.Get(pub.English).String()) {
63 t.Errorf("Could not find name %s in output %s", obj.Name.Get(pub.English), data)
64 }
65 rawType, _ := j.Marshal(obj.Type)
66 if !strings.Contains(string(data), string(rawType)) {
67 t.Errorf("Could not find activity type %#v in output %s", obj.Type, data)
68 }
69 }