@stream-io/feeds-client 0.1.11 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/index-react-bindings.browser.cjs +537 -331
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +537 -331
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +537 -331
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +537 -331
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +536 -329
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +536 -330
- package/dist/index.browser.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.node.cjs +536 -329
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +536 -330
- package/dist/index.node.js.map +1 -1
- package/dist/src/feed/event-handlers/activity/handle-activity-deleted.d.ts +12 -3
- package/dist/src/feed/event-handlers/activity/handle-activity-pinned.d.ts +3 -0
- package/dist/src/feed/event-handlers/activity/handle-activity-reaction-added.d.ts +10 -6
- package/dist/src/feed/event-handlers/activity/handle-activity-reaction-deleted.d.ts +10 -6
- package/dist/src/feed/event-handlers/activity/handle-activity-unpinned.d.ts +3 -0
- package/dist/src/feed/event-handlers/activity/handle-activity-updated.d.ts +7 -3
- package/dist/src/feed/event-handlers/bookmark/handle-bookmark-added.d.ts +10 -6
- package/dist/src/feed/event-handlers/bookmark/handle-bookmark-deleted.d.ts +10 -6
- package/dist/src/feed/event-handlers/bookmark/handle-bookmark-updated.d.ts +10 -6
- package/dist/src/feed/event-handlers/index.d.ts +1 -0
- package/dist/src/feed/event-handlers/watch/handle-watch-started.d.ts +2 -0
- package/dist/src/feed/event-handlers/watch/handle-watch-stopped.d.ts +2 -0
- package/dist/src/feed/event-handlers/watch/index.d.ts +2 -0
- package/dist/src/feed/feed.d.ts +4 -12
- package/dist/src/feeds-client/event-handlers/index.d.ts +1 -0
- package/dist/src/feeds-client/event-handlers/user/handle-user-updated.d.ts +3 -0
- package/dist/src/{feeds-client.d.ts → feeds-client/feeds-client.d.ts} +16 -16
- package/dist/src/feeds-client/index.d.ts +2 -0
- package/dist/src/gen/feeds/FeedsApi.d.ts +27 -23
- package/dist/src/gen/models/index.d.ts +198 -23
- package/dist/src/test-utils/response-generators.d.ts +46 -1
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/update-entity-in-array.d.ts +27 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -1
- package/package.json +2 -2
- package/src/feed/event-handlers/activity/activity-reaction-utils.test.ts +108 -96
- package/src/feed/event-handlers/activity/activity-utils.test.ts +84 -122
- package/src/feed/event-handlers/activity/handle-activity-deleted.ts +43 -10
- package/src/feed/event-handlers/activity/handle-activity-pinned.test.ts +60 -0
- package/src/feed/event-handlers/activity/handle-activity-pinned.ts +30 -0
- package/src/feed/event-handlers/activity/handle-activity-reaction-added.test.ts +157 -0
- package/src/feed/event-handlers/activity/handle-activity-reaction-added.ts +82 -40
- package/src/feed/event-handlers/activity/handle-activity-reaction-deleted.test.ts +200 -0
- package/src/feed/event-handlers/activity/handle-activity-reaction-deleted.ts +89 -51
- package/src/feed/event-handlers/activity/handle-activity-unpinned.test.ts +94 -0
- package/src/feed/event-handlers/activity/handle-activity-unpinned.ts +30 -0
- package/src/feed/event-handlers/activity/handle-activity-updated.test.ts +115 -0
- package/src/feed/event-handlers/activity/handle-activity-updated.ts +73 -35
- package/src/feed/event-handlers/bookmark/bookmark-utils.test.ts +121 -109
- package/src/feed/event-handlers/bookmark/handle-bookmark-added.test.ts +178 -0
- package/src/feed/event-handlers/bookmark/handle-bookmark-added.ts +82 -39
- package/src/feed/event-handlers/bookmark/handle-bookmark-deleted.test.ts +188 -0
- package/src/feed/event-handlers/bookmark/handle-bookmark-deleted.ts +86 -48
- package/src/feed/event-handlers/bookmark/handle-bookmark-updated.test.ts +196 -0
- package/src/feed/event-handlers/bookmark/handle-bookmark-updated.ts +83 -44
- package/src/feed/event-handlers/follow/handle-follow-created.test.ts +16 -12
- package/src/feed/event-handlers/follow/handle-follow-created.ts +4 -7
- package/src/feed/event-handlers/follow/handle-follow-deleted.test.ts +19 -15
- package/src/feed/event-handlers/follow/handle-follow-deleted.ts +6 -6
- package/src/feed/event-handlers/follow/handle-follow-updated.ts +7 -10
- package/src/feed/event-handlers/index.ts +2 -1
- package/src/feed/event-handlers/watch/handle-watch-started.ts +5 -0
- package/src/feed/event-handlers/watch/handle-watch-stopped.ts +5 -0
- package/src/feed/event-handlers/watch/index.ts +2 -0
- package/src/feed/feed.ts +15 -33
- package/src/feeds-client/event-handlers/index.ts +1 -0
- package/src/feeds-client/event-handlers/user/handle-user-updated.test.ts +53 -0
- package/src/feeds-client/event-handlers/user/handle-user-updated.ts +28 -0
- package/src/{feeds-client.ts → feeds-client/feeds-client.ts} +48 -39
- package/src/feeds-client/index.ts +2 -0
- package/src/gen/feeds/FeedsApi.ts +164 -138
- package/src/gen/model-decoders/decoders.ts +28 -0
- package/src/gen/models/index.ts +349 -29
- package/src/gen/moderation/ModerationApi.ts +1 -0
- package/src/test-utils/response-generators.ts +270 -11
- package/src/utils/index.ts +1 -0
- package/src/utils/state-update-queue.ts +1 -1
- package/src/utils/update-entity-in-array.ts +51 -0
|
@@ -8,53 +8,14 @@ import {
|
|
|
8
8
|
UserResponse,
|
|
9
9
|
} from '../../../gen/models';
|
|
10
10
|
import {
|
|
11
|
-
addBookmarkToActivity,
|
|
12
|
-
removeBookmarkFromActivity,
|
|
13
|
-
updateBookmarkInActivity,
|
|
14
11
|
addBookmarkToActivities,
|
|
15
12
|
removeBookmarkFromActivities,
|
|
16
13
|
updateBookmarkInActivities,
|
|
17
14
|
} from './';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
updated_at: new Date(),
|
|
23
|
-
banned: false,
|
|
24
|
-
language: 'en',
|
|
25
|
-
online: false,
|
|
26
|
-
role: 'user',
|
|
27
|
-
blocked_user_ids: [],
|
|
28
|
-
teams: [],
|
|
29
|
-
custom: {},
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const createMockActivity = (id: string): ActivityResponse => ({
|
|
33
|
-
id,
|
|
34
|
-
type: 'test',
|
|
35
|
-
created_at: new Date(),
|
|
36
|
-
updated_at: new Date(),
|
|
37
|
-
visibility: 'public',
|
|
38
|
-
bookmark_count: 0,
|
|
39
|
-
comment_count: 0,
|
|
40
|
-
reaction_count: 0,
|
|
41
|
-
share_count: 0,
|
|
42
|
-
attachments: [],
|
|
43
|
-
comments: [],
|
|
44
|
-
feeds: [],
|
|
45
|
-
filter_tags: [],
|
|
46
|
-
interest_tags: [],
|
|
47
|
-
latest_reactions: [],
|
|
48
|
-
mentioned_users: [],
|
|
49
|
-
own_bookmarks: [],
|
|
50
|
-
own_reactions: [],
|
|
51
|
-
custom: {},
|
|
52
|
-
reaction_groups: {},
|
|
53
|
-
search_data: {},
|
|
54
|
-
popularity: 0,
|
|
55
|
-
score: 0,
|
|
56
|
-
user: createMockUser('user1'),
|
|
57
|
-
});
|
|
15
|
+
import {
|
|
16
|
+
generateActivityResponse,
|
|
17
|
+
generateUserResponse,
|
|
18
|
+
} from '../../../test-utils';
|
|
58
19
|
|
|
59
20
|
const createMockBookmark = (
|
|
60
21
|
user: UserResponse,
|
|
@@ -94,11 +55,62 @@ const createMockUpdatedEvent = (
|
|
|
94
55
|
type: 'bookmark.updated',
|
|
95
56
|
});
|
|
96
57
|
|
|
58
|
+
const addBookmarkToActivity = (
|
|
59
|
+
event: BookmarkAddedEvent,
|
|
60
|
+
activity: ActivityResponse,
|
|
61
|
+
eventBelongsToCurrentUser: boolean,
|
|
62
|
+
) => {
|
|
63
|
+
const result = addBookmarkToActivities(
|
|
64
|
+
event,
|
|
65
|
+
[activity],
|
|
66
|
+
eventBelongsToCurrentUser,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
changed: result.changed,
|
|
71
|
+
...result.entities![0],
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const removeBookmarkFromActivity = (
|
|
76
|
+
event: BookmarkAddedEvent,
|
|
77
|
+
activity: ActivityResponse,
|
|
78
|
+
eventBelongsToCurrentUser: boolean,
|
|
79
|
+
) => {
|
|
80
|
+
const result = removeBookmarkFromActivities(
|
|
81
|
+
event,
|
|
82
|
+
[activity],
|
|
83
|
+
eventBelongsToCurrentUser,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
changed: result.changed,
|
|
88
|
+
...result.entities![0],
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const updateBookmarkInActivity = (
|
|
93
|
+
event: BookmarkAddedEvent,
|
|
94
|
+
activity: ActivityResponse,
|
|
95
|
+
eventBelongsToCurrentUser: boolean,
|
|
96
|
+
) => {
|
|
97
|
+
const result = updateBookmarkInActivities(
|
|
98
|
+
event,
|
|
99
|
+
[activity],
|
|
100
|
+
eventBelongsToCurrentUser,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
changed: result.changed,
|
|
105
|
+
...result.entities![0],
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
97
109
|
describe('bookmark-utils', () => {
|
|
98
110
|
describe('addBookmarkToActivity', () => {
|
|
99
111
|
it('should add bookmark to own_bookmarks when from current user', () => {
|
|
100
|
-
const activity =
|
|
101
|
-
const user =
|
|
112
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
113
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
102
114
|
const bookmark = createMockBookmark(user, activity);
|
|
103
115
|
const event = createMockAddedEvent(bookmark);
|
|
104
116
|
|
|
@@ -110,8 +122,8 @@ describe('bookmark-utils', () => {
|
|
|
110
122
|
});
|
|
111
123
|
|
|
112
124
|
it('should not add bookmark to own_bookmarks when not from current user', () => {
|
|
113
|
-
const activity =
|
|
114
|
-
const user =
|
|
125
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
126
|
+
const user = generateUserResponse({ id: 'user2' });
|
|
115
127
|
const bookmark = createMockBookmark(user, activity);
|
|
116
128
|
const event = createMockAddedEvent(bookmark);
|
|
117
129
|
|
|
@@ -122,8 +134,8 @@ describe('bookmark-utils', () => {
|
|
|
122
134
|
});
|
|
123
135
|
|
|
124
136
|
it('should handle existing bookmarks correctly', () => {
|
|
125
|
-
const activity =
|
|
126
|
-
const user =
|
|
137
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
138
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
127
139
|
const existingBookmark = createMockBookmark(user, activity);
|
|
128
140
|
activity.own_bookmarks = [existingBookmark];
|
|
129
141
|
|
|
@@ -141,8 +153,8 @@ describe('bookmark-utils', () => {
|
|
|
141
153
|
|
|
142
154
|
describe('removeBookmarkFromActivity', () => {
|
|
143
155
|
it('should remove bookmark from own_bookmarks when from current user', () => {
|
|
144
|
-
const activity =
|
|
145
|
-
const user =
|
|
156
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
157
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
146
158
|
const bookmark = createMockBookmark(user, activity);
|
|
147
159
|
activity.own_bookmarks = [bookmark];
|
|
148
160
|
|
|
@@ -154,8 +166,8 @@ describe('bookmark-utils', () => {
|
|
|
154
166
|
});
|
|
155
167
|
|
|
156
168
|
it('should not remove bookmark from own_bookmarks when not from current user', () => {
|
|
157
|
-
const activity =
|
|
158
|
-
const user =
|
|
169
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
170
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
159
171
|
const bookmark = createMockBookmark(user, activity);
|
|
160
172
|
activity.own_bookmarks = [bookmark];
|
|
161
173
|
|
|
@@ -168,9 +180,9 @@ describe('bookmark-utils', () => {
|
|
|
168
180
|
});
|
|
169
181
|
|
|
170
182
|
it('should remove correct bookmark when multiple bookmarks exist', () => {
|
|
171
|
-
const activity =
|
|
172
|
-
const user1 =
|
|
173
|
-
const user2 =
|
|
183
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
184
|
+
const user1 = generateUserResponse({ id: 'user1' });
|
|
185
|
+
const user2 = generateUserResponse({ id: 'user2' });
|
|
174
186
|
const bookmark1 = createMockBookmark(user1, activity);
|
|
175
187
|
const bookmark2 = createMockBookmark(user2, activity);
|
|
176
188
|
activity.own_bookmarks = [bookmark1, bookmark2];
|
|
@@ -184,8 +196,8 @@ describe('bookmark-utils', () => {
|
|
|
184
196
|
});
|
|
185
197
|
|
|
186
198
|
it('should correctly identify bookmarks by activity_id + folder_id + user_id', () => {
|
|
187
|
-
const activity =
|
|
188
|
-
const user =
|
|
199
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
200
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
189
201
|
|
|
190
202
|
// Create two bookmarks with same activity and user but different folders
|
|
191
203
|
const bookmark1 = {
|
|
@@ -221,8 +233,8 @@ describe('bookmark-utils', () => {
|
|
|
221
233
|
});
|
|
222
234
|
|
|
223
235
|
it('should handle bookmarks without folders correctly', () => {
|
|
224
|
-
const activity =
|
|
225
|
-
const user =
|
|
236
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
237
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
226
238
|
|
|
227
239
|
// Create two bookmarks: one with folder, one without
|
|
228
240
|
const bookmarkWithFolder = {
|
|
@@ -251,8 +263,8 @@ describe('bookmark-utils', () => {
|
|
|
251
263
|
|
|
252
264
|
describe('updateBookmarkInActivity', () => {
|
|
253
265
|
it('should update bookmark in own_bookmarks when from current user', () => {
|
|
254
|
-
const activity =
|
|
255
|
-
const user =
|
|
266
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
267
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
256
268
|
const bookmark = createMockBookmark(user, activity);
|
|
257
269
|
activity.own_bookmarks = [bookmark];
|
|
258
270
|
|
|
@@ -269,8 +281,8 @@ describe('bookmark-utils', () => {
|
|
|
269
281
|
});
|
|
270
282
|
|
|
271
283
|
it('should not update bookmark in own_bookmarks when not from current user', () => {
|
|
272
|
-
const activity =
|
|
273
|
-
const user =
|
|
284
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
285
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
274
286
|
const bookmark = createMockBookmark(user, activity);
|
|
275
287
|
activity.own_bookmarks = [bookmark];
|
|
276
288
|
|
|
@@ -288,8 +300,8 @@ describe('bookmark-utils', () => {
|
|
|
288
300
|
|
|
289
301
|
// Test for the bug: updating bookmarks with same activity_id but different folder_id
|
|
290
302
|
it('should correctly update bookmark by activity_id + folder_id + user_id', () => {
|
|
291
|
-
const activity =
|
|
292
|
-
const user =
|
|
303
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
304
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
293
305
|
|
|
294
306
|
// Create two bookmarks with same activity and user but different folders
|
|
295
307
|
const bookmark1 = {
|
|
@@ -330,8 +342,8 @@ describe('bookmark-utils', () => {
|
|
|
330
342
|
});
|
|
331
343
|
|
|
332
344
|
it('should handle updating bookmarks without folders correctly', () => {
|
|
333
|
-
const activity =
|
|
334
|
-
const user =
|
|
345
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
346
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
335
347
|
|
|
336
348
|
// Create two bookmarks: one with folder, one without
|
|
337
349
|
const bookmarkWithFolder = {
|
|
@@ -365,56 +377,56 @@ describe('bookmark-utils', () => {
|
|
|
365
377
|
|
|
366
378
|
describe('addBookmarkToActivities', () => {
|
|
367
379
|
it('should add bookmark to correct activity', () => {
|
|
368
|
-
const activity1 =
|
|
369
|
-
const activity2 =
|
|
380
|
+
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
381
|
+
const activity2 = generateActivityResponse({ id: 'activity2' });
|
|
370
382
|
const activities = [activity1, activity2];
|
|
371
383
|
|
|
372
|
-
const user =
|
|
384
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
373
385
|
const bookmark = createMockBookmark(user, activity1);
|
|
374
386
|
const event = createMockAddedEvent(bookmark);
|
|
375
387
|
|
|
376
388
|
const result = addBookmarkToActivities(event, activities, true);
|
|
377
389
|
|
|
378
390
|
expect(result.changed).toBe(true);
|
|
379
|
-
expect(result.
|
|
380
|
-
expect(result.
|
|
381
|
-
expect(result.
|
|
382
|
-
expect(result.
|
|
391
|
+
expect(result.entities).toHaveLength(2);
|
|
392
|
+
expect(result.entities![0].own_bookmarks).toHaveLength(1);
|
|
393
|
+
expect(result.entities![0].own_bookmarks[0]).toEqual(bookmark);
|
|
394
|
+
expect(result.entities![1].own_bookmarks).toHaveLength(0);
|
|
383
395
|
});
|
|
384
396
|
|
|
385
397
|
it('should return unchanged when activity not found', () => {
|
|
386
|
-
const activity1 =
|
|
398
|
+
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
387
399
|
const activities = [activity1];
|
|
388
400
|
|
|
389
|
-
const user =
|
|
390
|
-
const differentActivity =
|
|
401
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
402
|
+
const differentActivity = generateActivityResponse({ id: 'activity2' });
|
|
391
403
|
const bookmark = createMockBookmark(user, differentActivity);
|
|
392
404
|
const event = createMockAddedEvent(bookmark);
|
|
393
405
|
|
|
394
406
|
const result = addBookmarkToActivities(event, activities, true);
|
|
395
407
|
|
|
396
408
|
expect(result.changed).toBe(false);
|
|
397
|
-
expect(result.
|
|
409
|
+
expect(result.entities).toEqual(activities);
|
|
398
410
|
});
|
|
399
411
|
|
|
400
412
|
it('should handle undefined activities', () => {
|
|
401
|
-
const user =
|
|
402
|
-
const activity =
|
|
413
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
414
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
403
415
|
const bookmark = createMockBookmark(user, activity);
|
|
404
416
|
const event = createMockAddedEvent(bookmark);
|
|
405
417
|
|
|
406
418
|
const result = addBookmarkToActivities(event, undefined, true);
|
|
407
419
|
|
|
408
420
|
expect(result.changed).toBe(false);
|
|
409
|
-
expect(result.
|
|
421
|
+
expect(result.entities).toBeUndefined();
|
|
410
422
|
});
|
|
411
423
|
});
|
|
412
424
|
|
|
413
425
|
describe('removeBookmarkFromActivities', () => {
|
|
414
426
|
it('should remove bookmark from correct activity', () => {
|
|
415
|
-
const activity1 =
|
|
416
|
-
const activity2 =
|
|
417
|
-
const user =
|
|
427
|
+
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
428
|
+
const activity2 = generateActivityResponse({ id: 'activity2' });
|
|
429
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
418
430
|
const bookmark = createMockBookmark(user, activity1);
|
|
419
431
|
activity1.own_bookmarks = [bookmark];
|
|
420
432
|
const activities = [activity1, activity2];
|
|
@@ -423,44 +435,44 @@ describe('bookmark-utils', () => {
|
|
|
423
435
|
const result = removeBookmarkFromActivities(event, activities, true);
|
|
424
436
|
|
|
425
437
|
expect(result.changed).toBe(true);
|
|
426
|
-
expect(result.
|
|
427
|
-
expect(result.
|
|
428
|
-
expect(result.
|
|
438
|
+
expect(result.entities).toHaveLength(2);
|
|
439
|
+
expect(result.entities![0].own_bookmarks).toHaveLength(0);
|
|
440
|
+
expect(result.entities![1].own_bookmarks).toHaveLength(0);
|
|
429
441
|
});
|
|
430
442
|
|
|
431
443
|
it('should return unchanged when activity not found', () => {
|
|
432
|
-
const activity1 =
|
|
444
|
+
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
433
445
|
const activities = [activity1];
|
|
434
446
|
|
|
435
|
-
const user =
|
|
436
|
-
const differentActivity =
|
|
447
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
448
|
+
const differentActivity = generateActivityResponse({ id: 'activity2' });
|
|
437
449
|
const bookmark = createMockBookmark(user, differentActivity);
|
|
438
450
|
const event = createMockDeletedEvent(bookmark);
|
|
439
451
|
|
|
440
452
|
const result = removeBookmarkFromActivities(event, activities, true);
|
|
441
453
|
|
|
442
454
|
expect(result.changed).toBe(false);
|
|
443
|
-
expect(result.
|
|
455
|
+
expect(result.entities).toEqual(activities);
|
|
444
456
|
});
|
|
445
457
|
|
|
446
458
|
it('should handle undefined activities', () => {
|
|
447
|
-
const user =
|
|
448
|
-
const activity =
|
|
459
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
460
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
449
461
|
const bookmark = createMockBookmark(user, activity);
|
|
450
462
|
const event = createMockDeletedEvent(bookmark);
|
|
451
463
|
|
|
452
464
|
const result = removeBookmarkFromActivities(event, undefined, true);
|
|
453
465
|
|
|
454
466
|
expect(result.changed).toBe(false);
|
|
455
|
-
expect(result.
|
|
467
|
+
expect(result.entities).toBeUndefined();
|
|
456
468
|
});
|
|
457
469
|
});
|
|
458
470
|
|
|
459
471
|
describe('updateBookmarkInActivities', () => {
|
|
460
472
|
it('should update bookmark in correct activity', () => {
|
|
461
|
-
const activity1 =
|
|
462
|
-
const activity2 =
|
|
463
|
-
const user =
|
|
473
|
+
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
474
|
+
const activity2 = generateActivityResponse({ id: 'activity2' });
|
|
475
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
464
476
|
const bookmark = createMockBookmark(user, activity1);
|
|
465
477
|
activity1.own_bookmarks = [bookmark];
|
|
466
478
|
const activities = [activity1, activity2];
|
|
@@ -473,37 +485,37 @@ describe('bookmark-utils', () => {
|
|
|
473
485
|
const result = updateBookmarkInActivities(event, activities, true);
|
|
474
486
|
|
|
475
487
|
expect(result.changed).toBe(true);
|
|
476
|
-
expect(result.
|
|
477
|
-
expect(result.
|
|
478
|
-
expect(result.
|
|
479
|
-
expect(result.
|
|
488
|
+
expect(result.entities).toHaveLength(2);
|
|
489
|
+
expect(result.entities![0].own_bookmarks).toHaveLength(1);
|
|
490
|
+
expect(result.entities![0].own_bookmarks[0]).toEqual(updatedBookmark);
|
|
491
|
+
expect(result.entities![1].own_bookmarks).toHaveLength(0);
|
|
480
492
|
});
|
|
481
493
|
|
|
482
494
|
it('should return unchanged when activity not found', () => {
|
|
483
|
-
const activity1 =
|
|
495
|
+
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
484
496
|
const activities = [activity1];
|
|
485
497
|
|
|
486
|
-
const user =
|
|
487
|
-
const differentActivity =
|
|
498
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
499
|
+
const differentActivity = generateActivityResponse({ id: 'activity2' });
|
|
488
500
|
const bookmark = createMockBookmark(user, differentActivity);
|
|
489
501
|
const event = createMockUpdatedEvent(bookmark);
|
|
490
502
|
|
|
491
503
|
const result = updateBookmarkInActivities(event, activities, true);
|
|
492
504
|
|
|
493
505
|
expect(result.changed).toBe(false);
|
|
494
|
-
expect(result.
|
|
506
|
+
expect(result.entities).toEqual(activities);
|
|
495
507
|
});
|
|
496
508
|
|
|
497
509
|
it('should handle undefined activities', () => {
|
|
498
|
-
const user =
|
|
499
|
-
const activity =
|
|
510
|
+
const user = generateUserResponse({ id: 'user1' });
|
|
511
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
500
512
|
const bookmark = createMockBookmark(user, activity);
|
|
501
513
|
const event = createMockUpdatedEvent(bookmark);
|
|
502
514
|
|
|
503
515
|
const result = updateBookmarkInActivities(event, undefined, true);
|
|
504
516
|
|
|
505
517
|
expect(result.changed).toBe(false);
|
|
506
|
-
expect(result.
|
|
518
|
+
expect(result.entities).toBeUndefined();
|
|
507
519
|
});
|
|
508
520
|
});
|
|
509
521
|
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { Feed } from '../../../feed';
|
|
3
|
+
import { FeedsClient } from '../../../feeds-client';
|
|
4
|
+
import { handleBookmarkAdded } from './handle-bookmark-added';
|
|
5
|
+
import {
|
|
6
|
+
generateActivityPinResponse,
|
|
7
|
+
generateActivityResponse,
|
|
8
|
+
generateFeedResponse,
|
|
9
|
+
generateOwnUser,
|
|
10
|
+
getHumanId,
|
|
11
|
+
generateFeedReactionResponse,
|
|
12
|
+
generateBookmarkAddedEvent,
|
|
13
|
+
} from '../../../test-utils/response-generators';
|
|
14
|
+
|
|
15
|
+
describe(handleBookmarkAdded.name, () => {
|
|
16
|
+
let feed: Feed;
|
|
17
|
+
let client: FeedsClient;
|
|
18
|
+
let currentUserId: string;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
client = new FeedsClient('mock-api-key');
|
|
22
|
+
currentUserId = getHumanId();
|
|
23
|
+
client.state.partialNext({
|
|
24
|
+
connected_user: generateOwnUser({ id: currentUserId }),
|
|
25
|
+
});
|
|
26
|
+
const feedResponse = generateFeedResponse({
|
|
27
|
+
id: 'main',
|
|
28
|
+
group_id: 'user',
|
|
29
|
+
created_by: { id: currentUserId },
|
|
30
|
+
});
|
|
31
|
+
feed = new Feed(
|
|
32
|
+
client,
|
|
33
|
+
feedResponse.group_id,
|
|
34
|
+
feedResponse.id,
|
|
35
|
+
feedResponse,
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('adds a bookmark for the current user and updates activities', () => {
|
|
40
|
+
const event = generateBookmarkAddedEvent({
|
|
41
|
+
bookmark: {
|
|
42
|
+
activity: {
|
|
43
|
+
own_reactions: [],
|
|
44
|
+
bookmark_count: 1,
|
|
45
|
+
},
|
|
46
|
+
user: { id: currentUserId },
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const activity = generateActivityResponse({
|
|
50
|
+
id: event.bookmark.activity.id,
|
|
51
|
+
bookmark_count: 0,
|
|
52
|
+
own_bookmarks: [],
|
|
53
|
+
own_reactions: [generateFeedReactionResponse()],
|
|
54
|
+
});
|
|
55
|
+
const activityPin = generateActivityPinResponse({
|
|
56
|
+
activity: { ...activity },
|
|
57
|
+
});
|
|
58
|
+
feed.state.partialNext({
|
|
59
|
+
activities: [activity],
|
|
60
|
+
pinned_activities: [activityPin],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const stateBefore = feed.currentState;
|
|
64
|
+
expect(stateBefore.activities![0].own_bookmarks).toHaveLength(0);
|
|
65
|
+
expect(
|
|
66
|
+
stateBefore.pinned_activities![0].activity.own_bookmarks,
|
|
67
|
+
).toHaveLength(0);
|
|
68
|
+
expect(stateBefore.activities![0].bookmark_count).toEqual(0);
|
|
69
|
+
expect(stateBefore.pinned_activities![0].activity.bookmark_count).toEqual(
|
|
70
|
+
0,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
handleBookmarkAdded.call(feed, event);
|
|
74
|
+
|
|
75
|
+
const stateAfter = feed.currentState;
|
|
76
|
+
expect(stateAfter.activities![0].own_bookmarks).toHaveLength(1);
|
|
77
|
+
expect(
|
|
78
|
+
stateAfter.pinned_activities![0].activity.own_bookmarks,
|
|
79
|
+
).toHaveLength(1);
|
|
80
|
+
expect(stateAfter.activities![0].own_bookmarks).toContain(event.bookmark);
|
|
81
|
+
expect(stateAfter.pinned_activities![0].activity.own_bookmarks).toContain(
|
|
82
|
+
event.bookmark,
|
|
83
|
+
);
|
|
84
|
+
expect(stateAfter.activities![0].own_reactions).toEqual(
|
|
85
|
+
stateBefore.activities![0].own_reactions,
|
|
86
|
+
);
|
|
87
|
+
expect(stateAfter.pinned_activities![0].activity.own_reactions).toEqual(
|
|
88
|
+
stateBefore.pinned_activities![0].activity.own_reactions,
|
|
89
|
+
);
|
|
90
|
+
expect(stateAfter.activities![0].bookmark_count).toEqual(1);
|
|
91
|
+
expect(stateAfter.pinned_activities![0].activity.bookmark_count).toEqual(1);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('does not add to own_bookmarks if bookmark is from another user but still updates activity', () => {
|
|
95
|
+
const event = generateBookmarkAddedEvent({
|
|
96
|
+
bookmark: {
|
|
97
|
+
activity: {
|
|
98
|
+
own_reactions: [],
|
|
99
|
+
bookmark_count: 1,
|
|
100
|
+
},
|
|
101
|
+
user: { id: 'other-user-id' },
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
const activity = generateActivityResponse({
|
|
105
|
+
id: event.bookmark.activity.id,
|
|
106
|
+
bookmark_count: 0,
|
|
107
|
+
own_bookmarks: [],
|
|
108
|
+
own_reactions: [generateFeedReactionResponse()],
|
|
109
|
+
});
|
|
110
|
+
const activityPin = generateActivityPinResponse({
|
|
111
|
+
activity: { ...activity },
|
|
112
|
+
});
|
|
113
|
+
feed.state.partialNext({
|
|
114
|
+
activities: [activity],
|
|
115
|
+
pinned_activities: [activityPin],
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const stateBefore = feed.currentState;
|
|
119
|
+
expect(stateBefore.activities![0].own_bookmarks).toHaveLength(0);
|
|
120
|
+
expect(
|
|
121
|
+
stateBefore.pinned_activities![0].activity.own_bookmarks,
|
|
122
|
+
).toHaveLength(0);
|
|
123
|
+
expect(stateBefore.activities![0].bookmark_count).toEqual(0);
|
|
124
|
+
expect(stateBefore.pinned_activities![0].activity.bookmark_count).toEqual(
|
|
125
|
+
0,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
handleBookmarkAdded.call(feed, event);
|
|
129
|
+
|
|
130
|
+
const stateAfter = feed.currentState;
|
|
131
|
+
expect(stateAfter.activities![0].own_bookmarks).toEqual(
|
|
132
|
+
stateBefore.activities![0].own_bookmarks,
|
|
133
|
+
);
|
|
134
|
+
expect(stateAfter.pinned_activities![0].activity.own_bookmarks).toEqual(
|
|
135
|
+
stateBefore.pinned_activities![0].activity.own_bookmarks,
|
|
136
|
+
);
|
|
137
|
+
expect(stateAfter.activities![0].own_reactions).toEqual(
|
|
138
|
+
stateBefore.activities![0].own_reactions,
|
|
139
|
+
);
|
|
140
|
+
expect(stateAfter.pinned_activities![0].activity.own_reactions).toEqual(
|
|
141
|
+
stateBefore.pinned_activities![0].activity.own_reactions,
|
|
142
|
+
);
|
|
143
|
+
expect(stateAfter.activities![0].bookmark_count).toEqual(1);
|
|
144
|
+
expect(stateAfter.pinned_activities![0].activity.bookmark_count).toEqual(1);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('does nothing if activity is not found', () => {
|
|
148
|
+
const event = generateBookmarkAddedEvent({
|
|
149
|
+
bookmark: {
|
|
150
|
+
activity: {
|
|
151
|
+
own_reactions: [],
|
|
152
|
+
bookmark_count: 1,
|
|
153
|
+
},
|
|
154
|
+
user: { id: 'other-user-id' },
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
const activity = generateActivityResponse({
|
|
158
|
+
id: 'unrelated-activity-id',
|
|
159
|
+
bookmark_count: 0,
|
|
160
|
+
own_bookmarks: [],
|
|
161
|
+
own_reactions: [generateFeedReactionResponse()],
|
|
162
|
+
});
|
|
163
|
+
const activityPin = generateActivityPinResponse({
|
|
164
|
+
activity: { ...activity },
|
|
165
|
+
});
|
|
166
|
+
feed.state.partialNext({
|
|
167
|
+
activities: [activity],
|
|
168
|
+
pinned_activities: [activityPin],
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const stateBefore = feed.currentState;
|
|
172
|
+
|
|
173
|
+
handleBookmarkAdded.call(feed, event);
|
|
174
|
+
|
|
175
|
+
const stateAfter = feed.currentState;
|
|
176
|
+
expect(stateAfter).toBe(stateBefore);
|
|
177
|
+
});
|
|
178
|
+
});
|