@stream-io/feeds-client 0.2.17 → 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.
Files changed (117) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/index.js +94 -25
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/react-bindings.js +26 -55
  5. package/dist/cjs/react-bindings.js.map +1 -1
  6. package/dist/es/index.mjs +86 -17
  7. package/dist/es/index.mjs.map +1 -1
  8. package/dist/es/react-bindings.mjs +19 -48
  9. package/dist/es/react-bindings.mjs.map +1 -1
  10. package/dist/{index-nq6SDtbt.js → feeds-client-C09giTf1.js} +322 -133
  11. package/dist/feeds-client-C09giTf1.js.map +1 -0
  12. package/dist/{index-BZL77zNq.mjs → feeds-client-CFadXO-B.mjs} +335 -146
  13. package/dist/feeds-client-CFadXO-B.mjs.map +1 -0
  14. package/dist/tsconfig.tsbuildinfo +1 -1
  15. package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts +2 -32
  16. package/dist/types/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.d.ts.map +1 -1
  17. package/dist/types/common/real-time/StableWSConnection.d.ts +3 -3
  18. package/dist/types/common/real-time/event-models.d.ts +7 -2
  19. package/dist/types/common/real-time/event-models.d.ts.map +1 -1
  20. package/dist/types/common/types.d.ts +1 -0
  21. package/dist/types/common/types.d.ts.map +1 -1
  22. package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts +4 -3
  23. package/dist/types/feed/event-handlers/activity/handle-activity-added.d.ts.map +1 -1
  24. package/dist/types/feed/event-handlers/activity/handle-activity-updated.d.ts.map +1 -1
  25. package/dist/types/feed/event-handlers/activity-updater.d.ts +44 -0
  26. package/dist/types/feed/event-handlers/activity-updater.d.ts.map +1 -0
  27. package/dist/types/feed/event-handlers/add-aggregated-activities-to-state.d.ts +6 -0
  28. package/dist/types/feed/event-handlers/add-aggregated-activities-to-state.d.ts.map +1 -0
  29. package/dist/types/feed/event-handlers/index.d.ts +3 -1
  30. package/dist/types/feed/event-handlers/index.d.ts.map +1 -1
  31. package/dist/types/feed/event-handlers/{aggregated-feed/handle-aggregated-feed-updated.d.ts → notification-feed/handle-notification-feed-updated.d.ts} +2 -11
  32. package/dist/types/feed/event-handlers/notification-feed/handle-notification-feed-updated.d.ts.map +1 -0
  33. package/dist/types/feed/event-handlers/notification-feed/index.d.ts +2 -0
  34. package/dist/types/feed/event-handlers/notification-feed/index.d.ts.map +1 -0
  35. package/dist/types/feed/event-handlers/story-feeds/handle-story-feeds-updated.d.ts +15 -0
  36. package/dist/types/feed/event-handlers/story-feeds/handle-story-feeds-updated.d.ts.map +1 -0
  37. package/dist/types/feed/event-handlers/story-feeds/index.d.ts +2 -0
  38. package/dist/types/feed/event-handlers/story-feeds/index.d.ts.map +1 -0
  39. package/dist/types/feed/feed.d.ts +10 -4
  40. package/dist/types/feed/feed.d.ts.map +1 -1
  41. package/dist/types/feeds-client/feeds-client.d.ts +14 -4
  42. package/dist/types/feeds-client/feeds-client.d.ts.map +1 -1
  43. package/dist/types/gen/feeds/FeedsApi.d.ts.map +1 -1
  44. package/dist/types/gen/models/index.d.ts +42 -451
  45. package/dist/types/gen/models/index.d.ts.map +1 -1
  46. package/dist/types/utils/throttling/index.d.ts +3 -0
  47. package/dist/types/utils/throttling/index.d.ts.map +1 -0
  48. package/dist/types/utils/throttling/throttle.d.ts +34 -0
  49. package/dist/types/utils/throttling/throttle.d.ts.map +1 -0
  50. package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts +14 -0
  51. package/dist/types/utils/throttling/throttled-get-batched-own-capabilities.d.ts.map +1 -0
  52. package/package.json +7 -3
  53. package/react-bindings.d.ts +11 -0
  54. package/react-bindings.js +7 -0
  55. package/react-bindings.mjs +11 -0
  56. package/src/bindings/react/hooks/feed-state-hooks/useOwnCapabilities.ts +21 -73
  57. package/src/common/real-time/event-models.ts +8 -2
  58. package/src/common/types.ts +1 -0
  59. package/src/feed/event-handlers/activity/handle-activity-added.ts +18 -12
  60. package/src/feed/event-handlers/activity/handle-activity-updated.ts +12 -16
  61. package/src/feed/event-handlers/activity-updater.ts +15 -0
  62. package/src/feed/event-handlers/add-aggregated-activities-to-state.ts +72 -0
  63. package/src/feed/event-handlers/index.ts +3 -1
  64. package/src/feed/event-handlers/{aggregated-feed/handle-aggregated-feed-updated.ts → notification-feed/handle-notification-feed-updated.ts} +2 -94
  65. package/src/feed/event-handlers/notification-feed/index.ts +1 -0
  66. package/src/feed/event-handlers/story-feeds/handle-story-feeds-updated.ts +122 -0
  67. package/src/feed/event-handlers/story-feeds/index.ts +1 -0
  68. package/src/feed/feed.ts +30 -3
  69. package/src/feeds-client/feeds-client.ts +127 -6
  70. package/src/gen/feeds/FeedsApi.ts +5 -0
  71. package/src/gen/model-decoders/decoders.ts +10 -4
  72. package/src/gen/models/index.ts +75 -834
  73. package/src/test-utils/response-generators.ts +37 -1
  74. package/src/utils/throttling/index.ts +2 -0
  75. package/src/utils/throttling/throttle.ts +123 -0
  76. package/src/utils/throttling/throttled-get-batched-own-capabilities.ts +42 -0
  77. package/dist/index-BZL77zNq.mjs.map +0 -1
  78. package/dist/index-nq6SDtbt.js.map +0 -1
  79. package/dist/types/feed/event-handlers/aggregated-feed/handle-aggregated-feed-updated.d.ts.map +0 -1
  80. package/dist/types/feed/event-handlers/aggregated-feed/index.d.ts +0 -2
  81. package/dist/types/feed/event-handlers/aggregated-feed/index.d.ts.map +0 -1
  82. package/src/feed/event-handlers/activity/activity-marked-utils.test.ts +0 -208
  83. package/src/feed/event-handlers/activity/activity-reaction-utils.test.ts +0 -371
  84. package/src/feed/event-handlers/activity/activity-utils.test.ts +0 -252
  85. package/src/feed/event-handlers/activity/handle-activity-added.test.ts +0 -86
  86. package/src/feed/event-handlers/activity/handle-activity-deleted.test.ts +0 -117
  87. package/src/feed/event-handlers/activity/handle-activity-pinned.test.ts +0 -60
  88. package/src/feed/event-handlers/activity/handle-activity-reaction-added.test.ts +0 -257
  89. package/src/feed/event-handlers/activity/handle-activity-reaction-deleted.test.ts +0 -317
  90. package/src/feed/event-handlers/activity/handle-activity-reaction-updated.test.ts +0 -282
  91. package/src/feed/event-handlers/activity/handle-activity-unpinned.test.ts +0 -95
  92. package/src/feed/event-handlers/activity/handle-activity-updated.test.ts +0 -245
  93. package/src/feed/event-handlers/aggregated-feed/handle-aggregated-feed-updated.test.ts +0 -644
  94. package/src/feed/event-handlers/aggregated-feed/index.ts +0 -1
  95. package/src/feed/event-handlers/bookmark/bookmark-utils.test.ts +0 -521
  96. package/src/feed/event-handlers/bookmark/handle-bookmark-added.test.ts +0 -178
  97. package/src/feed/event-handlers/bookmark/handle-bookmark-deleted.test.ts +0 -188
  98. package/src/feed/event-handlers/bookmark/handle-bookmark-updated.test.ts +0 -196
  99. package/src/feed/event-handlers/comment/handle-comment-added.test.ts +0 -271
  100. package/src/feed/event-handlers/comment/handle-comment-deleted.test.ts +0 -255
  101. package/src/feed/event-handlers/comment/handle-comment-reaction-added.test.ts +0 -329
  102. package/src/feed/event-handlers/comment/handle-comment-reaction-deleted.test.ts +0 -343
  103. package/src/feed/event-handlers/comment/handle-comment-reaction-updated.test.ts +0 -350
  104. package/src/feed/event-handlers/comment/handle-comment-updated.test.ts +0 -267
  105. package/src/feed/event-handlers/comment/utils/update-comment-count.test.ts +0 -322
  106. package/src/feed/event-handlers/feed-member/handle-feed-member-added.test.ts +0 -75
  107. package/src/feed/event-handlers/feed-member/handle-feed-member-removed.test.ts +0 -82
  108. package/src/feed/event-handlers/feed-member/handle-feed-member-updated.test.ts +0 -84
  109. package/src/feed/event-handlers/follow/follow-state-update-queue.test.ts +0 -219
  110. package/src/feed/event-handlers/follow/handle-follow-created.test.ts +0 -250
  111. package/src/feed/event-handlers/follow/handle-follow-deleted.test.ts +0 -268
  112. package/src/feed/event-handlers/follow/handle-follow-updated.test.ts +0 -131
  113. package/src/feed/feed.test.ts +0 -90
  114. package/src/feeds-client/event-handlers/user/handle-user-updated.test.ts +0 -53
  115. package/src/utils/event-triggered-by-connected-user.test.ts +0 -73
  116. package/src/utils/state-update-queue.test.ts +0 -129
  117. package/src/utils/unique-array-merge.test.ts +0 -179
