Debian Codegraph @

activity_test.go

raw symbols SCIP
1 package activitypub
2
3 import (
4 "bytes"
5 "fmt"
6 "testing"
7 "time"
8
9 "github.com/google/go-cmp/cmp"
10 )
11
12 func TestActivityNew(t *testing.T) {
13 testValue := ID("test")
14 var testType ActivityVocabularyType = "Accept"
15
16 a := ActivityNew(testValue, testType, nil)
17 if a.ID != testValue {
18 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
19 }
20 if !a.Match(testType) {
21 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), testType)
22 }
23
24 g := ActivityNew(testValue, "", nil)
25
26 if g.ID != testValue {
27 t.Errorf("Activity Id '%v' different than expected '%v'", g.ID, testValue)
28 }
29 if !g.Match(ActivityType) {
30 t.Errorf("Activity Type '%v' different than expected '%v'", g.GetType(), ActivityType)
31 }
32 }
33
34 func TestAcceptNew(t *testing.T) {
35 testValue := ID("test")
36
37 a := AcceptNew(testValue, nil)
38
39 if a.ID != testValue {
40 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
41 }
42 if !a.Match(AcceptType) {
43 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), AcceptType)
44 }
45 }
46
47 func TestAddNew(t *testing.T) {
48 testValue := ID("test")
49
50 a := AddNew(testValue, nil, nil)
51
52 if a.ID != testValue {
53 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
54 }
55 if !a.Match(AddType) {
56 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), AddType)
57 }
58 }
59
60 func TestAnnounceNew(t *testing.T) {
61 testValue := ID("test")
62
63 a := AnnounceNew(testValue, nil)
64
65 if a.ID != testValue {
66 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
67 }
68 if !a.Match(AnnounceType) {
69 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), AnnounceType)
70 }
71 }
72
73 func TestBlockNew(t *testing.T) {
74 testValue := ID("test")
75
76 a := BlockNew(testValue, nil)
77
78 if a.ID != testValue {
79 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
80 }
81 if !a.Match(BlockType) {
82 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), BlockType)
83 }
84 }
85
86 func TestCreateNew(t *testing.T) {
87 testValue := ID("test")
88
89 a := CreateNew(testValue, nil)
90
91 if a.ID != testValue {
92 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
93 }
94 if !a.Match(CreateType) {
95 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), CreateType)
96 }
97 }
98
99 func TestDeleteNew(t *testing.T) {
100 testValue := ID("test")
101
102 a := DeleteNew(testValue, nil)
103
104 if a.ID != testValue {
105 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
106 }
107 if !a.Match(DeleteType) {
108 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), DeleteType)
109 }
110 }
111
112 func TestDislikeNew(t *testing.T) {
113 testValue := ID("test")
114
115 a := DislikeNew(testValue, nil)
116
117 if a.ID != testValue {
118 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
119 }
120 if !a.Match(DislikeType) {
121 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), DislikeType)
122 }
123 }
124
125 func TestFlagNew(t *testing.T) {
126 testValue := ID("test")
127
128 a := FlagNew(testValue, nil)
129
130 if a.ID != testValue {
131 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
132 }
133 if !a.Match(FlagType) {
134 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), FlagType)
135 }
136 }
137
138 func TestFollowNew(t *testing.T) {
139 testValue := ID("test")
140
141 a := FollowNew(testValue, nil)
142
143 if a.ID != testValue {
144 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
145 }
146 if !a.Match(FollowType) {
147 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), FollowType)
148 }
149 }
150
151 func TestIgnoreNew(t *testing.T) {
152 testValue := ID("test")
153
154 a := IgnoreNew(testValue, nil)
155
156 if a.ID != testValue {
157 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
158 }
159 if !a.Match(IgnoreType) {
160 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), IgnoreType)
161 }
162 }
163
164 func TestInviteNew(t *testing.T) {
165 testValue := ID("test")
166
167 a := InviteNew(testValue, nil)
168
169 if a.ID != testValue {
170 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
171 }
172 if !a.Match(InviteType) {
173 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), InviteType)
174 }
175 }
176
177 func TestJoinNew(t *testing.T) {
178 testValue := ID("test")
179
180 a := JoinNew(testValue, nil)
181
182 if a.ID != testValue {
183 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
184 }
185 if !a.Match(JoinType) {
186 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), JoinType)
187 }
188 }
189
190 func TestLeaveNew(t *testing.T) {
191 testValue := ID("test")
192
193 a := LeaveNew(testValue, nil)
194
195 if a.ID != testValue {
196 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
197 }
198 if !a.Match(LeaveType) {
199 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), LeaveType)
200 }
201 }
202
203 func TestLikeNew(t *testing.T) {
204 testValue := ID("test")
205
206 a := LikeNew(testValue, nil)
207
208 if a.ID != testValue {
209 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
210 }
211 if !a.Match(LikeType) {
212 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), LikeType)
213 }
214 }
215
216 func TestListenNew(t *testing.T) {
217 testValue := ID("test")
218
219 a := ListenNew(testValue, nil)
220
221 if a.ID != testValue {
222 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
223 }
224 if !a.Match(ListenType) {
225 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), ListenType)
226 }
227 }
228
229 func TestMoveNew(t *testing.T) {
230 testValue := ID("test")
231
232 a := MoveNew(testValue, nil)
233
234 if a.ID != testValue {
235 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
236 }
237 if !a.Match(MoveType) {
238 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), MoveType)
239 }
240 }
241
242 func TestOfferNew(t *testing.T) {
243 testValue := ID("test")
244
245 a := OfferNew(testValue, nil)
246
247 if a.ID != testValue {
248 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
249 }
250 if !a.Match(OfferType) {
251 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), OfferType)
252 }
253 }
254
255 func TestRejectNew(t *testing.T) {
256 testValue := ID("test")
257
258 a := RejectNew(testValue, nil)
259
260 if a.ID != testValue {
261 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
262 }
263 if !a.Match(RejectType) {
264 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), RejectType)
265 }
266 }
267
268 func TestReadNew(t *testing.T) {
269 testValue := ID("test")
270
271 a := ReadNew(testValue, nil)
272
273 if a.ID != testValue {
274 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
275 }
276 if !a.Match(ReadType) {
277 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), ReadType)
278 }
279 }
280
281 func TestRemoveNew(t *testing.T) {
282 testValue := ID("test")
283
284 a := RemoveNew(testValue, nil, nil)
285
286 if a.ID != testValue {
287 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
288 }
289 if !a.Match(RemoveType) {
290 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), RemoveType)
291 }
292 }
293
294 func TestTentativeRejectNew(t *testing.T) {
295 testValue := ID("test")
296
297 a := TentativeRejectNew(testValue, nil)
298
299 if a.ID != testValue {
300 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
301 }
302 if !a.Match(TentativeRejectType) {
303 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), TentativeRejectType)
304 }
305 }
306
307 func TestTentativeAcceptNew(t *testing.T) {
308 testValue := ID("test")
309
310 a := TentativeAcceptNew(testValue, nil)
311
312 if a.ID != testValue {
313 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
314 }
315 if !a.Match(TentativeAcceptType) {
316 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), TentativeAcceptType)
317 }
318 }
319
320 func TestUndoNew(t *testing.T) {
321 testValue := ID("test")
322
323 a := UndoNew(testValue, nil)
324
325 if a.ID != testValue {
326 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
327 }
328 if !a.Match(UndoType) {
329 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), UndoType)
330 }
331 }
332
333 func TestUpdateNew(t *testing.T) {
334 testValue := ID("test")
335
336 a := UpdateNew(testValue, nil)
337
338 if a.ID != testValue {
339 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
340 }
341 if !a.Match(UpdateType) {
342 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), UpdateType)
343 }
344 }
345
346 func TestViewNew(t *testing.T) {
347 testValue := ID("test")
348
349 a := ViewNew(testValue, nil)
350
351 if a.ID != testValue {
352 t.Errorf("Activity Id '%v' different than expected '%v'", a.ID, testValue)
353 }
354 if !a.Match(ViewType) {
355 t.Errorf("Activity Type '%v' different than expected '%v'", a.GetType(), ViewType)
356 }
357 }
358
359 func TestActivityRecipients(t *testing.T) {
360 bob := PersonNew("bob")
361 alice := PersonNew("alice")
362 foo := OrganizationNew("foo")
363 bar := GroupNew("bar")
364
365 a := ActivityNew("t", "test", nil)
366
367 _ = a.To.Append(bob)
368 _ = a.To.Append(alice)
369 _ = a.To.Append(foo)
370 _ = a.To.Append(bar)
371 if len(a.To) != 4 {
372 t.Errorf("%T.To should have exactly 4(four) elements, not %d", a, len(a.To))
373 }
374
375 _ = a.To.Append(bar)
376 _ = a.To.Append(alice)
377 _ = a.To.Append(foo)
378 _ = a.To.Append(bob)
379 if len(a.To) != 4 {
380 t.Errorf("%T.To should still have exactly 4(eight) elements, not %d", a, len(a.To))
381 }
382
383 a.Recipients()
384 if len(a.To) != 4 {
385 t.Errorf("%T.To should have exactly 4(four) elements, not %d", a, len(a.To))
386 }
387
388 b := ActivityNew("t", "test", nil)
389
390 _ = b.To.Append(bar)
391 _ = b.To.Append(alice)
392 _ = b.To.Append(foo)
393 _ = b.To.Append(bob)
394 _ = b.Bto.Append(bar)
395 _ = b.Bto.Append(alice)
396 _ = b.Bto.Append(foo)
397 _ = b.Bto.Append(bob)
398 _ = b.CC.Append(bar)
399 _ = b.CC.Append(alice)
400 _ = b.CC.Append(foo)
401 _ = b.CC.Append(bob)
402 _ = b.BCC.Append(bar)
403 _ = b.BCC.Append(alice)
404 _ = b.BCC.Append(foo)
405 _ = b.BCC.Append(bob)
406
407 b.Recipients()
408 if len(b.To) != 4 {
409 t.Errorf("%T.To should have exactly 4(four) elements, not %d", b, len(b.To))
410 }
411 if len(b.Bto) != 0 {
412 t.Errorf("%T.Bto should have exactly 0(zero) elements, not %d", b, len(b.Bto))
413 }
414 if len(b.CC) != 0 {
415 t.Errorf("%T.CC should have exactly 0(zero) elements, not %d", b, len(b.CC))
416 }
417 if len(b.BCC) != 0 {
418 t.Errorf("%T.BCC should have exactly 0(zero) elements, not %d", b, len(b.BCC))
419 }
420 }
421
422 func TestBlockRecipients(t *testing.T) {
423 bob := PersonNew("bob")
424 alice := PersonNew("alice")
425 foo := OrganizationNew("foo")
426 bar := GroupNew("bar")
427
428 a := BlockNew("bbb", bob)
429
430 _ = a.To.Append(bob)
431 _ = a.To.Append(alice)
432 _ = a.To.Append(foo)
433 _ = a.To.Append(bar)
434 if len(a.To) != 4 {
435 t.Errorf("%T.To should have exactly 4(four) elements, not %d", a, len(a.To))
436 }
437
438 _ = a.To.Append(bar)
439 _ = a.To.Append(alice)
440 _ = a.To.Append(foo)
441 _ = a.To.Append(bob)
442 if len(a.To) != 4 {
443 t.Errorf("%T.To should still have exactly 4(eight) elements, not %d", a, len(a.To))
444 }
445
446 a.Recipients()
447 if len(a.To) != 3 {
448 t.Errorf("%T.To should have exactly 3(three) elements, not %d", a, len(a.To))
449 }
450
451 b := BlockNew("t", bob)
452
453 _ = b.To.Append(bar)
454 _ = b.To.Append(alice)
455 _ = b.To.Append(foo)
456 _ = b.To.Append(bob)
457 _ = b.Bto.Append(bar)
458 _ = b.Bto.Append(alice)
459 _ = b.Bto.Append(foo)
460 _ = b.Bto.Append(bob)
461 _ = b.CC.Append(bar)
462 _ = b.CC.Append(alice)
463 _ = b.CC.Append(foo)
464 _ = b.CC.Append(bob)
465 _ = b.BCC.Append(bar)
466 _ = b.BCC.Append(alice)
467 _ = b.BCC.Append(foo)
468 _ = b.BCC.Append(bob)
469
470 b.Recipients()
471 if len(b.To) != 3 {
472 t.Errorf("%T.To should have exactly 3(three) elements, not %d", b, len(b.To))
473 }
474 if len(b.Bto) != 0 {
475 t.Errorf("%T.Bto should have exactly 0(zero) elements, not %d", b, len(b.Bto))
476 }
477 if len(b.CC) != 0 {
478 t.Errorf("%T.CC should have exactly 0(zero) elements, not %d", b, len(b.CC))
479 }
480 if len(b.BCC) != 0 {
481 t.Errorf("%T.BCC should have exactly 0(zero) elements, not %d", b, len(b.BCC))
482 }
483 var err error
484 recIds := make([]ID, 0)
485 err = checkDedup(b.To, &recIds)
486 if err != nil {
487 t.Error(err)
488 }
489 err = checkDedup(b.Bto, &recIds)
490 if err != nil {
491 t.Error(err)
492 }
493 err = checkDedup(b.CC, &recIds)
494 if err != nil {
495 t.Error(err)
496 }
497 err = checkDedup(b.BCC, &recIds)
498 if err != nil {
499 t.Error(err)
500 }
501 }
502
503 func TestCreate_Recipients(t *testing.T) {
504 to := PersonNew("bob")
505 o := ObjectNew(ArticleType)
506 cc := PersonNew("alice")
507
508 o.ID = "something"
509
510 c := CreateNew("act", o)
511 _ = c.To.Append(to)
512 _ = c.CC.Append(cc)
513 _ = c.BCC.Append(cc)
514
515 c.Recipients()
516
517 var err error
518 recIds := make([]ID, 0)
519 err = checkDedup(c.To, &recIds)
520 if err != nil {
521 t.Error(err)
522 }
523 err = checkDedup(c.Bto, &recIds)
524 if err != nil {
525 t.Error(err)
526 }
527 err = checkDedup(c.CC, &recIds)
528 if err != nil {
529 t.Error(err)
530 }
531 err = checkDedup(c.BCC, &recIds)
532 if err != nil {
533 t.Error(err)
534 }
535 }
536
537 func TestDislike_Recipients(t *testing.T) {
538 to := PersonNew("bob")
539 o := ObjectNew(ArticleType)
540 cc := PersonNew("alice")
541
542 o.ID = "something"
543
544 d := DislikeNew("act", o)
545 _ = d.To.Append(to)
546 _ = d.CC.Append(cc)
547 _ = d.BCC.Append(cc)
548
549 d.Recipients()
550
551 var err error
552 recIds := make([]ID, 0)
553 err = checkDedup(d.To, &recIds)
554 if err != nil {
555 t.Error(err)
556 }
557 err = checkDedup(d.Bto, &recIds)
558 if err != nil {
559 t.Error(err)
560 }
561 err = checkDedup(d.CC, &recIds)
562 if err != nil {
563 t.Error(err)
564 }
565 err = checkDedup(d.BCC, &recIds)
566 if err != nil {
567 t.Error(err)
568 }
569 }
570
571 func TestLike_Recipients(t *testing.T) {
572 to := PersonNew("bob")
573 o := ObjectNew(ArticleType)
574 cc := PersonNew("alice")
575
576 o.ID = "something"
577
578 l := LikeNew("act", o)
579 _ = l.To.Append(to)
580 _ = l.CC.Append(cc)
581 _ = l.BCC.Append(cc)
582
583 l.Recipients()
584
585 var err error
586 recIds := make([]ID, 0)
587 err = checkDedup(l.To, &recIds)
588 if err != nil {
589 t.Error(err)
590 }
591 err = checkDedup(l.Bto, &recIds)
592 if err != nil {
593 t.Error(err)
594 }
595 err = checkDedup(l.CC, &recIds)
596 if err != nil {
597 t.Error(err)
598 }
599 err = checkDedup(l.BCC, &recIds)
600 if err != nil {
601 t.Error(err)
602 }
603 }
604
605 func TestUpdate_Recipients(t *testing.T) {
606 to := PersonNew("bob")
607 o := ObjectNew(ArticleType)
608 cc := PersonNew("alice")
609
610 o.ID = "something"
611
612 u := UpdateNew("act", o)
613 _ = u.To.Append(to)
614 _ = u.CC.Append(cc)
615 _ = u.BCC.Append(cc)
616
617 u.Recipients()
618
619 var err error
620 recIds := make([]ID, 0)
621 err = checkDedup(u.To, &recIds)
622 if err != nil {
623 t.Error(err)
624 }
625 err = checkDedup(u.Bto, &recIds)
626 if err != nil {
627 t.Error(err)
628 }
629 err = checkDedup(u.CC, &recIds)
630 if err != nil {
631 t.Error(err)
632 }
633 err = checkDedup(u.BCC, &recIds)
634 if err != nil {
635 t.Error(err)
636 }
637 }
638
639 func TestActivity_GetID(t *testing.T) {
640 a := ActivityNew("test", ActivityType, Person{})
641
642 if a.GetID() != "test" {
643 t.Errorf("%T should return an empty %T object. Received %#v", a, a.GetID(), a.GetID())
644 }
645 }
646
647 func TestActivity_GetIDGetType(t *testing.T) {
648 a := ActivityNew("test", ActivityType, Person{})
649
650 if a.GetID() != "test" || !a.Match(ActivityType) {
651 t.Errorf("%T should not return an empty %T object. Received %#v", a, a.GetID(), a.GetID())
652 }
653 }
654
655 func TestActivity_IsLink(t *testing.T) {
656 a := ActivityNew("test", ActivityType, Person{})
657
658 if a.IsLink() {
659 t.Errorf("%T should not respond true to IsLink", a)
660 }
661 }
662
663 func TestActivity_IsObject(t *testing.T) {
664 a := ActivityNew("test", ActivityType, Person{})
665
666 if !a.IsObject() {
667 t.Errorf("%T should respond true to IsObject", a)
668 }
669 }
670
671 func checkDedup(list ItemCollection, recIds *[]ID) error {
672 for _, rec := range list {
673 for _, id := range *recIds {
674 if rec.GetID() == id {
675 return fmt.Errorf("%T[%s] already stored in recipients list, Deduplication faild", rec, id)
676 }
677 }
678 *recIds = append(*recIds, rec.GetID())
679 }
680 return nil
681 }
682
683 func TestActivity_Recipients(t *testing.T) {
684 to := PersonNew("bob")
685 o := ObjectNew(ArticleType)
686 cc := PersonNew("alice")
687
688 o.ID = "something"
689
690 c := ActivityNew("act", ActivityType, o)
691 _ = c.To.Append(to)
692 _ = c.CC.Append(cc)
693 _ = c.BCC.Append(cc)
694
695 c.Recipients()
696
697 var err error
698 recIds := make([]ID, 0)
699 err = checkDedup(c.To, &recIds)
700 if err != nil {
701 t.Error(err)
702 }
703 err = checkDedup(c.Bto, &recIds)
704 if err != nil {
705 t.Error(err)
706 }
707 err = checkDedup(c.CC, &recIds)
708 if err != nil {
709 t.Error(err)
710 }
711 err = checkDedup(c.BCC, &recIds)
712 if err != nil {
713 t.Error(err)
714 }
715 }
716
717 func TestBlock_Recipients(t *testing.T) {
718 to := PersonNew("bob")
719 o := ObjectNew(ArticleType)
720 cc := PersonNew("alice")
721
722 o.ID = "something"
723
724 b := BlockNew("act", o)
725 _ = b.To.Append(to)
726 _ = b.CC.Append(cc)
727 _ = b.BCC.Append(cc)
728
729 b.Recipients()
730
731 var err error
732 recIds := make([]ID, 0)
733 err = checkDedup(b.To, &recIds)
734 if err != nil {
735 t.Error(err)
736 }
737 err = checkDedup(b.Bto, &recIds)
738 if err != nil {
739 t.Error(err)
740 }
741 err = checkDedup(b.CC, &recIds)
742 if err != nil {
743 t.Error(err)
744 }
745 err = checkDedup(b.BCC, &recIds)
746 if err != nil {
747 t.Error(err)
748 }
749 }
750
751 func TestActivity_UnmarshalJSON(t *testing.T) {
752 a := Activity{}
753
754 dataEmpty := []byte("{}")
755 _ = a.UnmarshalJSON(dataEmpty)
756 if a.ID != "" {
757 t.Errorf("Unmarshaled object %T should have empty ID, received %q", a, a.ID)
758 }
759 if HasTypes(a) {
760 t.Errorf("Unmarshaled object %T should have empty Type, received %q", a, a.GetType())
761 }
762 if a.AttributedTo != nil {
763 t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", a, a.AttributedTo)
764 }
765 if len(a.Name) != 0 {
766 t.Errorf("Unmarshaled object %T should have empty Name, received %q", a, a.Name)
767 }
768 if len(a.Summary) != 0 {
769 t.Errorf("Unmarshaled object %T should have empty Summary, received %q", a, a.Summary)
770 }
771 if len(a.Content) != 0 {
772 t.Errorf("Unmarshaled object %T should have empty Content, received %q", a, a.Content)
773 }
774 if a.URL != nil {
775 t.Errorf("Unmarshaled object %T should have empty URL, received %v", a, a.URL)
776 }
777 if !a.Published.IsZero() {
778 t.Errorf("Unmarshaled object %T should have empty Published, received %q", a, a.Published)
779 }
780 if !a.StartTime.IsZero() {
781 t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", a, a.StartTime)
782 }
783 if !a.Updated.IsZero() {
784 t.Errorf("Unmarshaled object %T should have empty Updated, received %q", a, a.Updated)
785 }
786 }
787
788 func TestCreate_UnmarshalJSON(t *testing.T) {
789 c := Create{}
790
791 dataEmpty := []byte("{}")
792 _ = c.UnmarshalJSON(dataEmpty)
793 if c.ID != "" {
794 t.Errorf("Unmarshaled object %T should have empty ID, received %q", c, c.ID)
795 }
796 if HasTypes(c) {
797 t.Errorf("Unmarshaled object %T should have empty Type, received %q", c, c.GetType())
798 }
799 if c.AttributedTo != nil {
800 t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", c, c.AttributedTo)
801 }
802 if len(c.Name) != 0 {
803 t.Errorf("Unmarshaled object %T should have empty Name, received %q", c, c.Name)
804 }
805 if len(c.Summary) != 0 {
806 t.Errorf("Unmarshaled object %T should have empty Summary, received %q", c, c.Summary)
807 }
808 if len(c.Content) != 0 {
809 t.Errorf("Unmarshaled object %T should have empty Content, received %q", c, c.Content)
810 }
811 if c.URL != nil {
812 t.Errorf("Unmarshaled object %T should have empty URL, received %v", c, c.URL)
813 }
814 if !c.Published.IsZero() {
815 t.Errorf("Unmarshaled object %T should have empty Published, received %q", c, c.Published)
816 }
817 if !c.StartTime.IsZero() {
818 t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", c, c.StartTime)
819 }
820 if !c.Updated.IsZero() {
821 t.Errorf("Unmarshaled object %T should have empty Updated, received %q", c, c.Updated)
822 }
823 }
824
825 func TestDislike_UnmarshalJSON(t *testing.T) {
826 d := Dislike{}
827
828 dataEmpty := []byte("{}")
829 _ = d.UnmarshalJSON(dataEmpty)
830 if d.ID != "" {
831 t.Errorf("Unmarshaled object %T should have empty ID, received %q", d, d.ID)
832 }
833 if HasTypes(d) {
834 t.Errorf("Unmarshaled object %T should have empty Type, received %q", d, d.GetType())
835 }
836 if d.AttributedTo != nil {
837 t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", d, d.AttributedTo)
838 }
839 if len(d.Name) != 0 {
840 t.Errorf("Unmarshaled object %T should have empty Name, received %q", d, d.Name)
841 }
842 if len(d.Summary) != 0 {
843 t.Errorf("Unmarshaled object %T should have empty Summary, received %q", d, d.Summary)
844 }
845 if len(d.Content) != 0 {
846 t.Errorf("Unmarshaled object %T should have empty Content, received %q", d, d.Content)
847 }
848 if d.URL != nil {
849 t.Errorf("Unmarshaled object %T should have empty URL, received %v", d, d.URL)
850 }
851 if !d.Published.IsZero() {
852 t.Errorf("Unmarshaled object %T should have empty Published, received %q", d, d.Published)
853 }
854 if !d.StartTime.IsZero() {
855 t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", d, d.StartTime)
856 }
857 if !d.Updated.IsZero() {
858 t.Errorf("Unmarshaled object %T should have empty Updated, received %q", d, d.Updated)
859 }
860 }
861
862 func TestLike_UnmarshalJSON(t *testing.T) {
863 l := Like{}
864
865 dataEmpty := []byte("{}")
866 l.UnmarshalJSON(dataEmpty)
867 if l.ID != "" {
868 t.Errorf("Unmarshaled object %T should have empty ID, received %q", l, l.ID)
869 }
870 if HasTypes(l) {
871 t.Errorf("Unmarshaled object %T should have empty Type, received %q", l, l.GetType())
872 }
873 if l.AttributedTo != nil {
874 t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", l, l.AttributedTo)
875 }
876 if len(l.Name) != 0 {
877 t.Errorf("Unmarshaled object %T should have empty Name, received %q", l, l.Name)
878 }
879 if len(l.Summary) != 0 {
880 t.Errorf("Unmarshaled object %T should have empty Summary, received %q", l, l.Summary)
881 }
882 if len(l.Content) != 0 {
883 t.Errorf("Unmarshaled object %T should have empty Content, received %q", l, l.Content)
884 }
885 if l.URL != nil {
886 t.Errorf("Unmarshaled object %T should have empty URL, received %v", l, l.URL)
887 }
888 if !l.Published.IsZero() {
889 t.Errorf("Unmarshaled object %T should have empty Published, received %q", l, l.Published)
890 }
891 if !l.StartTime.IsZero() {
892 t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", l, l.StartTime)
893 }
894 if !l.Updated.IsZero() {
895 t.Errorf("Unmarshaled object %T should have empty Updated, received %q", l, l.Updated)
896 }
897 }
898
899 func TestUpdate_UnmarshalJSON(t *testing.T) {
900 u := Update{}
901
902 dataEmpty := []byte("{}")
903 u.UnmarshalJSON(dataEmpty)
904 if u.ID != "" {
905 t.Errorf("Unmarshaled object %T should have empty ID, received %q", u, u.ID)
906 }
907 if HasTypes(u) {
908 t.Errorf("Unmarshaled object %T should have empty Type, received %q", u, u.GetType())
909 }
910 if u.AttributedTo != nil {
911 t.Errorf("Unmarshaled object %T should have empty AttributedTo, received %q", u, u.AttributedTo)
912 }
913 if len(u.Name) != 0 {
914 t.Errorf("Unmarshaled object %T should have empty Name, received %q", u, u.Name)
915 }
916 if len(u.Summary) != 0 {
917 t.Errorf("Unmarshaled object %T should have empty Summary, received %q", u, u.Summary)
918 }
919 if len(u.Content) != 0 {
920 t.Errorf("Unmarshaled object %T should have empty Content, received %q", u, u.Content)
921 }
922 if u.URL != nil {
923 t.Errorf("Unmarshaled object %T should have empty URL, received %v", u, u.URL)
924 }
925 if !u.Published.IsZero() {
926 t.Errorf("Unmarshaled object %T should have empty Published, received %q", u, u.Published)
927 }
928 if !u.StartTime.IsZero() {
929 t.Errorf("Unmarshaled object %T should have empty StartTime, received %q", u, u.StartTime)
930 }
931 if !u.Updated.IsZero() {
932 t.Errorf("Unmarshaled object %T should have empty Updated, received %q", u, u.Updated)
933 }
934 }
935
936 func TestToActivity(t *testing.T) {
937 tests := []struct {
938 name string
939 it LinkOrIRI
940 want *Activity
941 wantErr error
942 }{
943 {
944 name: "empty",
945 },
946 {
947 name: "Valid Activity",
948 it: Activity{ID: "test", Type: UpdateType},
949 want: &Activity{ID: "test", Type: UpdateType},
950 },
951 {
952 name: "Valid *Activity",
953 it: &Activity{ID: "test", Type: CreateType},
954 want: &Activity{ID: "test", Type: CreateType},
955 },
956 {
957 name: "IRI",
958 it: IRI("https://example.com"),
959 wantErr: ErrorInvalidType[Activity](IRI("")),
960 },
961 {
962 name: "IRIs",
963 it: IRIs{IRI("https://example.com")},
964 wantErr: ErrorInvalidType[Activity](IRIs{}),
965 },
966 {
967 name: "ItemCollection",
968 it: ItemCollection{},
969 wantErr: ErrorInvalidType[Activity](ItemCollection{}),
970 },
971 {
972 name: "IntransitiveActivity",
973 it: &IntransitiveActivity{ID: "test", Type: ArriveType},
974 wantErr: ErrorInvalidType[Activity](&IntransitiveActivity{}),
975 },
976 {
977 name: "Object",
978 it: &Object{ID: "test", Type: ArticleType},
979 wantErr: ErrorInvalidType[Activity](&Object{}),
980 },
981 {
982 name: "Actor",
983 it: &Actor{ID: "test", Type: PersonType},
984 wantErr: ErrorInvalidType[Activity](&Person{}),
985 },
986 }
987 for _, tt := range tests {
988 t.Run(tt.name, func(t *testing.T) {
989 got, err := ToActivity(tt.it)
990 if !cmp.Equal(err, tt.wantErr, EquateWeakErrors) {
991 t.Errorf("ToActivity() error = %v, wantErr %v", err, tt.wantErr)
992 return
993 }
994 if !cmp.Equal(got, tt.want) {
995 t.Errorf("ToActivity() got = %s", cmp.Diff(tt.want, got))
996 }
997 })
998 }
999 }
1000
1001 func TestValidEventRSVPActivityType(t *testing.T) {
1002 t.Skipf("TODO")
1003 }
1004
1005 func TestValidGroupManagementActivityType(t *testing.T) {
1006 t.Skipf("TODO")
1007 }
1008
1009 func TestActivity_Clean(t *testing.T) {
1010 t.Skipf("TODO")
1011 }
1012
1013 func TestActivity_IsCollection(t *testing.T) {
1014 t.Skipf("TODO")
1015 }
1016
1017 func TestActivity_GetLink(t *testing.T) {
1018 t.Skipf("TODO")
1019 }
1020
1021 func TestActivity_GetType(t *testing.T) {
1022 t.Skipf("TODO")
1023 }
1024
1025 func TestActivity_MarshalJSON(t *testing.T) {
1026 type fields struct {
1027 ID ID
1028 Type Typer
1029 Name NaturalLanguageValues
1030 Attachment Item
1031 AttributedTo Item
1032 Audience ItemCollection
1033 Content NaturalLanguageValues
1034 Context Item
1035 MediaType MimeType
1036 EndTime time.Time
1037 Generator Item
1038 Icon Item
1039 Image Item
1040 InReplyTo Item
1041 Location Item
1042 Preview Item
1043 Published time.Time
1044 Replies Item
1045 StartTime time.Time
1046 Summary NaturalLanguageValues
1047 Tag ItemCollection
1048 Updated time.Time
1049 URL Item
1050 To ItemCollection
1051 Bto ItemCollection
1052 CC ItemCollection
1053 BCC ItemCollection
1054 Duration time.Duration
1055 Likes Item
1056 Shares Item
1057 Source Source
1058 Actor Item
1059 Target Item
1060 Result Item
1061 Origin Item
1062 Instrument Item
1063 Object Item
1064 }
1065 tests := []struct {
1066 name string
1067 fields fields
1068 want [][]byte
1069 wantErr bool
1070 }{
1071 {
1072 name: "Empty",
1073 fields: fields{},
1074 want: nil,
1075 wantErr: false,
1076 },
1077 {
1078 name: "JustID",
1079 fields: fields{
1080 ID: ID("example.com"),
1081 },
1082 want: [][]byte{[]byte(`{"id":"example.com"}`)},
1083 wantErr: false,
1084 },
1085 {
1086 name: "JustType",
1087 fields: fields{
1088 Type: ActivityVocabularyType("myType"),
1089 },
1090 want: [][]byte{[]byte(`{"type":"myType"}`)},
1091 wantErr: false,
1092 },
1093 {
1094 name: "JustOneName",
1095 fields: fields{
1096 Name: NaturalLanguageValues{
1097 NilLangRef: Content("ana"),
1098 },
1099 },
1100 want: [][]byte{[]byte(`{"name":"ana"}`)},
1101 wantErr: false,
1102 },
1103 {
1104 name: "MoreNames",
1105 fields: fields{
1106 Name: NaturalLanguageValues{
1107 English: Content("anna"),
1108 French: Content("anne"),
1109 },
1110 },
1111 want: [][]byte{
1112 []byte(`{"nameMap":{"en":"anna","fr":"anne"}}`),
1113 []byte(`{"nameMap":{"fr":"anne","en":"anna"}}`),
1114 },
1115 wantErr: false,
1116 },
1117 {
1118 name: "JustOneSummary",
1119 fields: fields{
1120 Summary: NaturalLanguageValues{
1121 NilLangRef: Content("test summary"),
1122 },
1123 },
1124 want: [][]byte{[]byte(`{"summary":"test summary"}`)},
1125 wantErr: false,
1126 },
1127 {
1128 name: "MoreSummaryEntries",
1129 fields: fields{
1130 Summary: NaturalLanguageValues{
1131 English: Content("test summary"),
1132 French: Content("teste summary"),
1133 },
1134 },
1135 want: [][]byte{
1136 []byte(`{"summaryMap":{"en":"test summary","fr":"teste summary"}}`),
1137 []byte(`{"summaryMap":{"fr":"teste summary","en":"test summary"}}`),
1138 },
1139 wantErr: false,
1140 },
1141 {
1142 name: "JustOneContent",
1143 fields: fields{
1144 Content: NaturalLanguageValues{
1145 NilLangRef: Content("test content"),
1146 },
1147 },
1148 want: [][]byte{[]byte(`{"content":"test content"}`)},
1149 wantErr: false,
1150 },
1151 {
1152 name: "MoreContentEntries",
1153 fields: fields{
1154 Content: NaturalLanguageValues{
1155 English: Content("test content"),
1156 French: Content("teste content"),
1157 },
1158 },
1159 want: [][]byte{
1160 []byte(`{"contentMap":{"en":"test content","fr":"teste content"}}`),
1161 []byte(`{"contentMap":{"fr":"teste content","en":"test content"}}`),
1162 },
1163 wantErr: false,
1164 },
1165 {
1166 name: "MediaType",
1167 fields: fields{
1168 MediaType: MimeType("text/stupid"),
1169 },
1170 want: [][]byte{[]byte(`{"mediaType":"text/stupid"}`)},
1171 wantErr: false,
1172 },
1173 {
1174 name: "Attachment",
1175 fields: fields{
1176 Attachment: &Object{
1177 ID: "some example",
1178 Type: VideoType,
1179 },
1180 },
1181 want: [][]byte{[]byte(`{"attachment":{"id":"some example","type":"Video"}}`)},
1182 wantErr: false,
1183 },
1184 {
1185 name: "AttributedTo",
1186 fields: fields{
1187 AttributedTo: &Actor{
1188 ID: "http://example.com/ana",
1189 Type: PersonType,
1190 },
1191 },
1192 want: [][]byte{[]byte(`{"attributedTo":{"id":"http://example.com/ana","type":"Person"}}`)},
1193 wantErr: false,
1194 },
1195 {
1196 name: "AttributedToDouble",
1197 fields: fields{
1198 AttributedTo: ItemCollection{
1199 &Actor{
1200 ID: "http://example.com/ana",
1201 Type: PersonType,
1202 },
1203 &Actor{
1204 ID: "http://example.com/GGG",
1205 Type: GroupType,
1206 },
1207 },
1208 },
1209 want: [][]byte{[]byte(`{"attributedTo":[{"id":"http://example.com/ana","type":"Person"},{"id":"http://example.com/GGG","type":"Group"}]}`)},
1210 wantErr: false,
1211 },
1212 {
1213 name: "Source",
1214 fields: fields{
1215 Source: Source{
1216 MediaType: MimeType("text/plain"),
1217 Content: NaturalLanguageValues{},
1218 },
1219 },
1220 want: [][]byte{[]byte(`{"source":{"mediaType":"text/plain"}}`)},
1221 wantErr: false,
1222 },
1223 }
1224 for _, tt := range tests {
1225 t.Run(tt.name, func(t *testing.T) {
1226 a := Activity{
1227 ID: tt.fields.ID,
1228 Type: tt.fields.Type,
1229 Name: tt.fields.Name,
1230 Attachment: tt.fields.Attachment,
1231 AttributedTo: tt.fields.AttributedTo,
1232 Audience: tt.fields.Audience,
1233 Content: tt.fields.Content,
1234 Context: tt.fields.Context,
1235 MediaType: tt.fields.MediaType,
1236 EndTime: tt.fields.EndTime,
1237 Generator: tt.fields.Generator,
1238 Icon: tt.fields.Icon,
1239 Image: tt.fields.Image,
1240 InReplyTo: tt.fields.InReplyTo,
1241 Location: tt.fields.Location,
1242 Preview: tt.fields.Preview,
1243 Published: tt.fields.Published,
1244 Replies: tt.fields.Replies,
1245 StartTime: tt.fields.StartTime,
1246 Summary: tt.fields.Summary,
1247 Tag: tt.fields.Tag,
1248 Updated: tt.fields.Updated,
1249 URL: tt.fields.URL,
1250 To: tt.fields.To,
1251 Bto: tt.fields.Bto,
1252 CC: tt.fields.CC,
1253 BCC: tt.fields.BCC,
1254 Duration: tt.fields.Duration,
1255 Likes: tt.fields.Likes,
1256 Shares: tt.fields.Shares,
1257 Source: tt.fields.Source,
1258 Actor: tt.fields.Actor,
1259 Target: tt.fields.Target,
1260 Result: tt.fields.Result,
1261 Origin: tt.fields.Origin,
1262 Instrument: tt.fields.Instrument,
1263 Object: tt.fields.Object,
1264 }
1265 got, err := a.MarshalJSON()
1266 if (err != nil) != tt.wantErr {
1267 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
1268 return
1269 }
1270 found := got == nil
1271 for _, wantBytes := range tt.want {
1272 if bytes.Equal(got, wantBytes) {
1273 found = true
1274 }
1275 }
1276 if !found {
1277 t.Errorf("MarshalJSON() got = %s, want %s", got, tt.want)
1278 }
1279 })
1280 }
1281 }
1282
1283 func TestIntransitiveActivity_MarshalJSON(t *testing.T) {
1284 type fields struct {
1285 ID ID
1286 Type Typer
1287 Name NaturalLanguageValues
1288 Attachment Item
1289 AttributedTo Item
1290 Audience ItemCollection
1291 Content NaturalLanguageValues
1292 Context Item
1293 MediaType MimeType
1294 EndTime time.Time
1295 Generator Item
1296 Icon Item
1297 Image Item
1298 InReplyTo Item
1299 Location Item
1300 Preview Item
1301 Published time.Time
1302 Replies Item
1303 StartTime time.Time
1304 Summary NaturalLanguageValues
1305 Tag ItemCollection
1306 Updated time.Time
1307 URL Item
1308 To ItemCollection
1309 Bto ItemCollection
1310 CC ItemCollection
1311 BCC ItemCollection
1312 Duration time.Duration
1313 Likes Item
1314 Shares Item
1315 Source Source
1316 Actor CanReceiveActivities
1317 Target Item
1318 Result Item
1319 Origin Item
1320 Instrument Item
1321 }
1322 tests := []struct {
1323 name string
1324 fields fields
1325 want [][]byte
1326 wantErr bool
1327 }{
1328 {
1329 name: "Empty",
1330 fields: fields{},
1331 want: nil,
1332 wantErr: false,
1333 },
1334 {
1335 name: "JustID",
1336 fields: fields{
1337 ID: ID("example.com"),
1338 },
1339 want: [][]byte{[]byte(`{"id":"example.com"}`)},
1340 wantErr: false,
1341 },
1342 {
1343 name: "JustType",
1344 fields: fields{
1345 Type: ActivityVocabularyType("myType"),
1346 },
1347 want: [][]byte{[]byte(`{"type":"myType"}`)},
1348 wantErr: false,
1349 },
1350 {
1351 name: "JustOneName",
1352 fields: fields{
1353 Name: NaturalLanguageValues{
1354 NilLangRef: Content("ana"),
1355 },
1356 },
1357 want: [][]byte{[]byte(`{"name":"ana"}`)},
1358 wantErr: false,
1359 },
1360 {
1361 name: "MoreNames",
1362 fields: fields{
1363 Name: NaturalLanguageValues{
1364 English: Content("anna"),
1365 French: Content("anne"),
1366 },
1367 },
1368 want: [][]byte{[]byte(`{"nameMap":{"en":"anna","fr":"anne"}}`), []byte(`{"nameMap":{"fr":"anne","en":"anna"}}`)},
1369 wantErr: false,
1370 },
1371 {
1372 name: "JustOneSummary",
1373 fields: fields{
1374 Summary: NaturalLanguageValues{
1375 NilLangRef: Content("test summary"),
1376 },
1377 },
1378 want: [][]byte{[]byte(`{"summary":"test summary"}`)},
1379 wantErr: false,
1380 },
1381 {
1382 name: "MoreSummaryEntries",
1383 fields: fields{
1384 Summary: NaturalLanguageValues{
1385 English: Content("test summary"),
1386 French: Content("teste summary"),
1387 },
1388 },
1389 want: [][]byte{
1390 []byte(`{"summaryMap":{"en":"test summary","fr":"teste summary"}}`),
1391 []byte(`{"summaryMap":{"fr":"teste summary","en":"test summary"}}`),
1392 },
1393 wantErr: false,
1394 },
1395 {
1396 name: "JustOneContent",
1397 fields: fields{
1398 Content: NaturalLanguageValues{
1399 NilLangRef: Content("test content"),
1400 },
1401 },
1402 want: [][]byte{[]byte(`{"content":"test content"}`)},
1403 wantErr: false,
1404 },
1405 {
1406 name: "MoreContentEntries",
1407 fields: fields{
1408 Content: NaturalLanguageValues{
1409 English: Content("test content"),
1410 French: Content("teste content"),
1411 },
1412 },
1413 want: [][]byte{
1414 []byte(`{"contentMap":{"en":"test content","fr":"teste content"}}`),
1415 []byte(`{"contentMap":{"fr":"teste content","en":"test content"}}`),
1416 },
1417 wantErr: false,
1418 },
1419 {
1420 name: "MediaType",
1421 fields: fields{
1422 MediaType: MimeType("text/stupid"),
1423 },
1424 want: [][]byte{[]byte(`{"mediaType":"text/stupid"}`)},
1425 wantErr: false,
1426 },
1427 {
1428 name: "Attachment",
1429 fields: fields{
1430 Attachment: &Object{
1431 ID: "some example",
1432 Type: VideoType,
1433 },
1434 },
1435 want: [][]byte{[]byte(`{"attachment":{"id":"some example","type":"Video"}}`)},
1436 wantErr: false,
1437 },
1438 {
1439 name: "AttributedTo",
1440 fields: fields{
1441 AttributedTo: &Actor{
1442 ID: "http://example.com/ana",
1443 Type: PersonType,
1444 },
1445 },
1446 want: [][]byte{[]byte(`{"attributedTo":{"id":"http://example.com/ana","type":"Person"}}`)},
1447 wantErr: false,
1448 },
1449 {
1450 name: "AttributedToDouble",
1451 fields: fields{
1452 AttributedTo: ItemCollection{
1453 &Actor{
1454 ID: "http://example.com/ana",
1455 Type: PersonType,
1456 },
1457 &Actor{
1458 ID: "http://example.com/GGG",
1459 Type: GroupType,
1460 },
1461 },
1462 },
1463 want: [][]byte{[]byte(`{"attributedTo":[{"id":"http://example.com/ana","type":"Person"},{"id":"http://example.com/GGG","type":"Group"}]}`)},
1464 wantErr: false,
1465 },
1466 {
1467 name: "Source",
1468 fields: fields{
1469 Source: Source{
1470 MediaType: MimeType("text/plain"),
1471 Content: NaturalLanguageValues{},
1472 },
1473 },
1474 want: [][]byte{[]byte(`{"source":{"mediaType":"text/plain"}}`)},
1475 wantErr: false,
1476 },
1477 }
1478 for _, tt := range tests {
1479 t.Run(tt.name, func(t *testing.T) {
1480 i := IntransitiveActivity{
1481 ID: tt.fields.ID,
1482 Type: tt.fields.Type,
1483 Name: tt.fields.Name,
1484 Attachment: tt.fields.Attachment,
1485 AttributedTo: tt.fields.AttributedTo,
1486 Audience: tt.fields.Audience,
1487 Content: tt.fields.Content,
1488 Context: tt.fields.Context,
1489 MediaType: tt.fields.MediaType,
1490 EndTime: tt.fields.EndTime,
1491 Generator: tt.fields.Generator,
1492 Icon: tt.fields.Icon,
1493 Image: tt.fields.Image,
1494 InReplyTo: tt.fields.InReplyTo,
1495 Location: tt.fields.Location,
1496 Preview: tt.fields.Preview,
1497 Published: tt.fields.Published,
1498 Replies: tt.fields.Replies,
1499 StartTime: tt.fields.StartTime,
1500 Summary: tt.fields.Summary,
1501 Tag: tt.fields.Tag,
1502 Updated: tt.fields.Updated,
1503 URL: tt.fields.URL,
1504 To: tt.fields.To,
1505 Bto: tt.fields.Bto,
1506 CC: tt.fields.CC,
1507 BCC: tt.fields.BCC,
1508 Duration: tt.fields.Duration,
1509 Likes: tt.fields.Likes,
1510 Shares: tt.fields.Shares,
1511 Source: tt.fields.Source,
1512 Actor: tt.fields.Actor,
1513 Target: tt.fields.Target,
1514 Result: tt.fields.Result,
1515 Origin: tt.fields.Origin,
1516 Instrument: tt.fields.Instrument,
1517 }
1518 got, err := i.MarshalJSON()
1519 if (err != nil) != tt.wantErr {
1520 t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
1521 return
1522 }
1523 found := got == nil
1524 for _, wantBytes := range tt.want {
1525 if bytes.Equal(got, wantBytes) {
1526 found = true
1527 }
1528 }
1529 if !found {
1530 t.Errorf("MarshalJSON() got = %s, want %s", got, tt.want)
1531 }
1532 })
1533 }
1534 }
1535
1536 func TestActivity_Equals(t *testing.T) {
1537 type fields struct {
1538 ID ID
1539 Type Typer
1540 Name NaturalLanguageValues
1541 Attachment Item
1542 AttributedTo Item
1543 Audience ItemCollection
1544 Content NaturalLanguageValues
1545 Context Item
1546 MediaType MimeType
1547 EndTime time.Time
1548 Generator Item
1549 Icon Item
1550 Image Item
1551 InReplyTo Item
1552 Location Item
1553 Preview Item
1554 Published time.Time
1555 Replies Item
1556 StartTime time.Time
1557 Summary NaturalLanguageValues
1558 Tag ItemCollection
1559 Updated time.Time
1560 URL Item
1561 To ItemCollection
1562 Bto ItemCollection
1563 CC ItemCollection
1564 BCC ItemCollection
1565 Duration time.Duration
1566 Likes Item
1567 Shares Item
1568 Source Source
1569 Actor Item
1570 Target Item
1571 Result Item
1572 Origin Item
1573 Instrument Item
1574 Object Item
1575 }
1576 tests := []struct {
1577 name string
1578 fields fields
1579 arg Item
1580 want bool
1581 }{
1582 {
1583 name: "equal-empty-activity",
1584 fields: fields{},
1585 arg: Activity{},
1586 want: true,
1587 },
1588 {
1589 name: "equal-activity-just-id",
1590 fields: fields{ID: "test"},
1591 arg: Activity{ID: "test"},
1592 want: true,
1593 },
1594 {
1595 name: "equal-activity-id",
1596 fields: fields{ID: "test", URL: IRI("example.com")},
1597 arg: Activity{ID: "test"},
1598 want: true,
1599 },
1600 {
1601 name: "equal-false-with-id-and-url",
1602 fields: fields{ID: "test"},
1603 arg: Activity{ID: "test", URL: IRI("example.com")},
1604 want: false,
1605 },
1606 {
1607 name: "not a valid activity",
1608 fields: fields{ID: "http://example.com"},
1609 arg: Link{ID: "http://example.com"},
1610 want: false,
1611 },
1612 }
1613 for _, tt := range tests {
1614 t.Run(tt.name, func(t *testing.T) {
1615 a := Activity{
1616 ID: tt.fields.ID,
1617 Type: tt.fields.Type,
1618 Name: tt.fields.Name,
1619 Attachment: tt.fields.Attachment,
1620 AttributedTo: tt.fields.AttributedTo,
1621 Audience: tt.fields.Audience,
1622 Content: tt.fields.Content,
1623 Context: tt.fields.Context,
1624 MediaType: tt.fields.MediaType,
1625 EndTime: tt.fields.EndTime,
1626 Generator: tt.fields.Generator,
1627 Icon: tt.fields.Icon,
1628 Image: tt.fields.Image,
1629 InReplyTo: tt.fields.InReplyTo,
1630 Location: tt.fields.Location,
1631 Preview: tt.fields.Preview,
1632 Published: tt.fields.Published,
1633 Replies: tt.fields.Replies,
1634 StartTime: tt.fields.StartTime,
1635 Summary: tt.fields.Summary,
1636 Tag: tt.fields.Tag,
1637 Updated: tt.fields.Updated,
1638 URL: tt.fields.URL,
1639 To: tt.fields.To,
1640 Bto: tt.fields.Bto,
1641 CC: tt.fields.CC,
1642 BCC: tt.fields.BCC,
1643 Duration: tt.fields.Duration,
1644 Likes: tt.fields.Likes,
1645 Shares: tt.fields.Shares,
1646 Source: tt.fields.Source,
1647 Actor: tt.fields.Actor,
1648 Target: tt.fields.Target,
1649 Result: tt.fields.Result,
1650 Origin: tt.fields.Origin,
1651 Instrument: tt.fields.Instrument,
1652 Object: tt.fields.Object,
1653 }
1654 if got := a.Equals(tt.arg); got != tt.want {
1655 t.Errorf("Equal() = %v, want %v, have: %v, target: %v", got, tt.want, a, tt.arg)
1656 }
1657 })
1658 }
1659 }
1660
1661 func TestCleanRecipients(t *testing.T) {
1662 tests := []struct {
1663 name string
1664 it Item
1665 }{
1666 {
1667 name: "nil",
1668 it: nil,
1669 },
1670 {
1671 name: "empty Object",
1672 it: &Object{},
1673 },
1674 {
1675 name: "Object with Bto",
1676 it: &Object{Bto: ItemCollection{IRI("https://example.com")}},
1677 },
1678 {
1679 name: "Object with BCC",
1680 it: &Object{BCC: ItemCollection{IRI("https://example.com")}},
1681 },
1682 {
1683 name: "Object with Bto/BCC",
1684 it: &Object{
1685 Bto: ItemCollection{IRI("https://example.com/1")},
1686 BCC: ItemCollection{IRI("https://example.com/2")},
1687 },
1688 },
1689 {
1690 name: "empty Actor",
1691 it: &Actor{},
1692 },
1693 {
1694 name: "Actor with Bto",
1695 it: &Actor{Bto: ItemCollection{IRI("https://example.com")}},
1696 },
1697 {
1698 name: "Actor with BCC",
1699 it: &Actor{BCC: ItemCollection{IRI("https://example.com")}},
1700 },
1701 {
1702 name: "Actor with Bto/BCC",
1703 it: &Actor{
1704 Bto: ItemCollection{IRI("https://example.com/1")},
1705 BCC: ItemCollection{IRI("https://example.com/2")},
1706 },
1707 },
1708 {
1709 name: "empty Activity",
1710 it: &Activity{},
1711 },
1712 {
1713 name: "Activity with Bto",
1714 it: &Activity{Bto: ItemCollection{IRI("https://example.com")}},
1715 },
1716 {
1717 name: "Activity with BCC",
1718 it: &Activity{BCC: ItemCollection{IRI("https://example.com")}},
1719 },
1720 {
1721 name: "Activity with Bto/BCC",
1722 it: &Activity{
1723 Bto: ItemCollection{IRI("https://example.com/1")},
1724 BCC: ItemCollection{IRI("https://example.com/2")},
1725 },
1726 },
1727 {
1728 name: "empty IntransitiveActivity",
1729 it: &IntransitiveActivity{},
1730 },
1731 {
1732 name: "IntransitiveActivity with Bto",
1733 it: &IntransitiveActivity{Bto: ItemCollection{IRI("https://example.com")}},
1734 },
1735 {
1736 name: "IntransitiveActivity with BCC",
1737 it: &IntransitiveActivity{BCC: ItemCollection{IRI("https://example.com")}},
1738 },
1739 {
1740 name: "IntransitiveActivity with Bto/BCC",
1741 it: &IntransitiveActivity{
1742 Bto: ItemCollection{IRI("https://example.com/1")},
1743 BCC: ItemCollection{IRI("https://example.com/2")},
1744 },
1745 },
1746 {
1747 name: "empty Collection",
1748 it: &Collection{},
1749 },
1750 {
1751 name: "Collection with Bto",
1752 it: &Collection{Bto: ItemCollection{IRI("https://example.com")}},
1753 },
1754 {
1755 name: "Collection with BCC",
1756 it: &Collection{BCC: ItemCollection{IRI("https://example.com")}},
1757 },
1758 {
1759 name: "Collection with Bto/BCC",
1760 it: &Collection{
1761 Bto: ItemCollection{IRI("https://example.com/1")},
1762 BCC: ItemCollection{IRI("https://example.com/2")},
1763 },
1764 },
1765 }
1766 for _, tt := range tests {
1767 t.Run(tt.name, func(t *testing.T) {
1768 it := CleanRecipients(tt.it)
1769 _ = OnObject(it, func(o *Object) error {
1770 if len(o.Bto) > 0 {
1771 t.Errorf("Bto failed to be cleaned: %v", o.Bto)
1772 }
1773 if len(o.BCC) > 0 {
1774 t.Errorf("BCC failed to be cleaned: %v", o.BCC)
1775 }
1776 return nil
1777 })
1778 })
1779 }
1780 }