-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfeeds_integration_test.go
More file actions
2108 lines (1741 loc) · 75 KB
/
feeds_integration_test.go
File metadata and controls
2108 lines (1741 loc) · 75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package getstream_test
import (
"context"
"fmt"
"os"
"strings"
"testing"
"time"
"github.com/GetStream/getstream-go/v4"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
/*
Systematic Integration tests for Feed operations
These tests follow a logical flow: setup → create → operate → cleanup
Test order:
1. Environment Setup (user, feed creation)
2. Activity Operations (create, read, update, delete)
3. Reaction Operations (add, query, delete)
4. Comment Operations (add, read, update, delete)
5. Bookmark Operations (add, query, update, delete)
6. Follow Operations (follow, query, unfollow)
7. Batch Operations
8. Advanced Operations (polls, pins, etc.)
9. Cleanup
*/
const (
userFeedType = "user"
pollQuestion = "What's your favorite programming language?"
testBookmarkFolder = "test-bookmarks1"
)
// TestFeedIntegrationSuite runs comprehensive integration tests for the Feeds API
func TestFeedIntegrationSuite(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("Skipping integration tests in short mode")
}
ctx := context.Background()
client, err := getstream.NewClientFromEnvVars()
require.NoError(t, err, "Failed to create client")
feedsClient := client.Feeds()
testUserID := "test-user-" + uuid.New().String()
testUserID2 := "test-user-2-" + uuid.New().String()
// Track created resources for cleanup
var createdActivityIDs []string
var createdCommentIDs []string
// Setup environment
setupEnvironment(t, ctx, client, testUserID, testUserID2)
// Cleanup function
defer func() {
cleanupResources(ctx, feedsClient, createdActivityIDs, createdCommentIDs)
}()
// Run all tests
t.Run("Test01_SetupEnvironmentDemo", func(t *testing.T) {
test01SetupEnvironmentDemo(t, testUserID, testUserID2)
})
t.Run("Test02_CreateActivity", func(t *testing.T) {
test02CreateActivity(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test02b_CreateActivityWithAttachments", func(t *testing.T) {
test02bCreateActivityWithAttachments(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test02c_CreateVideoActivity", func(t *testing.T) {
test02cCreateVideoActivity(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test02d_CreateStoryActivityWithExpiration", func(t *testing.T) {
test02dCreateStoryActivityWithExpiration(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test02e_CreateActivityMultipleFeeds", func(t *testing.T) {
test02eCreateActivityMultipleFeeds(t, ctx, feedsClient, testUserID, testUserID2, &createdActivityIDs)
})
t.Run("Test03_QueryActivities", func(t *testing.T) {
test03QueryActivities(t, ctx, feedsClient)
})
t.Run("Test04_GetSingleActivity", func(t *testing.T) {
test04GetSingleActivity(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test05_UpdateActivity", func(t *testing.T) {
test05UpdateActivity(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test06_AddReaction", func(t *testing.T) {
test06AddReaction(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test07_QueryReactions", func(t *testing.T) {
test07QueryReactions(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test08_AddComment", func(t *testing.T) {
test08AddComment(t, ctx, feedsClient, testUserID, &createdActivityIDs, &createdCommentIDs)
})
t.Run("Test09_QueryComments", func(t *testing.T) {
test09QueryComments(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test10_UpdateComment", func(t *testing.T) {
test10UpdateComment(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test11_AddBookmark", func(t *testing.T) {
test11AddBookmark(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test12_QueryBookmarks", func(t *testing.T) {
test12QueryBookmarks(t, ctx, feedsClient, testUserID)
})
t.Run("Test13_UpdateBookmark", func(t *testing.T) {
test13UpdateBookmark(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test14_FollowUser", func(t *testing.T) {
test14FollowUser(t, ctx, feedsClient, testUserID, testUserID2)
})
t.Run("Test15_QueryFollows", func(t *testing.T) {
test15QueryFollows(t, ctx, feedsClient)
})
t.Run("Test16_UpsertActivities", func(t *testing.T) {
test16UpsertActivities(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test17_PinActivity", func(t *testing.T) {
test17PinActivity(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test18_UnpinActivity", func(t *testing.T) {
test18UnpinActivity(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test19_DeleteBookmark", func(t *testing.T) {
test19DeleteBookmark(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test20_DeleteReaction", func(t *testing.T) {
test20DeleteReaction(t, ctx, feedsClient, testUserID, testUserID2, &createdActivityIDs)
})
t.Run("Test21_DeleteComment", func(t *testing.T) {
test21DeleteComment(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test22_UnfollowUser", func(t *testing.T) {
test22UnfollowUser(t, ctx, feedsClient, testUserID2, testUserID)
})
t.Run("Test23_DeleteActivities", func(t *testing.T) {
test23DeleteActivities(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test24_CreatePoll", func(t *testing.T) {
test24CreatePoll(t, ctx, client, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test25_VotePoll", func(t *testing.T) {
test25VotePoll(t, ctx, client, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test26_ModerateActivity", func(t *testing.T) {
test26ModerateActivity(t, ctx, feedsClient, testUserID, testUserID2, &createdActivityIDs)
})
t.Run("Test27_DeviceManagement", func(t *testing.T) {
test27DeviceManagement(t, ctx, client, testUserID)
})
t.Run("Test28_QueryActivitiesWithFilters", func(t *testing.T) {
test28QueryActivitiesWithFilters(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test29_GetFeedActivitiesWithPagination", func(t *testing.T) {
test29GetFeedActivitiesWithPagination(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test30_ErrorHandlingScenarios", func(t *testing.T) {
test30ErrorHandlingScenarios(t, ctx, feedsClient, testUserID)
})
t.Run("Test31_AuthenticationScenarios", func(t *testing.T) {
test31AuthenticationScenarios(t, ctx, feedsClient, testUserID, &createdActivityIDs)
})
t.Run("Test32_RealWorldUsageDemo", func(t *testing.T) {
test32RealWorldUsageDemo(t, ctx, feedsClient, testUserID, testUserID2, &createdActivityIDs)
})
// Feed Group CRUD Operations
t.Run("Test33_FeedGroupCRUD", func(t *testing.T) {
// Flaky test due to eventual consistency in feed creation
// test33FeedGroupCRUD(t, ctx, feedsClient)
})
// Feed View CRUD Operations
t.Run("Test34_FeedViewCRUD", func(t *testing.T) {
test34FeedViewCRUD(t, ctx, feedsClient)
})
t.Run("UploadFileFromPath", func(t *testing.T) {
testFileUploadIntegration(t, ctx, client, testUserID)
})
t.Run("UploadImageWithSizes", func(t *testing.T) {
testImageUploadIntegration(t, ctx, client, testUserID)
})
t.Run("UploadFileError", func(t *testing.T) {
testFileUploadErrorIntegration(t, ctx, client, testUserID)
})
}
// =================================================================
// ENVIRONMENT SETUP
// =================================================================
func setupEnvironment(t *testing.T, ctx context.Context, client *getstream.Stream, testUserID, testUserID2 string) {
// Create test users
// snippet-start: CreateUsers
_, err := client.UpdateUsers(ctx, &getstream.UpdateUsersRequest{
Users: map[string]getstream.UserRequest{
testUserID: {
ID: testUserID,
Name: getstream.PtrTo("Test User " + testUserID),
Role: getstream.PtrTo("user"),
},
testUserID2: {
ID: testUserID2,
Name: getstream.PtrTo("Test User " + testUserID2),
Role: getstream.PtrTo("user"),
},
},
})
// snippet-end: CreateUsers
if err != nil {
t.Logf("⚠️ Setup failed: %v", err)
// Continue with tests even if setup partially fails
}
// Create feeds
// snippet-start: GetOrCreateFeed
feedsClient := client.Feeds()
_, err = feedsClient.GetOrCreateFeed(ctx, userFeedType, testUserID, &getstream.GetOrCreateFeedRequest{
UserID: &testUserID,
})
if err != nil {
t.Logf("Failed to create feed 1: %v", err)
}
_, err = feedsClient.GetOrCreateFeed(ctx, userFeedType, testUserID2, &getstream.GetOrCreateFeedRequest{
UserID: &testUserID2,
})
// snippet-end: GetOrCreateFeed
if err != nil {
t.Logf("Failed to create feed 2: %v", err)
}
}
// =================================================================
// 1. ENVIRONMENT SETUP TEST
// =================================================================
func test01SetupEnvironmentDemo(t *testing.T, testUserID, testUserID2 string) {
fmt.Println("\n🔧 Demonstrating environment setup...")
fmt.Printf("✅ Users and feeds are automatically created in setup\n")
fmt.Printf(" Test User 1: %s\n", testUserID)
fmt.Printf(" Test User 2: %s\n", testUserID2)
assert.True(t, true) // Just a demo test
}
// =================================================================
// 2. ACTIVITY OPERATIONS
// =================================================================
func test02CreateActivity(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n📝 Testing activity creation...")
// snippet-start: AddActivity
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
response, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Feeds: []string{feedIdentifier},
Text: getstream.PtrTo("This is a test activity from Go SDK"),
UserID: &testUserID,
Custom: map[string]interface{}{
"test_field": "test_value",
"timestamp": time.Now().Unix(),
},
})
// snippet-end: AddActivity
assertResponseSuccess(t, response, err, "add activity")
// Access the typed response data directly
require.NotNil(t, response.Data.Activity)
require.NotEmpty(t, response.Data.Activity.ID)
require.NotNil(t, response.Data.Activity.Text)
// Compare text
assert.Equal(t, "This is a test activity from Go SDK", *response.Data.Activity.Text)
activityID := response.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
fmt.Printf("✅ Created activity with ID: %s\n", activityID)
}
func test02bCreateActivityWithAttachments(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n🖼️ Testing activity creation with image attachments...")
// snippet-start: AddActivityWithImageAttachment
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
response, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Feeds: []string{feedIdentifier},
Text: getstream.PtrTo("Look at this amazing view of NYC!"),
UserID: &testUserID,
Attachments: []getstream.Attachment{
{
ImageUrl: getstream.PtrTo("https://example.com/nyc-skyline.jpg"),
Type: getstream.PtrTo("image"),
Title: getstream.PtrTo("NYC Skyline"),
},
},
Custom: map[string]interface{}{
"location": "New York City",
"camera": "iPhone 15 Pro",
},
})
// snippet-end: AddActivityWithImageAttachment
assertResponseSuccess(t, response, err, "add activity with image attachment")
activityID := response.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
fmt.Printf("✅ Created activity with image attachment: %s\n", activityID)
}
func test02cCreateVideoActivity(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n🎥 Testing video activity creation...")
// snippet-start: AddVideoActivity
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
response, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "video",
Feeds: []string{feedIdentifier},
Text: getstream.PtrTo("Check out this amazing video!"),
UserID: &testUserID,
Attachments: []getstream.Attachment{
{
AssetUrl: getstream.PtrTo("https://example.com/amazing-video.mp4"),
Type: getstream.PtrTo("video"),
Title: getstream.PtrTo("Amazing Video"),
Custom: map[string]interface{}{
"duration": 120,
},
},
},
Custom: map[string]interface{}{
"video_quality": "4K",
"duration_seconds": 120,
},
})
// snippet-end: AddVideoActivity
assertResponseSuccess(t, response, err, "add video activity")
activityID := response.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
fmt.Printf("✅ Created video activity: %s\n", activityID)
}
func test02dCreateStoryActivityWithExpiration(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n📖 Testing story activity with expiration...")
// snippet-start: AddStoryActivityWithExpiration
tomorrow := time.Now().Add(24 * time.Hour)
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
response, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "story",
Feeds: []string{feedIdentifier},
Text: getstream.PtrTo("My daily story - expires tomorrow!"),
UserID: &testUserID,
ExpiresAt: getstream.PtrTo(tomorrow.Format(time.RFC3339)),
Attachments: []getstream.Attachment{
{
ImageUrl: getstream.PtrTo("https://example.com/story-image.jpg"),
Type: getstream.PtrTo("image"),
},
{
AssetUrl: getstream.PtrTo("https://example.com/story-video.mp4"),
Type: getstream.PtrTo("video"),
Custom: map[string]interface{}{
"duration": 15,
},
},
},
Custom: map[string]interface{}{
"story_type": "daily",
"auto_expire": true,
},
})
// snippet-end: AddStoryActivityWithExpiration
assertResponseSuccess(t, response, err, "add story activity with expiration")
activityID := response.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
fmt.Printf("✅ Created story activity with expiration: %s\n", activityID)
}
func test02eCreateActivityMultipleFeeds(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID, testUserID2 string, createdActivityIDs *[]string) {
fmt.Println("\n📡 Testing activity creation to multiple feeds...")
// snippet-start: AddActivityToMultipleFeeds
feedIdentifier1 := fmt.Sprintf("%s:%s", userFeedType, testUserID)
feedIdentifier2 := fmt.Sprintf("%s:%s", userFeedType, testUserID2)
response, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Feeds: []string{feedIdentifier1, feedIdentifier2},
Text: getstream.PtrTo("This post appears in multiple feeds!"),
UserID: &testUserID,
Custom: map[string]interface{}{
"cross_posted": true,
"target_feeds": 2,
},
})
// snippet-end: AddActivityToMultipleFeeds
assertResponseSuccess(t, response, err, "add activity to multiple feeds")
activityID := response.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
fmt.Printf("✅ Created activity in multiple feeds: %s\n", activityID)
}
func test03QueryActivities(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient) {
fmt.Println("\n🔍 Testing activity querying...")
// snippet-start: QueryActivities
response, err := feedsClient.QueryActivities(ctx, &getstream.QueryActivitiesRequest{
Limit: getstream.PtrTo(10),
Filter: map[string]interface{}{
"activity_type": "post",
},
})
// snippet-end: QueryActivities
assertResponseSuccess(t, response, err, "query activities")
require.NotNil(t, response.Data.Activities)
fmt.Println("✅ Queried activities successfully")
}
func test04GetSingleActivity(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n📄 Testing single activity retrieval...")
// First create an activity to retrieve
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Text: getstream.PtrTo("Activity for retrieval test"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
})
assertResponseSuccess(t, createResponse, err, "create activity for retrieval test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// snippet-start: GetActivity
response, err := feedsClient.GetActivity(ctx, activityID, &getstream.GetActivityRequest{})
// snippet-end: GetActivity
assertResponseSuccess(t, response, err, "get activity")
require.NotNil(t, response.Data.Activity)
assert.Equal(t, activityID, response.Data.Activity.ID)
fmt.Println("✅ Retrieved single activity")
}
func test05UpdateActivity(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n✏️ Testing activity update...")
// First create an activity to update
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Text: getstream.PtrTo("Activity for update test"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
})
assertResponseSuccess(t, createResponse, err, "create activity for update test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// snippet-start: UpdateActivity
response, err := feedsClient.UpdateActivity(ctx, activityID, &getstream.UpdateActivityRequest{
Text: getstream.PtrTo("Updated activity text from Go SDK"),
UserID: &testUserID, // Required for server-side auth
Custom: map[string]interface{}{
"updated": true,
"update_time": time.Now().Unix(),
},
})
// snippet-end: UpdateActivity
assertResponseSuccess(t, response, err, "update activity")
fmt.Println("✅ Updated activity")
}
// =================================================================
// 3. REACTION OPERATIONS
// =================================================================
func test06AddReaction(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n👍 Testing reaction addition...")
// First create an activity to react to
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Text: getstream.PtrTo("Activity for reaction test"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
})
assertResponseSuccess(t, createResponse, err, "create activity for reaction test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// snippet-start: AddReaction
response, err := feedsClient.AddActivityReaction(ctx, activityID, &getstream.AddActivityReactionRequest{
Type: "like",
UserID: &testUserID,
})
// snippet-end: AddReaction
assertResponseSuccess(t, response, err, "add reaction")
fmt.Println("✅ Added like reaction")
}
func test07QueryReactions(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n🔍 Testing reaction querying...")
// Create an activity and add a reaction to it
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Text: getstream.PtrTo("Activity for query reactions test"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
})
assertResponseSuccess(t, createResponse, err, "create activity for query reactions test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// Add a reaction first
reactionResponse, err := feedsClient.AddActivityReaction(ctx, activityID, &getstream.AddActivityReactionRequest{
Type: "like",
UserID: &testUserID,
})
assertResponseSuccess(t, reactionResponse, err, "add reaction for query test")
// snippet-start: QueryActivityReactions
response, err := feedsClient.QueryActivityReactions(ctx, activityID, &getstream.QueryActivityReactionsRequest{
Limit: getstream.PtrTo(10),
Filter: map[string]interface{}{
"type": "like",
},
})
// snippet-end: QueryActivityReactions
if err != nil {
fmt.Printf("Query reactions skipped: %v\n", err)
t.Skip("Query reactions not supported: " + err.Error())
return
}
assertResponseSuccess(t, response, err, "query reactions")
fmt.Println("✅ Queried reactions")
}
// =================================================================
// 4. COMMENT OPERATIONS
// =================================================================
func test08AddComment(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs, createdCommentIDs *[]string) {
fmt.Println("\n💬 Testing comment addition...")
// First create an activity to comment on
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Feeds: []string{feedIdentifier},
Text: getstream.PtrTo("Activity for comment test"),
UserID: &testUserID,
})
assertResponseSuccess(t, createResponse, err, "create activity for comment test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// snippet-start: AddComment
response, err := feedsClient.AddComment(ctx, &getstream.AddCommentRequest{
Comment: getstream.PtrTo("This is a test comment from Go SDK"),
ObjectID: &activityID,
ObjectType: getstream.PtrTo("activity"),
UserID: &testUserID,
})
// snippet-end: AddComment
assertResponseSuccess(t, response, err, "add comment")
if response.Data.Comment.ID != "" {
testCommentID := response.Data.Comment.ID
*createdCommentIDs = append(*createdCommentIDs, testCommentID)
fmt.Printf("✅ Added comment with ID: %s\n", testCommentID)
} else {
fmt.Println("✅ Added comment (no ID returned)")
}
}
func test09QueryComments(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n🔍 Testing comment querying...")
// Create an activity and add a comment to it
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Text: getstream.PtrTo("Activity for query comments test"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
})
assertResponseSuccess(t, createResponse, err, "create activity for query comments test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// Add a comment first
commentResponse, err := feedsClient.AddComment(ctx, &getstream.AddCommentRequest{
Comment: getstream.PtrTo("Comment for query test"),
ObjectID: &activityID,
ObjectType: getstream.PtrTo("activity"),
UserID: &testUserID,
})
assertResponseSuccess(t, commentResponse, err, "add comment for query test")
// snippet-start: QueryComments
response, err := feedsClient.QueryComments(ctx, &getstream.QueryCommentsRequest{
Filter: map[string]interface{}{
"object_id": activityID,
},
Limit: getstream.PtrTo(10),
})
// snippet-end: QueryComments
assertResponseSuccess(t, response, err, "query comments")
fmt.Println("✅ Queried comments")
}
func test10UpdateComment(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n✏️ Testing comment update...")
// Create an activity and add a comment to update
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Text: getstream.PtrTo("Activity for update comment test"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
})
assertResponseSuccess(t, createResponse, err, "create activity for update comment test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// Add a comment to update
commentResponse, err := feedsClient.AddComment(ctx, &getstream.AddCommentRequest{
Comment: getstream.PtrTo("Comment to be updated"),
ObjectID: &activityID,
ObjectType: getstream.PtrTo("activity"),
UserID: &testUserID,
})
assertResponseSuccess(t, commentResponse, err, "add comment for update test")
commentID := "comment-id" // Fallback if ID not returned
if commentResponse.Data.Comment.ID != "" {
commentID = commentResponse.Data.Comment.ID
}
// snippet-start: UpdateComment
response, err := feedsClient.UpdateComment(ctx, commentID, &getstream.UpdateCommentRequest{
Comment: getstream.PtrTo("Updated comment text from Go SDK"),
UserID: &testUserID,
})
// snippet-end: UpdateComment
assertResponseSuccess(t, response, err, "update comment")
fmt.Println("✅ Updated comment")
}
// =================================================================
// 5. BOOKMARK OPERATIONS
// =================================================================
func test11AddBookmark(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n🔖 Testing bookmark addition...")
// Create an activity to bookmark
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Text: getstream.PtrTo("Activity for bookmark test"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
})
assertResponseSuccess(t, createResponse, err, "create activity for bookmark test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// snippet-start: AddBookmark
response, err := feedsClient.AddBookmark(ctx, activityID, &getstream.AddBookmarkRequest{
UserID: &testUserID,
NewFolder: &getstream.AddFolderRequest{
Name: testBookmarkFolder,
},
})
// snippet-end: AddBookmark
if err != nil {
fmt.Printf("Add bookmark failed: %v\n", err)
t.Skip("Add bookmark not supported: " + err.Error())
return
}
assertResponseSuccess(t, response, err, "add bookmark")
fmt.Println("✅ Added bookmark")
}
func test12QueryBookmarks(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string) {
fmt.Println("\n🔍 Testing bookmark querying...")
// snippet-start: QueryBookmarks
response, err := feedsClient.QueryBookmarks(ctx, &getstream.QueryBookmarksRequest{
Limit: getstream.PtrTo(10),
Filter: map[string]interface{}{
"user_id": testUserID,
},
})
// snippet-end: QueryBookmarks
assertResponseSuccess(t, response, err, "query bookmarks")
fmt.Println("✅ Queried bookmarks")
}
func test13UpdateBookmark(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n✏️ Testing bookmark update...")
// Create an activity and bookmark it first
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Feeds: []string{feedIdentifier},
Text: getstream.PtrTo("Activity for update bookmark test"),
UserID: &testUserID,
})
assertResponseSuccess(t, createResponse, err, "create activity for update bookmark test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// Add a bookmark first
bookmarkResponse, err := feedsClient.AddBookmark(ctx, activityID, &getstream.AddBookmarkRequest{
NewFolder: &getstream.AddFolderRequest{
Name: testBookmarkFolder,
},
UserID: &testUserID,
})
assertResponseSuccess(t, bookmarkResponse, err, "add bookmark for update test")
// snippet-start: UpdateBookmark
folderID := bookmarkResponse.Data.Bookmark.Folder.ID
response, err := feedsClient.UpdateBookmark(ctx, activityID, &getstream.UpdateBookmarkRequest{
FolderID: &folderID,
UserID: &testUserID,
})
// snippet-end: UpdateBookmark
assertResponseSuccess(t, response, err, "update bookmark")
fmt.Println("✅ Updated bookmark")
}
// =================================================================
// 6. FOLLOW OPERATIONS
// =================================================================
func test14FollowUser(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID, testUserID2 string) {
fmt.Println("\n👥 Testing follow operation...")
// snippet-start: Follow
source := fmt.Sprintf("%s:%s", userFeedType, testUserID)
target := fmt.Sprintf("%s:%s", userFeedType, testUserID2)
response, err := feedsClient.Follow(ctx, &getstream.FollowRequest{
Source: source,
Target: target,
})
// snippet-end: Follow
if err != nil {
fmt.Printf("Follow failed: %v\n", err)
t.Skip("Follow operation not supported: " + err.Error())
return
}
assertResponseSuccess(t, response, err, "follow user")
fmt.Printf("✅ Followed user: %s\n", testUserID2)
}
func test15QueryFollows(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient) {
fmt.Println("\n🔍 Testing follow querying...")
// snippet-start: QueryFollows
response, err := feedsClient.QueryFollows(ctx, &getstream.QueryFollowsRequest{
Limit: getstream.PtrTo(10),
})
// snippet-end: QueryFollows
assertResponseSuccess(t, response, err, "query follows")
fmt.Println("✅ Queried follows")
}
// =================================================================
// 7. BATCH OPERATIONS
// =================================================================
func test16UpsertActivities(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n📝 Testing batch activity upsert...")
// snippet-start: UpsertActivities
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
// Use unique IDs to ensure we're creating new activities, not updating existing ones
activityID1 := "upsert-activity-1-" + uuid.New().String()
activityID2 := "upsert-activity-2-" + uuid.New().String()
activities := []getstream.ActivityRequest{
{
ID: &activityID1,
Type: "post",
Text: getstream.PtrTo("Batch activity 1"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
},
{
ID: &activityID2,
Type: "post",
Text: getstream.PtrTo("Batch activity 2"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
},
}
response, err := feedsClient.UpsertActivities(ctx, &getstream.UpsertActivitiesRequest{
Activities: activities,
})
// snippet-end: UpsertActivities
assertResponseSuccess(t, response, err, "upsert activities")
// Track created activities for cleanup
if response.Data.Activities != nil {
for _, activity := range response.Data.Activities {
if activity.ID != "" {
*createdActivityIDs = append(*createdActivityIDs, activity.ID)
}
}
}
fmt.Println("✅ Upserted batch activities")
}
// =================================================================
// 8. ADVANCED OPERATIONS
// =================================================================
func test17PinActivity(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n📌 Testing activity pinning...")
// Create an activity to pin
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Feeds: []string{feedIdentifier},
Text: getstream.PtrTo("Activity for pin test"),
UserID: &testUserID,
})
assertResponseSuccess(t, createResponse, err, "create activity for pin test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// snippet-start: PinActivity
response, err := feedsClient.PinActivity(ctx, userFeedType, testUserID, activityID, &getstream.PinActivityRequest{
UserID: &testUserID,
})
// snippet-end: PinActivity
assertResponseSuccess(t, response, err, "pin activity")
fmt.Println("✅ Pinned activity")
}
func test18UnpinActivity(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n📌 Testing activity unpinning...")
// Create an activity, pin it, then unpin it
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Feeds: []string{feedIdentifier},
Text: getstream.PtrTo("Activity for unpin test"),
UserID: &testUserID,
})
assertResponseSuccess(t, createResponse, err, "create activity for unpin test")
activityID := createResponse.Data.Activity.ID
*createdActivityIDs = append(*createdActivityIDs, activityID)
// Pin it first
pinResponse, err := feedsClient.PinActivity(ctx, userFeedType, testUserID, activityID, &getstream.PinActivityRequest{
UserID: &testUserID,
})
assertResponseSuccess(t, pinResponse, err, "pin activity for unpin test")
// snippet-start: UnpinActivity
response, err := feedsClient.UnpinActivity(ctx, userFeedType, testUserID, activityID, &getstream.UnpinActivityRequest{
UserID: &testUserID,
})
// snippet-end: UnpinActivity
assertResponseSuccess(t, response, err, "unpin activity")
fmt.Println("✅ Unpinned activity")
}
// =================================================================
// 9. CLEANUP OPERATIONS (in reverse order)
// =================================================================
func test19DeleteBookmark(t *testing.T, ctx context.Context, feedsClient *getstream.FeedsClient, testUserID string, createdActivityIDs *[]string) {
fmt.Println("\n🗑️ Testing bookmark deletion...")
// Create an activity and bookmark it first
feedIdentifier := fmt.Sprintf("%s:%s", userFeedType, testUserID)
createResponse, err := feedsClient.AddActivity(ctx, &getstream.AddActivityRequest{
Type: "post",
Text: getstream.PtrTo("Activity for delete bookmark test"),
UserID: &testUserID,
Feeds: []string{feedIdentifier},
})
assertResponseSuccess(t, createResponse, err, "create activity for delete bookmark test")