@stream-io/feeds-client 0.2.18 → 0.2.19
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 +16 -0
- package/dist/cjs/index.js +94 -25
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react-bindings.js +26 -55
- package/dist/cjs/react-bindings.js.map +1 -1
- package/dist/es/index.mjs +86 -17
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/react-bindings.mjs +19 -48
- package/dist/es/react-bindings.mjs.map +1 -1
- package/dist/{index--koeDtxd.js → feeds-client-C09giTf1.js} +177 -79
- package/dist/feeds-client-C09giTf1.js.map +1 -0
- package/dist/{index-Zde8UE5f.mjs → feeds-client-CFadXO-B.mjs} +190 -92
- package/dist/feeds-client-CFadXO-B.mjs.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts +2 -32
- package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts.map +1 -1
- package/dist/types/common/real-time/event-models.d.ts +7 -2
- package/dist/types/common/real-time/event-models.d.ts.map +1 -1
- package/dist/types/common/types.d.ts +1 -0
- package/dist/types/common/types.d.ts.map +1 -1
- package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts.map +1 -1
- package/dist/types/feed/event-handlers/activity/handle-activity-updated.d.ts.map +1 -1
- package/dist/types/feed/feed.d.ts +1 -1
- package/dist/types/feed/feed.d.ts.map +1 -1
- package/dist/types/feeds-client/feeds-client.d.ts +9 -1
- package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
- package/dist/types/utils/throttling/index.d.ts +3 -0
- package/dist/types/utils/throttling/index.d.ts.map +1 -0
- package/dist/types/utils/throttling/throttle.d.ts +34 -0
- package/dist/types/utils/throttling/throttle.d.ts.map +1 -0
- package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts +14 -0
- package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts.map +1 -0
- package/package.json +7 -3
- package/react-bindings.d.ts +11 -0
- package/react-bindings.js +7 -0
- package/react-bindings.mjs +11 -0
- package/src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts +21 -73
- package/src/common/real-time/event-models.ts +8 -2
- package/src/common/types.ts +1 -0
- package/src/feed/event-handlers/activity/handle-activity-added.ts +9 -1
- package/src/feed/event-handlers/activity/handle-activity-updated.ts +4 -0
- package/src/feed/feed.ts +18 -3
- package/src/feeds-client/feeds-client.ts +106 -3
- package/src/utils/throttling/index.ts +2 -0
- package/src/utils/throttling/throttle.ts +123 -0
- package/src/utils/throttling/throttled-get-batched-own-capabilities.ts +42 -0
- package/dist/index--koeDtxd.js.map +0 -1
- package/dist/index-Zde8UE5f.mjs.map +0 -1
- package/src/feed/event-handlers/activity/activity-marked-utils.test.ts +0 -208
- package/src/feed/event-handlers/activity/activity-reaction-utils.test.ts +0 -371
- package/src/feed/event-handlers/activity/handle-activity-added.test.ts +0 -97
- package/src/feed/event-handlers/activity/handle-activity-deleted.test.ts +0 -117
- package/src/feed/event-handlers/activity/handle-activity-pinned.test.ts +0 -60
- package/src/feed/event-handlers/activity/handle-activity-reaction-added.test.ts +0 -257
- package/src/feed/event-handlers/activity/handle-activity-reaction-deleted.test.ts +0 -317
- package/src/feed/event-handlers/activity/handle-activity-reaction-updated.test.ts +0 -282
- package/src/feed/event-handlers/activity/handle-activity-unpinned.test.ts +0 -95
- package/src/feed/event-handlers/activity/handle-activity-updated.test.ts +0 -245
- package/src/feed/event-handlers/add-aggregated-activities-to-state.test.ts +0 -510
- package/src/feed/event-handlers/bookmark/bookmark-utils.test.ts +0 -521
- package/src/feed/event-handlers/bookmark/handle-bookmark-added.test.ts +0 -178
- package/src/feed/event-handlers/bookmark/handle-bookmark-deleted.test.ts +0 -188
- package/src/feed/event-handlers/bookmark/handle-bookmark-updated.test.ts +0 -196
- package/src/feed/event-handlers/comment/handle-comment-added.test.ts +0 -271
- package/src/feed/event-handlers/comment/handle-comment-deleted.test.ts +0 -255
- package/src/feed/event-handlers/comment/handle-comment-reaction-added.test.ts +0 -329
- package/src/feed/event-handlers/comment/handle-comment-reaction-deleted.test.ts +0 -343
- package/src/feed/event-handlers/comment/handle-comment-reaction-updated.test.ts +0 -350
- package/src/feed/event-handlers/comment/handle-comment-updated.test.ts +0 -267
- package/src/feed/event-handlers/comment/utils/update-comment-count.test.ts +0 -322
- package/src/feed/event-handlers/feed-member/handle-feed-member-added.test.ts +0 -75
- package/src/feed/event-handlers/feed-member/handle-feed-member-removed.test.ts +0 -82
- package/src/feed/event-handlers/feed-member/handle-feed-member-updated.test.ts +0 -84
- package/src/feed/event-handlers/follow/follow-state-update-queue.test.ts +0 -219
- package/src/feed/event-handlers/follow/handle-follow-created.test.ts +0 -250
- package/src/feed/event-handlers/follow/handle-follow-deleted.test.ts +0 -268
- package/src/feed/event-handlers/follow/handle-follow-updated.test.ts +0 -131
- package/src/feed/event-handlers/notification-feed/handle-notification-feed-updated.test.ts +0 -182
- package/src/feed/event-handlers/story-feeds/handle-story-feeds-updated.test.ts +0 -45
- package/src/feed/feed.test.ts +0 -90
- package/src/feeds-client/event-handlers/user/handle-user-updated.test.ts +0 -53
- package/src/utils/event-triggered-by-connected-user.test.ts +0 -73
- package/src/utils/state-update-queue.test.ts +0 -129
- package/src/utils/unique-array-merge.test.ts +0 -179
|
@@ -1,521 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import type {
|
|
3
|
-
BookmarkAddedEvent,
|
|
4
|
-
BookmarkDeletedEvent,
|
|
5
|
-
BookmarkUpdatedEvent,
|
|
6
|
-
ActivityResponse,
|
|
7
|
-
BookmarkResponse,
|
|
8
|
-
UserResponse,
|
|
9
|
-
} from '../../../gen/models';
|
|
10
|
-
import {
|
|
11
|
-
addBookmarkToActivities,
|
|
12
|
-
removeBookmarkFromActivities,
|
|
13
|
-
updateBookmarkInActivities,
|
|
14
|
-
} from './';
|
|
15
|
-
import {
|
|
16
|
-
generateActivityResponse,
|
|
17
|
-
generateUserResponse,
|
|
18
|
-
} from '../../../test-utils';
|
|
19
|
-
|
|
20
|
-
const createMockBookmark = (
|
|
21
|
-
user: UserResponse,
|
|
22
|
-
activity: ActivityResponse,
|
|
23
|
-
): BookmarkResponse => ({
|
|
24
|
-
created_at: new Date(),
|
|
25
|
-
updated_at: new Date(),
|
|
26
|
-
activity,
|
|
27
|
-
user,
|
|
28
|
-
custom: {},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const createMockAddedEvent = (
|
|
32
|
-
bookmark: BookmarkResponse,
|
|
33
|
-
): BookmarkAddedEvent => ({
|
|
34
|
-
bookmark,
|
|
35
|
-
created_at: new Date(),
|
|
36
|
-
custom: {},
|
|
37
|
-
type: 'bookmark.added',
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const createMockDeletedEvent = (
|
|
41
|
-
bookmark: BookmarkResponse,
|
|
42
|
-
): BookmarkDeletedEvent => ({
|
|
43
|
-
bookmark,
|
|
44
|
-
created_at: new Date(),
|
|
45
|
-
custom: {},
|
|
46
|
-
type: 'bookmark.deleted',
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const createMockUpdatedEvent = (
|
|
50
|
-
bookmark: BookmarkResponse,
|
|
51
|
-
): BookmarkUpdatedEvent => ({
|
|
52
|
-
bookmark,
|
|
53
|
-
created_at: new Date(),
|
|
54
|
-
custom: {},
|
|
55
|
-
type: 'bookmark.updated',
|
|
56
|
-
});
|
|
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
|
-
|
|
109
|
-
describe('bookmark-utils', () => {
|
|
110
|
-
describe('addBookmarkToActivity', () => {
|
|
111
|
-
it('should add bookmark to own_bookmarks when from current user', () => {
|
|
112
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
113
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
114
|
-
const bookmark = createMockBookmark(user, activity);
|
|
115
|
-
const event = createMockAddedEvent(bookmark);
|
|
116
|
-
|
|
117
|
-
const result = addBookmarkToActivity(event, activity, true);
|
|
118
|
-
|
|
119
|
-
expect(result.changed).toBe(true);
|
|
120
|
-
expect(result.own_bookmarks).toHaveLength(1);
|
|
121
|
-
expect(result.own_bookmarks[0]).toEqual(bookmark);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should not add bookmark to own_bookmarks when not from current user', () => {
|
|
125
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
126
|
-
const user = generateUserResponse({ id: 'user2' });
|
|
127
|
-
const bookmark = createMockBookmark(user, activity);
|
|
128
|
-
const event = createMockAddedEvent(bookmark);
|
|
129
|
-
|
|
130
|
-
const result = addBookmarkToActivity(event, activity, false);
|
|
131
|
-
|
|
132
|
-
expect(result.changed).toBe(true);
|
|
133
|
-
expect(result.own_bookmarks).toHaveLength(0);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('should handle existing bookmarks correctly', () => {
|
|
137
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
138
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
139
|
-
const existingBookmark = createMockBookmark(user, activity);
|
|
140
|
-
activity.own_bookmarks = [existingBookmark];
|
|
141
|
-
|
|
142
|
-
const newBookmark = createMockBookmark(user, activity);
|
|
143
|
-
const event = createMockAddedEvent(newBookmark);
|
|
144
|
-
|
|
145
|
-
const result = addBookmarkToActivity(event, activity, true);
|
|
146
|
-
|
|
147
|
-
expect(result.changed).toBe(true);
|
|
148
|
-
expect(result.own_bookmarks).toHaveLength(2);
|
|
149
|
-
expect(result.own_bookmarks).toContain(existingBookmark);
|
|
150
|
-
expect(result.own_bookmarks).toContain(newBookmark);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe('removeBookmarkFromActivity', () => {
|
|
155
|
-
it('should remove bookmark from own_bookmarks when from current user', () => {
|
|
156
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
157
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
158
|
-
const bookmark = createMockBookmark(user, activity);
|
|
159
|
-
activity.own_bookmarks = [bookmark];
|
|
160
|
-
|
|
161
|
-
const event = createMockDeletedEvent(bookmark);
|
|
162
|
-
const result = removeBookmarkFromActivity(event, activity, true);
|
|
163
|
-
|
|
164
|
-
expect(result.changed).toBe(true);
|
|
165
|
-
expect(result.own_bookmarks).toHaveLength(0);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('should not remove bookmark from own_bookmarks when not from current user', () => {
|
|
169
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
170
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
171
|
-
const bookmark = createMockBookmark(user, activity);
|
|
172
|
-
activity.own_bookmarks = [bookmark];
|
|
173
|
-
|
|
174
|
-
const event = createMockDeletedEvent(bookmark);
|
|
175
|
-
const result = removeBookmarkFromActivity(event, activity, false);
|
|
176
|
-
|
|
177
|
-
expect(result.changed).toBe(true);
|
|
178
|
-
expect(result.own_bookmarks).toHaveLength(1);
|
|
179
|
-
expect(result.own_bookmarks[0]).toEqual(bookmark);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('should remove correct bookmark when multiple bookmarks exist', () => {
|
|
183
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
184
|
-
const user1 = generateUserResponse({ id: 'user1' });
|
|
185
|
-
const user2 = generateUserResponse({ id: 'user2' });
|
|
186
|
-
const bookmark1 = createMockBookmark(user1, activity);
|
|
187
|
-
const bookmark2 = createMockBookmark(user2, activity);
|
|
188
|
-
activity.own_bookmarks = [bookmark1, bookmark2];
|
|
189
|
-
|
|
190
|
-
const event = createMockDeletedEvent(bookmark1);
|
|
191
|
-
const result = removeBookmarkFromActivity(event, activity, true);
|
|
192
|
-
|
|
193
|
-
expect(result.changed).toBe(true);
|
|
194
|
-
expect(result.own_bookmarks).toHaveLength(1);
|
|
195
|
-
expect(result.own_bookmarks[0]).toEqual(bookmark2);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('should correctly identify bookmarks by activity_id + folder_id + user_id', () => {
|
|
199
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
200
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
201
|
-
|
|
202
|
-
// Create two bookmarks with same activity and user but different folders
|
|
203
|
-
const bookmark1 = {
|
|
204
|
-
...createMockBookmark(user, activity),
|
|
205
|
-
folder: {
|
|
206
|
-
id: 'folder1',
|
|
207
|
-
name: 'Folder 1',
|
|
208
|
-
created_at: new Date(),
|
|
209
|
-
updated_at: new Date(),
|
|
210
|
-
custom: {},
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
const bookmark2 = {
|
|
214
|
-
...createMockBookmark(user, activity),
|
|
215
|
-
folder: {
|
|
216
|
-
id: 'folder2',
|
|
217
|
-
name: 'Folder 2',
|
|
218
|
-
created_at: new Date(),
|
|
219
|
-
updated_at: new Date(),
|
|
220
|
-
custom: {},
|
|
221
|
-
},
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
activity.own_bookmarks = [bookmark1, bookmark2];
|
|
225
|
-
|
|
226
|
-
// Try to remove bookmark1
|
|
227
|
-
const event = createMockDeletedEvent(bookmark1);
|
|
228
|
-
const result = removeBookmarkFromActivity(event, activity, true);
|
|
229
|
-
|
|
230
|
-
expect(result.changed).toBe(true);
|
|
231
|
-
expect(result.own_bookmarks).toHaveLength(1);
|
|
232
|
-
expect(result.own_bookmarks[0]).toEqual(bookmark2);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it('should handle bookmarks without folders correctly', () => {
|
|
236
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
237
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
238
|
-
|
|
239
|
-
// Create two bookmarks: one with folder, one without
|
|
240
|
-
const bookmarkWithFolder = {
|
|
241
|
-
...createMockBookmark(user, activity),
|
|
242
|
-
folder: {
|
|
243
|
-
id: 'folder1',
|
|
244
|
-
name: 'Folder 1',
|
|
245
|
-
created_at: new Date(),
|
|
246
|
-
updated_at: new Date(),
|
|
247
|
-
custom: {},
|
|
248
|
-
},
|
|
249
|
-
};
|
|
250
|
-
const bookmarkWithoutFolder = createMockBookmark(user, activity);
|
|
251
|
-
|
|
252
|
-
activity.own_bookmarks = [bookmarkWithFolder, bookmarkWithoutFolder];
|
|
253
|
-
|
|
254
|
-
// Try to remove bookmark without folder
|
|
255
|
-
const event = createMockDeletedEvent(bookmarkWithoutFolder);
|
|
256
|
-
const result = removeBookmarkFromActivity(event, activity, true);
|
|
257
|
-
|
|
258
|
-
expect(result.changed).toBe(true);
|
|
259
|
-
expect(result.own_bookmarks).toHaveLength(1);
|
|
260
|
-
expect(result.own_bookmarks[0]).toEqual(bookmarkWithFolder);
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
describe('updateBookmarkInActivity', () => {
|
|
265
|
-
it('should update bookmark in own_bookmarks when from current user', () => {
|
|
266
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
267
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
268
|
-
const bookmark = createMockBookmark(user, activity);
|
|
269
|
-
activity.own_bookmarks = [bookmark];
|
|
270
|
-
|
|
271
|
-
const updatedBookmark = {
|
|
272
|
-
...bookmark,
|
|
273
|
-
custom: { updated: true },
|
|
274
|
-
};
|
|
275
|
-
const event = createMockUpdatedEvent(updatedBookmark);
|
|
276
|
-
const result = updateBookmarkInActivity(event, activity, true);
|
|
277
|
-
|
|
278
|
-
expect(result.changed).toBe(true);
|
|
279
|
-
expect(result.own_bookmarks).toHaveLength(1);
|
|
280
|
-
expect(result.own_bookmarks[0]).toEqual(updatedBookmark);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it('should not update bookmark in own_bookmarks when not from current user', () => {
|
|
284
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
285
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
286
|
-
const bookmark = createMockBookmark(user, activity);
|
|
287
|
-
activity.own_bookmarks = [bookmark];
|
|
288
|
-
|
|
289
|
-
const updatedBookmark = {
|
|
290
|
-
...bookmark,
|
|
291
|
-
custom: { updated: true },
|
|
292
|
-
};
|
|
293
|
-
const event = createMockUpdatedEvent(updatedBookmark);
|
|
294
|
-
const result = updateBookmarkInActivity(event, activity, false);
|
|
295
|
-
|
|
296
|
-
expect(result.changed).toBe(true);
|
|
297
|
-
expect(result.own_bookmarks).toHaveLength(1);
|
|
298
|
-
expect(result.own_bookmarks[0]).toEqual(bookmark); // unchanged
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
// Test for the bug: updating bookmarks with same activity_id but different folder_id
|
|
302
|
-
it('should correctly update bookmark by activity_id + folder_id + user_id', () => {
|
|
303
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
304
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
305
|
-
|
|
306
|
-
// Create two bookmarks with same activity and user but different folders
|
|
307
|
-
const bookmark1 = {
|
|
308
|
-
...createMockBookmark(user, activity),
|
|
309
|
-
folder: {
|
|
310
|
-
id: 'folder1',
|
|
311
|
-
name: 'Folder 1',
|
|
312
|
-
created_at: new Date(),
|
|
313
|
-
updated_at: new Date(),
|
|
314
|
-
custom: {},
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
const bookmark2 = {
|
|
318
|
-
...createMockBookmark(user, activity),
|
|
319
|
-
folder: {
|
|
320
|
-
id: 'folder2',
|
|
321
|
-
name: 'Folder 2',
|
|
322
|
-
created_at: new Date(),
|
|
323
|
-
updated_at: new Date(),
|
|
324
|
-
custom: {},
|
|
325
|
-
},
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
activity.own_bookmarks = [bookmark1, bookmark2];
|
|
329
|
-
|
|
330
|
-
// Update bookmark1
|
|
331
|
-
const updatedBookmark1 = {
|
|
332
|
-
...bookmark1,
|
|
333
|
-
custom: { updated: true },
|
|
334
|
-
};
|
|
335
|
-
const event = createMockUpdatedEvent(updatedBookmark1);
|
|
336
|
-
const result = updateBookmarkInActivity(event, activity, true);
|
|
337
|
-
|
|
338
|
-
expect(result.changed).toBe(true);
|
|
339
|
-
expect(result.own_bookmarks).toHaveLength(2);
|
|
340
|
-
expect(result.own_bookmarks).toContain(updatedBookmark1);
|
|
341
|
-
expect(result.own_bookmarks).toContain(bookmark2);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it('should handle updating bookmarks without folders correctly', () => {
|
|
345
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
346
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
347
|
-
|
|
348
|
-
// Create two bookmarks: one with folder, one without
|
|
349
|
-
const bookmarkWithFolder = {
|
|
350
|
-
...createMockBookmark(user, activity),
|
|
351
|
-
folder: {
|
|
352
|
-
id: 'folder1',
|
|
353
|
-
name: 'Folder 1',
|
|
354
|
-
created_at: new Date(),
|
|
355
|
-
updated_at: new Date(),
|
|
356
|
-
custom: {},
|
|
357
|
-
},
|
|
358
|
-
};
|
|
359
|
-
const bookmarkWithoutFolder = createMockBookmark(user, activity);
|
|
360
|
-
|
|
361
|
-
activity.own_bookmarks = [bookmarkWithFolder, bookmarkWithoutFolder];
|
|
362
|
-
|
|
363
|
-
// Update bookmark without folder
|
|
364
|
-
const updatedBookmarkWithoutFolder = {
|
|
365
|
-
...bookmarkWithoutFolder,
|
|
366
|
-
custom: { updated: true },
|
|
367
|
-
};
|
|
368
|
-
const event = createMockUpdatedEvent(updatedBookmarkWithoutFolder);
|
|
369
|
-
const result = updateBookmarkInActivity(event, activity, true);
|
|
370
|
-
|
|
371
|
-
expect(result.changed).toBe(true);
|
|
372
|
-
expect(result.own_bookmarks).toHaveLength(2);
|
|
373
|
-
expect(result.own_bookmarks).toContain(bookmarkWithFolder);
|
|
374
|
-
expect(result.own_bookmarks).toContain(updatedBookmarkWithoutFolder);
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
describe('addBookmarkToActivities', () => {
|
|
379
|
-
it('should add bookmark to correct activity', () => {
|
|
380
|
-
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
381
|
-
const activity2 = generateActivityResponse({ id: 'activity2' });
|
|
382
|
-
const activities = [activity1, activity2];
|
|
383
|
-
|
|
384
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
385
|
-
const bookmark = createMockBookmark(user, activity1);
|
|
386
|
-
const event = createMockAddedEvent(bookmark);
|
|
387
|
-
|
|
388
|
-
const result = addBookmarkToActivities(event, activities, true);
|
|
389
|
-
|
|
390
|
-
expect(result.changed).toBe(true);
|
|
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);
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it('should return unchanged when activity not found', () => {
|
|
398
|
-
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
399
|
-
const activities = [activity1];
|
|
400
|
-
|
|
401
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
402
|
-
const differentActivity = generateActivityResponse({ id: 'activity2' });
|
|
403
|
-
const bookmark = createMockBookmark(user, differentActivity);
|
|
404
|
-
const event = createMockAddedEvent(bookmark);
|
|
405
|
-
|
|
406
|
-
const result = addBookmarkToActivities(event, activities, true);
|
|
407
|
-
|
|
408
|
-
expect(result.changed).toBe(false);
|
|
409
|
-
expect(result.entities).toEqual(activities);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
it('should handle undefined activities', () => {
|
|
413
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
414
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
415
|
-
const bookmark = createMockBookmark(user, activity);
|
|
416
|
-
const event = createMockAddedEvent(bookmark);
|
|
417
|
-
|
|
418
|
-
const result = addBookmarkToActivities(event, undefined, true);
|
|
419
|
-
|
|
420
|
-
expect(result.changed).toBe(false);
|
|
421
|
-
expect(result.entities).toBeUndefined();
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
describe('removeBookmarkFromActivities', () => {
|
|
426
|
-
it('should remove bookmark from correct activity', () => {
|
|
427
|
-
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
428
|
-
const activity2 = generateActivityResponse({ id: 'activity2' });
|
|
429
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
430
|
-
const bookmark = createMockBookmark(user, activity1);
|
|
431
|
-
activity1.own_bookmarks = [bookmark];
|
|
432
|
-
const activities = [activity1, activity2];
|
|
433
|
-
|
|
434
|
-
const event = createMockDeletedEvent(bookmark);
|
|
435
|
-
const result = removeBookmarkFromActivities(event, activities, true);
|
|
436
|
-
|
|
437
|
-
expect(result.changed).toBe(true);
|
|
438
|
-
expect(result.entities).toHaveLength(2);
|
|
439
|
-
expect(result.entities![0].own_bookmarks).toHaveLength(0);
|
|
440
|
-
expect(result.entities![1].own_bookmarks).toHaveLength(0);
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
it('should return unchanged when activity not found', () => {
|
|
444
|
-
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
445
|
-
const activities = [activity1];
|
|
446
|
-
|
|
447
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
448
|
-
const differentActivity = generateActivityResponse({ id: 'activity2' });
|
|
449
|
-
const bookmark = createMockBookmark(user, differentActivity);
|
|
450
|
-
const event = createMockDeletedEvent(bookmark);
|
|
451
|
-
|
|
452
|
-
const result = removeBookmarkFromActivities(event, activities, true);
|
|
453
|
-
|
|
454
|
-
expect(result.changed).toBe(false);
|
|
455
|
-
expect(result.entities).toEqual(activities);
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
it('should handle undefined activities', () => {
|
|
459
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
460
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
461
|
-
const bookmark = createMockBookmark(user, activity);
|
|
462
|
-
const event = createMockDeletedEvent(bookmark);
|
|
463
|
-
|
|
464
|
-
const result = removeBookmarkFromActivities(event, undefined, true);
|
|
465
|
-
|
|
466
|
-
expect(result.changed).toBe(false);
|
|
467
|
-
expect(result.entities).toBeUndefined();
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
describe('updateBookmarkInActivities', () => {
|
|
472
|
-
it('should update bookmark in correct activity', () => {
|
|
473
|
-
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
474
|
-
const activity2 = generateActivityResponse({ id: 'activity2' });
|
|
475
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
476
|
-
const bookmark = createMockBookmark(user, activity1);
|
|
477
|
-
activity1.own_bookmarks = [bookmark];
|
|
478
|
-
const activities = [activity1, activity2];
|
|
479
|
-
|
|
480
|
-
const updatedBookmark = {
|
|
481
|
-
...bookmark,
|
|
482
|
-
custom: { updated: true },
|
|
483
|
-
};
|
|
484
|
-
const event = createMockUpdatedEvent(updatedBookmark);
|
|
485
|
-
const result = updateBookmarkInActivities(event, activities, true);
|
|
486
|
-
|
|
487
|
-
expect(result.changed).toBe(true);
|
|
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);
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
it('should return unchanged when activity not found', () => {
|
|
495
|
-
const activity1 = generateActivityResponse({ id: 'activity1' });
|
|
496
|
-
const activities = [activity1];
|
|
497
|
-
|
|
498
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
499
|
-
const differentActivity = generateActivityResponse({ id: 'activity2' });
|
|
500
|
-
const bookmark = createMockBookmark(user, differentActivity);
|
|
501
|
-
const event = createMockUpdatedEvent(bookmark);
|
|
502
|
-
|
|
503
|
-
const result = updateBookmarkInActivities(event, activities, true);
|
|
504
|
-
|
|
505
|
-
expect(result.changed).toBe(false);
|
|
506
|
-
expect(result.entities).toEqual(activities);
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
it('should handle undefined activities', () => {
|
|
510
|
-
const user = generateUserResponse({ id: 'user1' });
|
|
511
|
-
const activity = generateActivityResponse({ id: 'activity1' });
|
|
512
|
-
const bookmark = createMockBookmark(user, activity);
|
|
513
|
-
const event = createMockUpdatedEvent(bookmark);
|
|
514
|
-
|
|
515
|
-
const result = updateBookmarkInActivities(event, undefined, true);
|
|
516
|
-
|
|
517
|
-
expect(result.changed).toBe(false);
|
|
518
|
-
expect(result.entities).toBeUndefined();
|
|
519
|
-
});
|
|
520
|
-
});
|
|
521
|
-
});
|
|
@@ -1,178 +0,0 @@
|
|
|
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).toBe(0);
|
|
69
|
-
expect(stateBefore.pinned_activities![0].activity.bookmark_count).toBe(
|
|
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).toBe(
|
|
85
|
-
stateBefore.activities![0].own_reactions,
|
|
86
|
-
);
|
|
87
|
-
expect(stateAfter.pinned_activities![0].activity.own_reactions).toBe(
|
|
88
|
-
stateBefore.pinned_activities![0].activity.own_reactions,
|
|
89
|
-
);
|
|
90
|
-
expect(stateAfter.activities![0].bookmark_count).toBe(1);
|
|
91
|
-
expect(stateAfter.pinned_activities![0].activity.bookmark_count).toBe(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).toBe(0);
|
|
124
|
-
expect(stateBefore.pinned_activities![0].activity.bookmark_count).toBe(
|
|
125
|
-
0,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
handleBookmarkAdded.call(feed, event);
|
|
129
|
-
|
|
130
|
-
const stateAfter = feed.currentState;
|
|
131
|
-
expect(stateAfter.activities![0].own_bookmarks).toBe(
|
|
132
|
-
stateBefore.activities![0].own_bookmarks,
|
|
133
|
-
);
|
|
134
|
-
expect(stateAfter.pinned_activities![0].activity.own_bookmarks).toBe(
|
|
135
|
-
stateBefore.pinned_activities![0].activity.own_bookmarks,
|
|
136
|
-
);
|
|
137
|
-
expect(stateAfter.activities![0].own_reactions).toBe(
|
|
138
|
-
stateBefore.activities![0].own_reactions,
|
|
139
|
-
);
|
|
140
|
-
expect(stateAfter.pinned_activities![0].activity.own_reactions).toBe(
|
|
141
|
-
stateBefore.pinned_activities![0].activity.own_reactions,
|
|
142
|
-
);
|
|
143
|
-
expect(stateAfter.activities![0].bookmark_count).toBe(1);
|
|
144
|
-
expect(stateAfter.pinned_activities![0].activity.bookmark_count).toBe(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
|
-
});
|