This repository has been archived on 2022-11-27. You can view files and clone it, but cannot push or open issues or pull requests.
activitypub/activitystreams/collections_test.go

92 lines
2.1 KiB
Go

package activitystreams
import (
"reflect"
"testing"
)
func TestCollectionNew(t *testing.T) {
var testValue = ObjectID("test")
c := CollectionNew(testValue)
if c.ID != testValue {
t.Errorf("APObject Id '%v' different than expected '%v'", c.ID, testValue)
}
if c.Type != CollectionType {
t.Errorf("APObject Type '%v' different than expected '%v'", c.Type, CollectionType)
}
}
func TestOrderedCollectionNew(t *testing.T) {
var testValue = ObjectID("test")
c := OrderedCollectionNew(testValue)
if c.ID != testValue {
t.Errorf("APObject Id '%v' different than expected '%v'", c.ID, testValue)
}
if c.Type != OrderedCollectionType {
t.Errorf("APObject Type '%v' different than expected '%v'", c.Type, OrderedCollectionType)
}
}
func TestCollectionPageNew(t *testing.T) {
var testValue = ObjectID("test")
c := CollectionNew(testValue)
p := CollectionPageNew(c)
if p.PartOf != c {
t.Errorf("Invalid collection '%v'", p.PartOf)
}
}
func TestOrderedCollectionPageNew(t *testing.T) {
var testValue = ObjectID("test")
c := OrderedCollectionNew(testValue)
p := OrderedCollectionPageNew(c)
if p.PartOf != c {
t.Errorf("Invalid collection '%v'", p.PartOf)
}
}
func TestValidCollectionType(t *testing.T) {
for _, validType := range validCollectionTypes {
if !ValidCollectionType(validType) {
t.Errorf("Generic Type '%#v' should be valid", validType)
}
}
}
func Test_OrderedCollection_Append(t *testing.T) {
id := ObjectID("test")
val := Object{ID: ObjectID("grrr")}
c := OrderedCollectionNew(id)
c.Append(val)
if c.TotalItems != 1 {
t.Errorf("Inbox collection of %q should have exactly an GetID", *c.GetID())
}
if !reflect.DeepEqual(c.OrderedItems[0], val) {
t.Errorf("First item in Inbox is does not match %q", val.ID)
}
}
func Test_Collection_Append(t *testing.T) {
id := ObjectID("test")
val := Object{ID: ObjectID("grrr")}
c := CollectionNew(id)
c.Append(val)
if c.TotalItems != 1 {
t.Errorf("Inbox collection of %q should have exactly an GetID", *c.GetID())
}
if !reflect.DeepEqual(c.Items[0], val) {
t.Errorf("First item in Inbox is does not match %q", val.ID)
}
}