@@ -1 +0,0 @@
1
- {"version":3,"file":"handle-aggregated-feed-updated.d.ts","sourceRoot":"","sources":["../../../../../src/feed/event-handlers/aggregated-feed/handle-aggregated-feed-updated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,EAC1B,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG/E,eAAO,MAAM,8BAA8B,GACzC,yBAAyB,0BAA0B,EAAE,EACrD,sBAAsB,0BAA0B,EAAE,GAAG,SAAS,EAC9D,UAAU,OAAO,GAAG,KAAK,GAAG,SAAS;2BAGZ,0BAA0B,EAAE;EAuCtD,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,wBAAwB,0BAA0B,EAClD,4BAA4B,0BAA0B;;;CAoBvD,CAAC;AAEF,eAAO,MAAM,+BAA+B,GAC1C,OAAO,4BAA4B,EACnC,8BAA8B,0BAA0B,EAAE,EAC1D,4BAA4B,0BAA0B,KACrD,iBAAiB,CAAC;IACnB,IAAI,CAAC,EAAE;QACL,mBAAmB,CAAC,EAAE,0BAA0B,CAAC;QACjD,qBAAqB,CAAC,EAAE,0BAA0B,EAAE,CAAC;KACtD,CAAC;CACH,CAyCA,CAAC;AAEF,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,YAAY,CAAC,iCAAiC,CAAC,QAavD;AAED,wBAAgB,0BAA0B,CACxC,oBAAoB,EAAE,0BAA0B,EAAE,GAAG,SAAS,EAC9D,KAAK,EAAE,uBAAuB,GAC7B,iBAAiB,CAAC;IACnB,IAAI,CAAC,EAAE;QACL,qBAAqB,CAAC,EAAE,0BAA0B,EAAE,CAAC;KACtD,CAAC;CACH,CAAC,CAoBD;AAED,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,YAAY,CAAC,4BAA4B,CAAC,QAWlD"}
@@ -1,2 +0,0 @@
1
- export * from './handle-aggregated-feed-updated';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/feed/event-handlers/aggregated-feed/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}
@@ -1,208 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type {
3
- ActivityMarkEvent,
4
- NotificationStatusResponse,
5
- } from '../../../gen/models';
6
- import { updateNotificationStatusFromActivityMarked } from './handle-activity-marked';
7
-
8
- const createMockActivityMarkEvent = (
9
- overrides: Partial<ActivityMarkEvent> = {},
10
- ): ActivityMarkEvent => ({
11
- created_at: new Date(),
12
- fid: 'user:notification',
13
- custom: {},
14
- type: 'feeds.activity.marked',
15
- ...overrides,
16
- });
17
-
18
- const createMockNotificationStatus = (
19
- overrides: Partial<NotificationStatusResponse> = {},
20
- ): NotificationStatusResponse => ({
21
- unread: 0,
22
- unseen: 0,
23
- ...overrides,
24
- });
25
-
26
- const createMockAggregatedActivity = (group: string) => ({ group });
27
-
28
- describe('activity-marked-utils', () => {
29
- describe('updateNotificationStatusFromActivityMarked', () => {
30
- it('should return unchanged if notification_status is undefined', () => {
31
- const event = createMockActivityMarkEvent({ mark_all_read: true });
32
- const currentStatus = undefined;
33
-
34
- const result = updateNotificationStatusFromActivityMarked(
35
- event,
36
- currentStatus,
37
- );
38
-
39
- expect(result.changed).toBe(false);
40
- });
41
-
42
- it('should handle mark_all_read by adding all aggregated activity groups', () => {
43
- const event = createMockActivityMarkEvent({ mark_all_read: true });
44
- const currentStatus = createMockNotificationStatus({
45
- read_activities: ['existing1'],
46
- });
47
- const aggregatedActivities = [
48
- createMockAggregatedActivity('group1'),
49
- createMockAggregatedActivity('group2'),
50
- createMockAggregatedActivity('group3'),
51
- ];
52
-
53
- const result = updateNotificationStatusFromActivityMarked(
54
- event,
55
- currentStatus,
56
- aggregatedActivities,
57
- );
58
-
59
- expect(result.changed).toBe(true);
60
- expect(result.data?.notification_status.read_activities).toEqual([
61
- 'existing1',
62
- 'group1',
63
- 'group2',
64
- 'group3',
65
- ]);
66
- });
67
-
68
- it('should handle mark_read by adding specific activity IDs', () => {
69
- const event = createMockActivityMarkEvent({
70
- mark_read: ['activity1', 'activity2'],
71
- });
72
- const currentStatus = createMockNotificationStatus({
73
- read_activities: ['existing1'],
74
- });
75
-
76
- const result = updateNotificationStatusFromActivityMarked(
77
- event,
78
- currentStatus,
79
- );
80
-
81
- expect(result.changed).toBe(true);
82
- expect(result.data?.notification_status.read_activities).toEqual([
83
- 'existing1',
84
- 'activity1',
85
- 'activity2',
86
- ]);
87
- });
88
-
89
- it('should handle mark_all_seen by setting last_seen_at to current date', () => {
90
- const event = createMockActivityMarkEvent({ mark_all_seen: true });
91
- const currentStatus = createMockNotificationStatus({
92
- last_seen_at: new Date('2023-01-01'),
93
- });
94
-
95
- const result = updateNotificationStatusFromActivityMarked(
96
- event,
97
- currentStatus,
98
- );
99
-
100
- expect(result.changed).toBe(true);
101
- expect(result.data?.notification_status.last_seen_at).toBeInstanceOf(
102
- Date,
103
- );
104
- expect(
105
- result.data?.notification_status.last_seen_at!.getTime(),
106
- ).toBeGreaterThan(new Date('2023-01-01').getTime());
107
- });
108
-
109
- it('should handle multiple mark flags simultaneously', () => {
110
- const event = createMockActivityMarkEvent({
111
- mark_all_read: true,
112
- mark_all_seen: true,
113
- });
114
- const currentStatus = createMockNotificationStatus({
115
- read_activities: ['existing1'],
116
- last_seen_at: new Date('2023-01-01'),
117
- });
118
- const aggregatedActivities = [
119
- createMockAggregatedActivity('group1'),
120
- createMockAggregatedActivity('group2'),
121
- ];
122
-
123
- const result = updateNotificationStatusFromActivityMarked(
124
- event,
125
- currentStatus,
126
- aggregatedActivities,
127
- );
128
-
129
- expect(result.changed).toBe(true);
130
- expect(result.data?.notification_status.read_activities).toEqual([
131
- 'existing1',
132
- 'group1',
133
- 'group2',
134
- ]);
135
- expect(result.data?.notification_status.last_seen_at).toBeInstanceOf(
136
- Date,
137
- );
138
- });
139
-
140
- it('should deduplicate read activities when adding new ones', () => {
141
- const event = createMockActivityMarkEvent({
142
- mark_read: ['activity1', 'activity1', 'activity2'],
143
- });
144
- const currentStatus = createMockNotificationStatus({
145
- read_activities: ['existing1', 'activity1'],
146
- });
147
-
148
- const result = updateNotificationStatusFromActivityMarked(
149
- event,
150
- currentStatus,
151
- );
152
-
153
- expect(result.changed).toBe(true);
154
- expect(result.data?.notification_status.read_activities).toEqual([
155
- 'existing1',
156
- 'activity1',
157
- 'activity2',
158
- ]);
159
- });
160
-
161
- it('should preserve existing notification status fields', () => {
162
- const event = createMockActivityMarkEvent({ mark_all_seen: true });
163
- const currentStatus = createMockNotificationStatus({
164
- unread: 5,
165
- unseen: 3,
166
- read_activities: ['existing1'],
167
- });
168
-
169
- const result = updateNotificationStatusFromActivityMarked(
170
- event,
171
- currentStatus,
172
- );
173
-
174
- expect(result.changed).toBe(true);
175
- expect(result.data?.notification_status.unread).toBe(5);
176
- expect(result.data?.notification_status.unseen).toBe(3);
177
- expect(result.data?.notification_status.read_activities).toEqual([
178
- 'existing1',
179
- ]);
180
- expect(result.data?.notification_status.last_seen_at).toBeInstanceOf(
181
- Date,
182
- );
183
- });
184
-
185
- it('should handle mark_all_read with no existing read_activities', () => {
186
- const event = createMockActivityMarkEvent({ mark_all_read: true });
187
- const currentStatus = createMockNotificationStatus({
188
- read_activities: undefined,
189
- });
190
- const aggregatedActivities = [
191
- createMockAggregatedActivity('group1'),
192
- createMockAggregatedActivity('group2'),
193
- ];
194
-
195
- const result = updateNotificationStatusFromActivityMarked(
196
- event,
197
- currentStatus,
198
- aggregatedActivities,
199
- );
200
-
201
- expect(result.changed).toBe(true);
202
- expect(result.data?.notification_status.read_activities).toEqual([
203
- 'group1',
204
- 'group2',
205
- ]);
206
- });
207
- });
208
- });
@@ -1,371 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import type {
3
- ActivityReactionAddedEvent,
4
- ActivityReactionDeletedEvent,
5
- ActivityResponse,
6
- FeedsReactionResponse,
7
- } from '../../../gen/models';
8
- import { addReactionToActivities, removeReactionFromActivities } from './';
9
- import {
10
- generateActivityResponse,
11
- generateFeedReactionResponse,
12
- } from '../../../test-utils';
13
-
14
- const addReactionToActivity = (
15
- event: ActivityReactionAddedEvent,
16
- activity: ActivityResponse,
17
- eventBelongsToCurrentUser: boolean,
18
- ) => {
19
- const result = addReactionToActivities(
20
- event,
21
- [activity],
22
- eventBelongsToCurrentUser,
23
- );
24
-
25
- return {
26
- changed: result.changed,
27
- ...result.entities![0],
28
- };
29
- };
30
-
31
- const removeReactionFromActivity = (
32
- event: ActivityReactionAddedEvent,
33
- activity: ActivityResponse,
34
- eventBelongsToCurrentUser: boolean,
35
- ) => {
36
- const result = removeReactionFromActivities(
37
- event,
38
- [activity],
39
- eventBelongsToCurrentUser,
40
- );
41
-
42
- return {
43
- changed: result.changed,
44
- ...result.entities![0],
45
- };
46
- };
47
-
48
- const createMockAddedEvent = (
49
- reaction: FeedsReactionResponse,
50
- activity: ActivityResponse,
51
- ): ActivityReactionAddedEvent => ({
52
- fid: 'test-fid',
53
- reaction,
54
- activity,
55
- created_at: new Date(),
56
- custom: {},
57
- type: 'reaction.added',
58
- });
59
-
60
- const createMockDeletedEvent = (
61
- reaction: FeedsReactionResponse,
62
- activity: ActivityResponse,
63
- ): ActivityReactionDeletedEvent => ({
64
- fid: 'test-fid',
65
- reaction,
66
- activity,
67
- created_at: new Date(),
68
- custom: {},
69
- type: 'reaction.deleted',
70
- });
71
-
72
- describe('activity-reaction-utils', () => {
73
- describe('addReactionToActivity', () => {
74
- it('should add reaction to own_reactions when from current user', () => {
75
- const activity = generateActivityResponse({ id: 'activity1' });
76
- const reaction = generateFeedReactionResponse({
77
- type: 'like',
78
- user: { id: 'user1' },
79
- activity_id: 'activity1',
80
- });
81
- const eventActivity = { ...activity };
82
- eventActivity.latest_reactions = [reaction];
83
- eventActivity.reaction_groups = {
84
- [reaction.type]: {
85
- count: 1,
86
- first_reaction_at: reaction.created_at,
87
- last_reaction_at: reaction.created_at,
88
- sum_scores: 0,
89
- },
90
- };
91
-
92
- const event = createMockAddedEvent(reaction, eventActivity);
93
- const result = addReactionToActivity(event, activity, true);
94
- expect(result.changed).toBe(true);
95
- expect(result.own_reactions).toHaveLength(1);
96
- expect(result.own_reactions[0]).toEqual(reaction);
97
- expect(result.latest_reactions).toHaveLength(1);
98
- expect(result.latest_reactions[0]).toEqual(reaction);
99
- expect(result.reaction_groups.like).toEqual({
100
- count: 1,
101
- first_reaction_at: reaction.created_at,
102
- last_reaction_at: reaction.created_at,
103
- sum_scores: 0,
104
- });
105
- });
106
-
107
- it('should not add reaction to own_reactions when not from current user', () => {
108
- const activity = generateActivityResponse({ id: 'activity1' });
109
- const reaction = generateFeedReactionResponse({
110
- type: 'like',
111
- user: { id: 'user2' },
112
- activity_id: 'activity1',
113
- });
114
- const eventActivity = { ...activity };
115
- eventActivity.latest_reactions = [reaction];
116
- eventActivity.reaction_groups = {
117
- [reaction.type]: {
118
- count: 1,
119
- first_reaction_at: reaction.created_at,
120
- last_reaction_at: reaction.created_at,
121
- sum_scores: 0,
122
- },
123
- };
124
- const event = createMockAddedEvent(reaction, eventActivity);
125
-
126
- const result = addReactionToActivity(event, activity, false);
127
-
128
- expect(result.changed).toBe(true);
129
- expect(result.own_reactions).toHaveLength(0);
130
- expect(result.latest_reactions).toHaveLength(1);
131
- expect(result.latest_reactions[0]).toEqual(reaction);
132
- expect(result.reaction_groups.like).toEqual({
133
- count: 1,
134
- first_reaction_at: reaction.created_at,
135
- last_reaction_at: reaction.created_at,
136
- sum_scores: 0,
137
- });
138
- });
139
- });
140
-
141
- describe('removeReactionFromActivity', () => {
142
- it('should remove reaction from own_reactions when from current user', () => {
143
- const activity = generateActivityResponse({ id: 'activity1' });
144
- const reaction = generateFeedReactionResponse({
145
- type: 'like',
146
- user: { id: 'user1' },
147
- activity_id: 'activity1',
148
- });
149
- const eventActivity = { ...activity };
150
- eventActivity.latest_reactions = [reaction];
151
- eventActivity.reaction_groups = {
152
- [reaction.type]: {
153
- count: 1,
154
- first_reaction_at: reaction.created_at,
155
- last_reaction_at: reaction.created_at,
156
- sum_scores: 0,
157
- },
158
- };
159
- const event = createMockAddedEvent(reaction, eventActivity);
160
- const activityWithReaction = addReactionToActivity(event, activity, true);
161
-
162
- const deleteEventActivity = { ...activityWithReaction };
163
- deleteEventActivity.latest_reactions = [];
164
- deleteEventActivity.reaction_groups = {};
165
- const deleteEvent = createMockDeletedEvent(reaction, deleteEventActivity);
166
- const result = removeReactionFromActivity(
167
- deleteEvent,
168
- activityWithReaction,
169
- true,
170
- );
171
-
172
- expect(result.changed).toBe(true);
173
- expect(result.own_reactions).toHaveLength(0);
174
- expect(result.latest_reactions).toHaveLength(0);
175
- expect(result.reaction_groups.like).toBeUndefined();
176
- });
177
-
178
- it('should not remove reaction from own_reactions when not from current user', () => {
179
- const activity = generateActivityResponse({ id: 'activity1' });
180
- const reaction = generateFeedReactionResponse({
181
- type: 'like',
182
- user: { id: 'user1' },
183
- activity_id: 'activity1',
184
- });
185
- const eventActivity = { ...activity };
186
- eventActivity.latest_reactions = [reaction];
187
- eventActivity.reaction_groups = {
188
- [reaction.type]: {
189
- count: 1,
190
- first_reaction_at: reaction.created_at,
191
- last_reaction_at: reaction.created_at,
192
- sum_scores: 0,
193
- },
194
- };
195
- const event = createMockAddedEvent(reaction, eventActivity);
196
- const activityWithReaction = addReactionToActivity(event, activity, true);
197
-
198
- const deleteEventActivity = { ...activityWithReaction };
199
- deleteEventActivity.latest_reactions = [];
200
- deleteEventActivity.reaction_groups = {};
201
- const deleteEvent = createMockDeletedEvent(reaction, deleteEventActivity);
202
- const result = removeReactionFromActivity(
203
- deleteEvent,
204
- activityWithReaction,
205
- false,
206
- );
207
-
208
- expect(result.changed).toBe(true);
209
- expect(result.own_reactions).toHaveLength(1);
210
- expect(result.latest_reactions).toHaveLength(0);
211
- expect(result.reaction_groups.like).toBeUndefined();
212
- });
213
- });
214
-
215
- describe('addReactionToActivities', () => {
216
- it('should add reaction to activity in activities array', () => {
217
- const activity = generateActivityResponse({ id: 'activity1' });
218
- const activities = [activity];
219
- const reaction = generateFeedReactionResponse({
220
- type: 'like',
221
- user: { id: 'user1' },
222
- activity_id: 'activity1',
223
- });
224
- const eventActivity = { ...activity };
225
- eventActivity.latest_reactions = [reaction];
226
- eventActivity.reaction_groups = {
227
- [reaction.type]: {
228
- count: 1,
229
- first_reaction_at: reaction.created_at,
230
- last_reaction_at: reaction.created_at,
231
- sum_scores: 0,
232
- },
233
- };
234
- const event = createMockAddedEvent(reaction, eventActivity);
235
-
236
- const result = addReactionToActivities(event, activities, true);
237
-
238
- expect(result.changed).toBe(true);
239
- expect(result.entities!).toHaveLength(1);
240
- expect(result.entities![0].own_reactions).toHaveLength(1);
241
- expect(result.entities![0].own_reactions[0]).toEqual(reaction);
242
- });
243
-
244
- it('should return unchanged state if activity not found', () => {
245
- const activity = generateActivityResponse({ id: 'activity1' });
246
- const activities = [activity];
247
- const reaction = generateFeedReactionResponse({
248
- type: 'like',
249
- user: { id: 'user1' },
250
- activity_id: 'activity2',
251
- });
252
- const eventActivity = generateActivityResponse({ id: 'activity2' });
253
- eventActivity.latest_reactions = [reaction];
254
- eventActivity.reaction_groups = {
255
- [reaction.type]: {
256
- count: 1,
257
- first_reaction_at: reaction.created_at,
258
- last_reaction_at: reaction.created_at,
259
- sum_scores: 0,
260
- },
261
- };
262
- const event = createMockAddedEvent(reaction, eventActivity);
263
-
264
- const result = addReactionToActivities(event, activities, true);
265
-
266
- expect(result.changed).toBe(false);
267
- expect(result.entities).toBe(activities);
268
- });
269
-
270
- it('should handle undefined activities', () => {
271
- const activity = generateActivityResponse({ id: 'activity1' });
272
- const reaction = generateFeedReactionResponse({
273
- type: 'like',
274
- user: { id: 'user1' },
275
- activity_id: 'activity1',
276
- });
277
- const eventActivity = { ...activity };
278
- eventActivity.own_reactions = [reaction];
279
- eventActivity.latest_reactions = [reaction];
280
- eventActivity.reaction_groups = {
281
- [reaction.type]: {
282
- count: 1,
283
- first_reaction_at: reaction.created_at,
284
- last_reaction_at: reaction.created_at,
285
- sum_scores: 0,
286
- },
287
- };
288
- const event = createMockAddedEvent(reaction, eventActivity);
289
-
290
- const result = addReactionToActivities(event, undefined, true);
291
-
292
- expect(result.changed).toBe(false);
293
- expect(result.entities).toBeUndefined();
294
- });
295
- });
296
-
297
- describe('removeReactionFromActivities', () => {
298
- it('should remove reaction from activity in activities array', () => {
299
- const activity = generateActivityResponse({ id: 'activity1' });
300
- const reaction = generateFeedReactionResponse({
301
- type: 'like',
302
- user: { id: 'user1' },
303
- activity_id: 'activity1',
304
- });
305
- const eventActivity = { ...activity };
306
- eventActivity.latest_reactions = [reaction];
307
- eventActivity.reaction_groups = {
308
- [reaction.type]: {
309
- count: 1,
310
- first_reaction_at: reaction.created_at,
311
- last_reaction_at: reaction.created_at,
312
- sum_scores: 0,
313
- },
314
- };
315
- const event = createMockAddedEvent(reaction, eventActivity);
316
- const activityWithReaction = addReactionToActivity(event, activity, true);
317
- const activities = [activityWithReaction];
318
-
319
- const deleteEventActivity = { ...activityWithReaction };
320
- deleteEventActivity.latest_reactions = [];
321
- deleteEventActivity.reaction_groups = {};
322
- const deleteEvent = createMockDeletedEvent(reaction, deleteEventActivity);
323
- const result = removeReactionFromActivities(
324
- deleteEvent,
325
- activities,
326
- true,
327
- );
328
-
329
- expect(result.changed).toBe(true);
330
- expect(result.entities).toHaveLength(1);
331
- expect(result.entities![0].own_reactions).toHaveLength(0);
332
- });
333
-
334
- it('should return unchanged state if activity not found', () => {
335
- const activity = generateActivityResponse({ id: 'activity1' });
336
- const activities = [activity];
337
- const reaction = generateFeedReactionResponse({
338
- type: 'like',
339
- user: { id: 'user1' },
340
- activity_id: 'activity2',
341
- });
342
- const eventActivity = generateActivityResponse({ id: 'activity2' });
343
- eventActivity.latest_reactions = [];
344
- eventActivity.reaction_groups = {};
345
- const event = createMockDeletedEvent(reaction, eventActivity);
346
-
347
- const result = removeReactionFromActivities(event, activities, true);
348
-
349
- expect(result.changed).toBe(false);
350
- expect(result.entities).toBe(activities);
351
- });
352
-
353
- it('should handle undefined activities', () => {
354
- const activity = generateActivityResponse({ id: 'activity1' });
355
- const reaction = generateFeedReactionResponse({
356
- type: 'like',
357
- user: { id: 'user1' },
358
- activity_id: 'activity1',
359
- });
360
- const eventActivity = { ...activity };
361
- eventActivity.latest_reactions = [];
362
- eventActivity.reaction_groups = {};
363
- const event = createMockDeletedEvent(reaction, eventActivity);
364
-
365
- const result = removeReactionFromActivities(event, undefined, true);
366
-
367
- expect(result.changed).toBe(false);
368
- expect(result.entities).toBeUndefined();
369
- });
370
- });
371
- });