2019-12-03 16:23:59 +00:00
|
|
|
package activitypub
|
2017-09-11 21:10:56 +00:00
|
|
|
|
2018-11-10 20:58:12 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2019-12-18 16:34:47 +00:00
|
|
|
"reflect"
|
2018-11-10 20:58:12 +00:00
|
|
|
"testing"
|
2019-12-18 16:34:47 +00:00
|
|
|
"time"
|
2018-11-10 20:58:12 +00:00
|
|
|
)
|
2017-09-11 21:10:56 +00:00
|
|
|
|
|
|
|
func TestActivityNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-10-02 09:53:09 +00:00
|
|
|
var testType ActivityVocabularyType = "Accept"
|
2017-09-11 21:10:56 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := ActivityNew(testValue, testType, nil)
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-11 21:10:56 +00:00
|
|
|
}
|
|
|
|
if a.Type != testType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, testType)
|
|
|
|
}
|
2017-09-12 08:54:21 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
g := ActivityNew(testValue, "", nil)
|
2017-09-12 08:54:21 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if g.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", g.ID, testValue)
|
2017-09-12 08:54:21 +00:00
|
|
|
}
|
|
|
|
if g.Type != ActivityType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", g.Type, ActivityType)
|
|
|
|
}
|
2017-09-11 21:10:56 +00:00
|
|
|
}
|
2017-09-12 08:54:21 +00:00
|
|
|
|
2017-09-12 16:53:41 +00:00
|
|
|
func TestAcceptNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := AcceptNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != AcceptType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, AcceptType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-03-27 15:40:25 +00:00
|
|
|
a := AddNew(testValue, nil, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != AddType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, AddType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAnnounceNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := AnnounceNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != AnnounceType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, AnnounceType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlockNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := BlockNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != BlockType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, BlockType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := CreateNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != CreateType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, CreateType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := DeleteNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != DeleteType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, DeleteType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDislikeNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := DislikeNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != DislikeType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, DislikeType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFlagNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := FlagNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != FlagType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, FlagType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFollowNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := FollowNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != FollowType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, FollowType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIgnoreNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := IgnoreNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != IgnoreType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, IgnoreType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInviteNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := InviteNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != InviteType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, InviteType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJoinNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := JoinNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != JoinType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, JoinType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLeaveNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := LeaveNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != LeaveType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, LeaveType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLikeNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := LikeNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != LikeType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, LikeType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListenNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := ListenNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != ListenType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, ListenType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMoveNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := MoveNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != MoveType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, MoveType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOfferNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := OfferNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != OfferType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, OfferType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRejectNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := RejectNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != RejectType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, RejectType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := ReadNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != ReadType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, ReadType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-03-27 15:40:25 +00:00
|
|
|
a := RemoveNew(testValue, nil, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != RemoveType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, RemoveType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTentativeRejectNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := TentativeRejectNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != TentativeRejectType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, TentativeRejectType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTentativeAcceptNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := TentativeAcceptNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != TentativeAcceptType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, TentativeAcceptType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUndoNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := UndoNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != UndoType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, UndoType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := UpdateNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != UpdateType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, UpdateType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestViewNew(t *testing.T) {
|
2019-12-05 18:02:15 +00:00
|
|
|
var testValue = ID("test")
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2017-10-03 20:46:03 +00:00
|
|
|
a := ViewNew(testValue, nil)
|
2017-09-12 16:53:41 +00:00
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if a.ID != testValue {
|
|
|
|
t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
|
2017-09-12 16:53:41 +00:00
|
|
|
}
|
|
|
|
if a.Type != ViewType {
|
|
|
|
t.Errorf("Activity Type '%v' different than expected '%v'", a.Type, ViewType)
|
|
|
|
}
|
2017-09-12 20:37:34 +00:00
|
|
|
}
|
2018-06-05 19:54:56 +00:00
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
func TestActivityRecipients(t *testing.T) {
|
2018-06-05 19:54:56 +00:00
|
|
|
bob := PersonNew("bob")
|
|
|
|
alice := PersonNew("alice")
|
|
|
|
foo := OrganizationNew("foo")
|
|
|
|
bar := GroupNew("bar")
|
|
|
|
|
|
|
|
a := ActivityNew("t", "test", nil)
|
|
|
|
|
|
|
|
a.To.Append(bob)
|
|
|
|
a.To.Append(alice)
|
|
|
|
a.To.Append(foo)
|
|
|
|
a.To.Append(bar)
|
|
|
|
if len(a.To) != 4 {
|
|
|
|
t.Errorf("%T.To should have exactly 4(four) elements, not %d", a, len(a.To))
|
|
|
|
}
|
|
|
|
|
|
|
|
a.To.Append(bar)
|
|
|
|
a.To.Append(alice)
|
|
|
|
a.To.Append(foo)
|
|
|
|
a.To.Append(bob)
|
|
|
|
if len(a.To) != 8 {
|
|
|
|
t.Errorf("%T.To should have exactly 8(eight) elements, not %d", a, len(a.To))
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
a.Recipients()
|
2018-06-05 19:54:56 +00:00
|
|
|
if len(a.To) != 4 {
|
|
|
|
t.Errorf("%T.To should have exactly 4(four) elements, not %d", a, len(a.To))
|
|
|
|
}
|
|
|
|
|
|
|
|
b := ActivityNew("t", "test", nil)
|
|
|
|
|
|
|
|
b.To.Append(bar)
|
|
|
|
b.To.Append(alice)
|
|
|
|
b.To.Append(foo)
|
|
|
|
b.To.Append(bob)
|
|
|
|
b.Bto.Append(bar)
|
|
|
|
b.Bto.Append(alice)
|
|
|
|
b.Bto.Append(foo)
|
|
|
|
b.Bto.Append(bob)
|
|
|
|
b.CC.Append(bar)
|
|
|
|
b.CC.Append(alice)
|
|
|
|
b.CC.Append(foo)
|
|
|
|
b.CC.Append(bob)
|
|
|
|
b.BCC.Append(bar)
|
|
|
|
b.BCC.Append(alice)
|
|
|
|
b.BCC.Append(foo)
|
|
|
|
b.BCC.Append(bob)
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
b.Recipients()
|
2018-06-05 19:54:56 +00:00
|
|
|
if len(b.To) != 4 {
|
|
|
|
t.Errorf("%T.To should have exactly 4(four) elements, not %d", b, len(b.To))
|
|
|
|
}
|
|
|
|
if len(b.Bto) != 0 {
|
|
|
|
t.Errorf("%T.Bto should have exactly 0(zero) elements, not %d", b, len(b.Bto))
|
|
|
|
}
|
|
|
|
if len(b.CC) != 0 {
|
|
|
|
t.Errorf("%T.CC should have exactly 0(zero) elements, not %d", b, len(b.CC))
|
|
|
|
}
|
|
|
|
if len(b.BCC) != 0 {
|
|
|
|
t.Errorf("%T.BCC should have exactly 0(zero) elements, not %d", b, len(b.BCC))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
func TestBlockRecipients(t *testing.T) {
|
2018-06-05 19:54:56 +00:00
|
|
|
bob := PersonNew("bob")
|
|
|
|
alice := PersonNew("alice")
|
|
|
|
foo := OrganizationNew("foo")
|
|
|
|
bar := GroupNew("bar")
|
|
|
|
|
|
|
|
a := BlockNew("bbb", bob)
|
|
|
|
|
|
|
|
a.To.Append(bob)
|
|
|
|
a.To.Append(alice)
|
|
|
|
a.To.Append(foo)
|
|
|
|
a.To.Append(bar)
|
|
|
|
if len(a.To) != 4 {
|
|
|
|
t.Errorf("%T.To should have exactly 4(four) elements, not %d", a, len(a.To))
|
|
|
|
}
|
|
|
|
|
|
|
|
a.To.Append(bar)
|
|
|
|
a.To.Append(alice)
|
|
|
|
a.To.Append(foo)
|
|
|
|
a.To.Append(bob)
|
|
|
|
if len(a.To) != 8 {
|
|
|
|
t.Errorf("%T.To should have exactly 8(eight) elements, not %d", a, len(a.To))
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
a.Recipients()
|
2019-12-03 18:59:20 +00:00
|
|
|
if len(a.To) != 3 {
|
|
|
|
t.Errorf("%T.To should have exactly 3(three) elements, not %d", a, len(a.To))
|
2018-06-05 19:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b := BlockNew("t", bob)
|
|
|
|
|
|
|
|
b.To.Append(bar)
|
|
|
|
b.To.Append(alice)
|
|
|
|
b.To.Append(foo)
|
|
|
|
b.To.Append(bob)
|
|
|
|
b.Bto.Append(bar)
|
|
|
|
b.Bto.Append(alice)
|
|
|
|
b.Bto.Append(foo)
|
|
|
|
b.Bto.Append(bob)
|
|
|
|
b.CC.Append(bar)
|
|
|
|
b.CC.Append(alice)
|
|
|
|
b.CC.Append(foo)
|
|
|
|
b.CC.Append(bob)
|
|
|
|
b.BCC.Append(bar)
|
|
|
|
b.BCC.Append(alice)
|
|
|
|
b.BCC.Append(foo)
|
|
|
|
b.BCC.Append(bob)
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
b.Recipients()
|
2019-12-03 18:59:20 +00:00
|
|
|
if len(b.To) != 3 {
|
|
|
|
t.Errorf("%T.To should have exactly 3(three) elements, not %d", b, len(b.To))
|
2018-06-05 19:54:56 +00:00
|
|
|
}
|
|
|
|
if len(b.Bto) != 0 {
|
|
|
|
t.Errorf("%T.Bto should have exactly 0(zero) elements, not %d", b, len(b.Bto))
|
|
|
|
}
|
|
|
|
if len(b.CC) != 0 {
|
|
|
|
t.Errorf("%T.CC should have exactly 0(zero) elements, not %d", b, len(b.CC))
|
|
|
|
}
|
|
|
|
if len(b.BCC) != 0 {
|
|
|
|
t.Errorf("%T.BCC should have exactly 0(zero) elements, not %d", b, len(b.BCC))
|
|
|
|
}
|
2018-11-10 20:58:12 +00:00
|
|
|
var err error
|
2019-12-05 18:02:15 +00:00
|
|
|
recIds := make([]ID, 0)
|
2018-11-10 20:58:12 +00:00
|
|
|
err = checkDedup(b.To, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(b.Bto, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(b.CC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(b.BCC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2018-06-05 19:54:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
func TestCreate_Recipients(t *testing.T) {
|
2018-11-10 20:58:12 +00:00
|
|
|
to := PersonNew("bob")
|
|
|
|
o := ObjectNew(ArticleType)
|
|
|
|
cc := PersonNew("alice")
|
|
|
|
|
|
|
|
o.ID = "something"
|
|
|
|
|
|
|
|
c := CreateNew("act", o)
|
|
|
|
c.To.Append(to)
|
|
|
|
c.CC.Append(cc)
|
|
|
|
c.BCC.Append(cc)
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
c.Recipients()
|
2018-11-10 20:58:12 +00:00
|
|
|
|
|
|
|
var err error
|
2019-12-05 18:02:15 +00:00
|
|
|
recIds := make([]ID, 0)
|
2018-11-10 20:58:12 +00:00
|
|
|
err = checkDedup(c.To, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(c.Bto, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(c.CC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(c.BCC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
func TestDislike_Recipients(t *testing.T) {
|
2018-11-10 20:58:12 +00:00
|
|
|
to := PersonNew("bob")
|
|
|
|
o := ObjectNew(ArticleType)
|
|
|
|
cc := PersonNew("alice")
|
|
|
|
|
|
|
|
o.ID = "something"
|
|
|
|
|
|
|
|
d := DislikeNew("act", o)
|
|
|
|
d.To.Append(to)
|
|
|
|
d.CC.Append(cc)
|
|
|
|
d.BCC.Append(cc)
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
d.Recipients()
|
2018-11-10 20:58:12 +00:00
|
|
|
|
|
|
|
var err error
|
2019-12-05 18:02:15 +00:00
|
|
|
recIds := make([]ID, 0)
|
2018-11-10 20:58:12 +00:00
|
|
|
err = checkDedup(d.To, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(d.Bto, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(d.CC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(d.BCC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
func TestLike_Recipients(t *testing.T) {
|
2018-11-10 20:58:12 +00:00
|
|
|
to := PersonNew("bob")
|
|
|
|
o := ObjectNew(ArticleType)
|
|
|
|
cc := PersonNew("alice")
|
|
|
|
|
|
|
|
o.ID = "something"
|
|
|
|
|
|
|
|
l := LikeNew("act", o)
|
|
|
|
l.To.Append(to)
|
|
|
|
l.CC.Append(cc)
|
|
|
|
l.BCC.Append(cc)
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
l.Recipients()
|
2018-11-10 20:58:12 +00:00
|
|
|
|
|
|
|
var err error
|
2019-12-05 18:02:15 +00:00
|
|
|
recIds := make([]ID, 0)
|
2018-11-10 20:58:12 +00:00
|
|
|
err = checkDedup(l.To, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(l.Bto, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(l.CC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(l.BCC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
func TestUpdate_Recipients(t *testing.T) {
|
2018-11-10 20:58:12 +00:00
|
|
|
to := PersonNew("bob")
|
|
|
|
o := ObjectNew(ArticleType)
|
|
|
|
cc := PersonNew("alice")
|
|
|
|
|
|
|
|
o.ID = "something"
|
|
|
|
|
|
|
|
u := UpdateNew("act", o)
|
|
|
|
u.To.Append(to)
|
|
|
|
u.CC.Append(cc)
|
|
|
|
u.BCC.Append(cc)
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
u.Recipients()
|
2018-11-10 20:58:12 +00:00
|
|
|
|
|
|
|
var err error
|
2019-12-05 18:02:15 +00:00
|
|
|
recIds := make([]ID, 0)
|
2018-11-10 20:58:12 +00:00
|
|
|
err = checkDedup(u.To, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(u.Bto, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(u.CC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(u.BCC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2018-06-05 19:54:56 +00:00
|
|
|
}
|
2018-11-10 20:58:12 +00:00
|
|
|
|
2018-06-09 12:05:46 +00:00
|
|
|
func TestActivity_GetID(t *testing.T) {
|
2018-06-09 11:06:55 +00:00
|
|
|
a := ActivityNew("test", ActivityType, Person{})
|
|
|
|
|
2019-12-03 15:26:43 +00:00
|
|
|
if a.GetID() != "test" {
|
|
|
|
t.Errorf("%T should return an empty %T object. Received %#v", a, a.GetID(), a.GetID())
|
2018-06-09 11:06:55 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-09 12:05:46 +00:00
|
|
|
func TestActivity_GetIDGetType(t *testing.T) {
|
2018-06-09 11:06:55 +00:00
|
|
|
a := ActivityNew("test", ActivityType, Person{})
|
|
|
|
|
2019-12-03 15:26:43 +00:00
|
|
|
if a.GetID() != "test" || a.GetType() != ActivityType {
|
|
|
|
t.Errorf("%T should not return an empty %T object. Received %#v", a, a.GetID(), a.GetID())
|
2018-06-09 11:06:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestActivity_IsLink(t *testing.T) {
|
|
|
|
a := ActivityNew("test", ActivityType, Person{})
|
|
|
|
|
|
|
|
if a.IsLink() {
|
|
|
|
t.Errorf("%T should not respond true to IsLink", a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func TestActivity_IsObject(t *testing.T) {
|
|
|
|
a := ActivityNew("test", ActivityType, Person{})
|
|
|
|
|
|
|
|
if !a.IsObject() {
|
|
|
|
t.Errorf("%T should respond true to IsObject", a)
|
|
|
|
}
|
|
|
|
}
|
2018-11-10 20:58:12 +00:00
|
|
|
|
2019-12-05 18:02:15 +00:00
|
|
|
func checkDedup(list ItemCollection, recIds *[]ID) error {
|
2018-11-10 20:58:12 +00:00
|
|
|
for _, rec := range list {
|
|
|
|
for _, id := range *recIds {
|
2019-12-03 15:26:43 +00:00
|
|
|
if rec.GetID() == id {
|
2018-11-10 20:58:12 +00:00
|
|
|
return fmt.Errorf("%T[%s] already stored in recipients list, Deduplication faild", rec, id)
|
|
|
|
}
|
|
|
|
}
|
2019-12-03 15:26:43 +00:00
|
|
|
*recIds = append(*recIds, rec.GetID())
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
func TestActivity_Recipients(t *testing.T) {
|
2018-11-10 20:58:12 +00:00
|
|
|
to := PersonNew("bob")
|
|
|
|
o := ObjectNew(ArticleType)
|
|
|
|
cc := PersonNew("alice")
|
|
|
|
|
|
|
|
o.ID = "something"
|
|
|
|
|
|
|
|
c := ActivityNew("act", ActivityType, o)
|
|
|
|
c.To.Append(to)
|
|
|
|
c.CC.Append(cc)
|
|
|
|
c.BCC.Append(cc)
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
c.Recipients()
|
2018-11-10 20:58:12 +00:00
|
|
|
|
|
|
|
var err error
|
2019-12-05 18:02:15 +00:00
|
|
|
recIds := make([]ID, 0)
|
2018-11-10 20:58:12 +00:00
|
|
|
err = checkDedup(c.To, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(c.Bto, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(c.CC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(c.BCC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2018-06-09 11:06:55 +00:00
|
|
|
}
|
2018-11-10 20:58:12 +00:00
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
func TestBlock_Recipients(t *testing.T) {
|
2018-11-10 20:58:12 +00:00
|
|
|
to := PersonNew("bob")
|
|
|
|
o := ObjectNew(ArticleType)
|
|
|
|
cc := PersonNew("alice")
|
|
|
|
|
|
|
|
o.ID = "something"
|
|
|
|
|
|
|
|
b := BlockNew("act", o)
|
|
|
|
b.To.Append(to)
|
|
|
|
b.CC.Append(cc)
|
|
|
|
b.BCC.Append(cc)
|
|
|
|
|
2019-05-26 20:25:44 +00:00
|
|
|
b.Recipients()
|
2018-11-10 20:58:12 +00:00
|
|
|
|
|
|
|
var err error
|
2019-12-05 18:02:15 +00:00
|
|
|
recIds := make([]ID, 0)
|
2018-11-10 20:58:12 +00:00
|
|
|
err = checkDedup(b.To, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(b.Bto, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(b.CC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
err = checkDedup(b.BCC, &recIds)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2018-06-09 11:06:55 +00:00
|
|
|
}
|
2018-11-04 19:31:04 +00:00
|
|
|
|
2018-11-10 20:58:12 +00:00
|
|
|
func TestActivity_UnmarshalJSON(t *testing.T) {
|
|
|
|
a := Activity{}
|
|
|
|
|
|
|
|
dataEmpty := []byte("{}")
|
|
|
|
a.UnmarshalJSON(dataEmpty)
|
|
|
|
if a.ID != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty ID, received %q", a, a.ID)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if a.Type != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Type, received %q", a, a.Type)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if a.AttributedTo != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", a, a.AttributedTo)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(a.Name) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Name, received %q", a, a.Name)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(a.Summary) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Summary, received %q", a, a.Summary)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(a.Content) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Content, received %q", a, a.Content)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if a.URL != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty URL, received %v", a, a.URL)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !a.Published.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Published, received %q", a, a.Published)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !a.StartTime.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", a, a.StartTime)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !a.Updated.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Updated, received %q", a, a.Updated)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreate_UnmarshalJSON(t *testing.T) {
|
|
|
|
c := Create{}
|
|
|
|
|
|
|
|
dataEmpty := []byte("{}")
|
|
|
|
c.UnmarshalJSON(dataEmpty)
|
|
|
|
if c.ID != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty ID, received %q", c, c.ID)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if c.Type != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Type, received %q", c, c.Type)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if c.AttributedTo != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", c, c.AttributedTo)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(c.Name) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Name, received %q", c, c.Name)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(c.Summary) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Summary, received %q", c, c.Summary)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(c.Content) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Content, received %q", c, c.Content)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if c.URL != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty URL, received %v", c, c.URL)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !c.Published.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Published, received %q", c, c.Published)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !c.StartTime.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", c, c.StartTime)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !c.Updated.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Updated, received %q", c, c.Updated)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDislike_UnmarshalJSON(t *testing.T) {
|
|
|
|
d := Dislike{}
|
|
|
|
|
|
|
|
dataEmpty := []byte("{}")
|
|
|
|
d.UnmarshalJSON(dataEmpty)
|
|
|
|
if d.ID != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty ID, received %q", d, d.ID)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if d.Type != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Type, received %q", d, d.Type)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if d.AttributedTo != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", d, d.AttributedTo)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(d.Name) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Name, received %q", d, d.Name)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(d.Summary) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Summary, received %q", d, d.Summary)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(d.Content) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Content, received %q", d, d.Content)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if d.URL != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty URL, received %v", d, d.URL)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !d.Published.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Published, received %q", d, d.Published)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !d.StartTime.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", d, d.StartTime)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !d.Updated.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Updated, received %q", d, d.Updated)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLike_UnmarshalJSON(t *testing.T) {
|
|
|
|
l := Like{}
|
|
|
|
|
|
|
|
dataEmpty := []byte("{}")
|
|
|
|
l.UnmarshalJSON(dataEmpty)
|
|
|
|
if l.ID != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty ID, received %q", l, l.ID)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if l.Type != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Type, received %q", l, l.Type)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if l.AttributedTo != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", l, l.AttributedTo)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(l.Name) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Name, received %q", l, l.Name)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(l.Summary) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Summary, received %q", l, l.Summary)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(l.Content) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Content, received %q", l, l.Content)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if l.URL != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty URL, received %v", l, l.URL)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !l.Published.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Published, received %q", l, l.Published)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !l.StartTime.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", l, l.StartTime)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !l.Updated.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Updated, received %q", l, l.Updated)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdate_UnmarshalJSON(t *testing.T) {
|
|
|
|
u := Update{}
|
|
|
|
|
|
|
|
dataEmpty := []byte("{}")
|
|
|
|
u.UnmarshalJSON(dataEmpty)
|
|
|
|
if u.ID != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty ID, received %q", u, u.ID)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if u.Type != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Type, received %q", u, u.Type)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if u.AttributedTo != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", u, u.AttributedTo)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(u.Name) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Name, received %q", u, u.Name)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(u.Summary) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Summary, received %q", u, u.Summary)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if len(u.Content) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Content, received %q", u, u.Content)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if u.URL != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty URL, received %v", u, u.URL)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !u.Published.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Published, received %q", u, u.Published)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !u.StartTime.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", u, u.StartTime)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
if !u.Updated.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object %T should have empty Updated, received %q", u, u.Updated)
|
2018-11-10 20:58:12 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-04 22:52:14 +00:00
|
|
|
|
|
|
|
func TestToActivity(t *testing.T) {
|
2019-05-30 18:44:02 +00:00
|
|
|
var it Item
|
2019-12-05 18:02:15 +00:00
|
|
|
act := ActivityNew(ID("test"), CreateType, nil)
|
2019-05-30 18:44:02 +00:00
|
|
|
it = act
|
|
|
|
|
|
|
|
a, err := ToActivity(it)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if a != act {
|
|
|
|
t.Errorf("Invalid activity returned by ToActivity #%v", a)
|
|
|
|
}
|
|
|
|
|
|
|
|
ob := ObjectNew(ArticleType)
|
|
|
|
it = ob
|
|
|
|
|
|
|
|
o, err := ToActivity(it)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Error returned when calling ToActivity with object should not be nil")
|
|
|
|
}
|
|
|
|
if o != nil {
|
|
|
|
t.Errorf("Invalid return by ToActivity #%v, should have been nil", o)
|
|
|
|
}
|
2019-05-04 22:52:14 +00:00
|
|
|
}
|
2019-05-11 08:31:19 +00:00
|
|
|
|
2019-05-11 09:53:32 +00:00
|
|
|
func TestFlattenActivityProperties(t *testing.T) {
|
2019-05-11 08:31:19 +00:00
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
|
|
|
|
2019-12-03 14:27:57 +00:00
|
|
|
func TestValidEventRSVPActivityType(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
|
|
|
func TestValidGroupManagementActivityType(t *testing.T) {
|
2019-05-11 08:31:19 +00:00
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
2019-05-16 09:08:27 +00:00
|
|
|
|
2019-12-03 14:27:57 +00:00
|
|
|
func TestActivity_Clean(t *testing.T) {
|
2019-05-16 09:08:27 +00:00
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
2019-12-03 14:27:57 +00:00
|
|
|
|
|
|
|
func TestActivity_IsCollection(t *testing.T) {
|
2019-05-16 09:08:27 +00:00
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
2019-12-15 18:01:29 +00:00
|
|
|
|
|
|
|
func TestActivity_GetLink(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestActivity_GetType(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
2019-12-19 13:47:32 +00:00
|
|
|
}
|
2019-12-18 16:34:47 +00:00
|
|
|
|
|
|
|
func TestActivity_MarshalJSON(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
ID ID
|
|
|
|
Type ActivityVocabularyType
|
|
|
|
Name NaturalLanguageValues
|
|
|
|
Attachment Item
|
|
|
|
AttributedTo Item
|
|
|
|
Audience ItemCollection
|
|
|
|
Content NaturalLanguageValues
|
|
|
|
Context Item
|
|
|
|
MediaType MimeType
|
|
|
|
EndTime time.Time
|
|
|
|
Generator Item
|
|
|
|
Icon Item
|
|
|
|
Image Item
|
|
|
|
InReplyTo Item
|
|
|
|
Location Item
|
|
|
|
Preview Item
|
|
|
|
Published time.Time
|
|
|
|
Replies Item
|
|
|
|
StartTime time.Time
|
|
|
|
Summary NaturalLanguageValues
|
|
|
|
Tag ItemCollection
|
|
|
|
Updated time.Time
|
|
|
|
URL LinkOrIRI
|
|
|
|
To ItemCollection
|
|
|
|
Bto ItemCollection
|
|
|
|
CC ItemCollection
|
|
|
|
BCC ItemCollection
|
|
|
|
Duration time.Duration
|
|
|
|
Likes Item
|
|
|
|
Shares Item
|
|
|
|
Source Source
|
|
|
|
Actor Item
|
|
|
|
Target Item
|
|
|
|
Result Item
|
|
|
|
Origin Item
|
|
|
|
Instrument Item
|
|
|
|
Object Item
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want []byte
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Empty",
|
|
|
|
fields: fields{},
|
|
|
|
want: nil,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustID",
|
|
|
|
fields: fields{
|
|
|
|
ID: ID("example.com"),
|
|
|
|
},
|
|
|
|
want: []byte(`{"id":"example.com"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustType",
|
|
|
|
fields: fields{
|
|
|
|
Type: ActivityVocabularyType("myType"),
|
|
|
|
},
|
|
|
|
want: []byte(`{"type":"myType"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustOneName",
|
|
|
|
fields: fields{
|
|
|
|
Name: NaturalLanguageValues{
|
|
|
|
{Ref: NilLangRef, Value: "ana"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"name":"ana"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "MoreNames",
|
|
|
|
fields: fields{
|
|
|
|
Name: NaturalLanguageValues{
|
|
|
|
{Ref: "en", Value: "anna"},
|
|
|
|
{Ref: "fr", Value: "anne"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"nameMap":{"en":"anna","fr":"anne"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustOneSummary",
|
|
|
|
fields: fields{
|
|
|
|
Summary: NaturalLanguageValues{
|
|
|
|
{Ref: NilLangRef, Value: "test summary"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"summary":"test summary"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "MoreSummaryEntries",
|
|
|
|
fields: fields{
|
|
|
|
Summary: NaturalLanguageValues{
|
|
|
|
{Ref: "en", Value: "test summary"},
|
|
|
|
{Ref: "fr", Value: "teste summary"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"summaryMap":{"en":"test summary","fr":"teste summary"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustOneContent",
|
|
|
|
fields: fields{
|
|
|
|
Content: NaturalLanguageValues{
|
|
|
|
{Ref: NilLangRef, Value: "test content"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"content":"test content"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "MoreContentEntries",
|
|
|
|
fields: fields{
|
|
|
|
Content: NaturalLanguageValues{
|
|
|
|
{Ref: "en", Value: "test content"},
|
|
|
|
{Ref: "fr", Value: "teste content"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"contentMap":{"en":"test content","fr":"teste content"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "MediaType",
|
|
|
|
fields: fields{
|
|
|
|
MediaType: MimeType("text/stupid"),
|
|
|
|
},
|
|
|
|
want: []byte(`{"mediaType":"text/stupid"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Attachment",
|
|
|
|
fields: fields{
|
|
|
|
Attachment: &Object{
|
|
|
|
ID: "some example",
|
|
|
|
Type: VideoType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"attachment":{"id":"some example","type":"Video"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AttributedTo",
|
|
|
|
fields: fields{
|
|
|
|
AttributedTo: &Actor{
|
|
|
|
ID: "http://example.com/ana",
|
|
|
|
Type: PersonType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"attributedTo":{"id":"http://example.com/ana","type":"Person"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AttributedToDouble",
|
|
|
|
fields: fields{
|
|
|
|
AttributedTo: ItemCollection{
|
|
|
|
&Actor{
|
|
|
|
ID: "http://example.com/ana",
|
|
|
|
Type: PersonType,
|
|
|
|
},
|
|
|
|
&Actor{
|
|
|
|
ID: "http://example.com/GGG",
|
|
|
|
Type: GroupType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"attributedTo":[{"id":"http://example.com/ana","type":"Person"},{"id":"http://example.com/GGG","type":"Group"}]}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Source",
|
|
|
|
fields: fields{
|
|
|
|
Source: Source{
|
|
|
|
MediaType: MimeType("text/plain"),
|
|
|
|
Content: NaturalLanguageValues{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"source":{"mediaType":"text/plain"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
a := Activity{
|
|
|
|
ID: tt.fields.ID,
|
|
|
|
Type: tt.fields.Type,
|
|
|
|
Name: tt.fields.Name,
|
|
|
|
Attachment: tt.fields.Attachment,
|
|
|
|
AttributedTo: tt.fields.AttributedTo,
|
|
|
|
Audience: tt.fields.Audience,
|
|
|
|
Content: tt.fields.Content,
|
|
|
|
Context: tt.fields.Context,
|
|
|
|
MediaType: tt.fields.MediaType,
|
|
|
|
EndTime: tt.fields.EndTime,
|
|
|
|
Generator: tt.fields.Generator,
|
|
|
|
Icon: tt.fields.Icon,
|
|
|
|
Image: tt.fields.Image,
|
|
|
|
InReplyTo: tt.fields.InReplyTo,
|
|
|
|
Location: tt.fields.Location,
|
|
|
|
Preview: tt.fields.Preview,
|
|
|
|
Published: tt.fields.Published,
|
|
|
|
Replies: tt.fields.Replies,
|
|
|
|
StartTime: tt.fields.StartTime,
|
|
|
|
Summary: tt.fields.Summary,
|
|
|
|
Tag: tt.fields.Tag,
|
|
|
|
Updated: tt.fields.Updated,
|
|
|
|
URL: tt.fields.URL,
|
|
|
|
To: tt.fields.To,
|
|
|
|
Bto: tt.fields.Bto,
|
|
|
|
CC: tt.fields.CC,
|
|
|
|
BCC: tt.fields.BCC,
|
|
|
|
Duration: tt.fields.Duration,
|
|
|
|
Likes: tt.fields.Likes,
|
|
|
|
Shares: tt.fields.Shares,
|
|
|
|
Source: tt.fields.Source,
|
|
|
|
Actor: tt.fields.Actor,
|
|
|
|
Target: tt.fields.Target,
|
|
|
|
Result: tt.fields.Result,
|
|
|
|
Origin: tt.fields.Origin,
|
|
|
|
Instrument: tt.fields.Instrument,
|
|
|
|
Object: tt.fields.Object,
|
|
|
|
}
|
|
|
|
got, err := a.MarshalJSON()
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("MarshalJSON() got = %s, want %s", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIntransitiveActivity_MarshalJSON(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
ID ID
|
|
|
|
Type ActivityVocabularyType
|
|
|
|
Name NaturalLanguageValues
|
|
|
|
Attachment Item
|
|
|
|
AttributedTo Item
|
|
|
|
Audience ItemCollection
|
|
|
|
Content NaturalLanguageValues
|
|
|
|
Context Item
|
|
|
|
MediaType MimeType
|
|
|
|
EndTime time.Time
|
|
|
|
Generator Item
|
|
|
|
Icon Item
|
|
|
|
Image Item
|
|
|
|
InReplyTo Item
|
|
|
|
Location Item
|
|
|
|
Preview Item
|
|
|
|
Published time.Time
|
|
|
|
Replies Item
|
|
|
|
StartTime time.Time
|
|
|
|
Summary NaturalLanguageValues
|
|
|
|
Tag ItemCollection
|
|
|
|
Updated time.Time
|
|
|
|
URL LinkOrIRI
|
|
|
|
To ItemCollection
|
|
|
|
Bto ItemCollection
|
|
|
|
CC ItemCollection
|
|
|
|
BCC ItemCollection
|
|
|
|
Duration time.Duration
|
|
|
|
Likes Item
|
|
|
|
Shares Item
|
|
|
|
Source Source
|
|
|
|
Actor CanReceiveActivities
|
|
|
|
Target Item
|
|
|
|
Result Item
|
|
|
|
Origin Item
|
|
|
|
Instrument Item
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want []byte
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Empty",
|
|
|
|
fields: fields{},
|
|
|
|
want: nil,
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustID",
|
|
|
|
fields: fields{
|
|
|
|
ID: ID("example.com"),
|
|
|
|
},
|
|
|
|
want: []byte(`{"id":"example.com"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustType",
|
|
|
|
fields: fields{
|
|
|
|
Type: ActivityVocabularyType("myType"),
|
|
|
|
},
|
|
|
|
want: []byte(`{"type":"myType"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustOneName",
|
|
|
|
fields: fields{
|
|
|
|
Name: NaturalLanguageValues{
|
|
|
|
{Ref: NilLangRef, Value: "ana"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"name":"ana"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "MoreNames",
|
|
|
|
fields: fields{
|
|
|
|
Name: NaturalLanguageValues{
|
|
|
|
{Ref: "en", Value: "anna"},
|
|
|
|
{Ref: "fr", Value: "anne"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"nameMap":{"en":"anna","fr":"anne"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustOneSummary",
|
|
|
|
fields: fields{
|
|
|
|
Summary: NaturalLanguageValues{
|
|
|
|
{Ref: NilLangRef, Value: "test summary"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"summary":"test summary"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "MoreSummaryEntries",
|
|
|
|
fields: fields{
|
|
|
|
Summary: NaturalLanguageValues{
|
|
|
|
{Ref: "en", Value: "test summary"},
|
|
|
|
{Ref: "fr", Value: "teste summary"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"summaryMap":{"en":"test summary","fr":"teste summary"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "JustOneContent",
|
|
|
|
fields: fields{
|
|
|
|
Content: NaturalLanguageValues{
|
|
|
|
{Ref: NilLangRef, Value: "test content"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"content":"test content"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "MoreContentEntries",
|
|
|
|
fields: fields{
|
|
|
|
Content: NaturalLanguageValues{
|
|
|
|
{Ref: "en", Value: "test content"},
|
|
|
|
{Ref: "fr", Value: "teste content"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"contentMap":{"en":"test content","fr":"teste content"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "MediaType",
|
|
|
|
fields: fields{
|
|
|
|
MediaType: MimeType("text/stupid"),
|
|
|
|
},
|
|
|
|
want: []byte(`{"mediaType":"text/stupid"}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Attachment",
|
|
|
|
fields: fields{
|
|
|
|
Attachment: &Object{
|
|
|
|
ID: "some example",
|
|
|
|
Type: VideoType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"attachment":{"id":"some example","type":"Video"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AttributedTo",
|
|
|
|
fields: fields{
|
|
|
|
AttributedTo: &Actor{
|
|
|
|
ID: "http://example.com/ana",
|
|
|
|
Type: PersonType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"attributedTo":{"id":"http://example.com/ana","type":"Person"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AttributedToDouble",
|
|
|
|
fields: fields{
|
|
|
|
AttributedTo: ItemCollection{
|
|
|
|
&Actor{
|
|
|
|
ID: "http://example.com/ana",
|
|
|
|
Type: PersonType,
|
|
|
|
},
|
|
|
|
&Actor{
|
|
|
|
ID: "http://example.com/GGG",
|
|
|
|
Type: GroupType,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"attributedTo":[{"id":"http://example.com/ana","type":"Person"},{"id":"http://example.com/GGG","type":"Group"}]}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Source",
|
|
|
|
fields: fields{
|
|
|
|
Source: Source{
|
|
|
|
MediaType: MimeType("text/plain"),
|
|
|
|
Content: NaturalLanguageValues{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []byte(`{"source":{"mediaType":"text/plain"}}`),
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
i := IntransitiveActivity{
|
|
|
|
ID: tt.fields.ID,
|
|
|
|
Type: tt.fields.Type,
|
|
|
|
Name: tt.fields.Name,
|
|
|
|
Attachment: tt.fields.Attachment,
|
|
|
|
AttributedTo: tt.fields.AttributedTo,
|
|
|
|
Audience: tt.fields.Audience,
|
|
|
|
Content: tt.fields.Content,
|
|
|
|
Context: tt.fields.Context,
|
|
|
|
MediaType: tt.fields.MediaType,
|
|
|
|
EndTime: tt.fields.EndTime,
|
|
|
|
Generator: tt.fields.Generator,
|
|
|
|
Icon: tt.fields.Icon,
|
|
|
|
Image: tt.fields.Image,
|
|
|
|
InReplyTo: tt.fields.InReplyTo,
|
|
|
|
Location: tt.fields.Location,
|
|
|
|
Preview: tt.fields.Preview,
|
|
|
|
Published: tt.fields.Published,
|
|
|
|
Replies: tt.fields.Replies,
|
|
|
|
StartTime: tt.fields.StartTime,
|
|
|
|
Summary: tt.fields.Summary,
|
|
|
|
Tag: tt.fields.Tag,
|
|
|
|
Updated: tt.fields.Updated,
|
|
|
|
URL: tt.fields.URL,
|
|
|
|
To: tt.fields.To,
|
|
|
|
Bto: tt.fields.Bto,
|
|
|
|
CC: tt.fields.CC,
|
|
|
|
BCC: tt.fields.BCC,
|
|
|
|
Duration: tt.fields.Duration,
|
|
|
|
Likes: tt.fields.Likes,
|
|
|
|
Shares: tt.fields.Shares,
|
|
|
|
Source: tt.fields.Source,
|
|
|
|
Actor: tt.fields.Actor,
|
|
|
|
Target: tt.fields.Target,
|
|
|
|
Result: tt.fields.Result,
|
|
|
|
Origin: tt.fields.Origin,
|
|
|
|
Instrument: tt.fields.Instrument,
|
|
|
|
}
|
|
|
|
got, err := i.MarshalJSON()
|
|
|
|
if (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("MarshalJSON() got = %s, want %s", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-12-15 18:01:29 +00:00
|
|
|
}
|