@stream-io/feeds-client 0.2.0 → 0.2.2
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/@react-bindings/hooks/feed-state-hooks/index.ts +4 -0
- package/CHANGELOG.md +16 -0
- package/dist/@react-bindings/hooks/feed-state-hooks/index.d.ts +4 -0
- package/dist/@react-bindings/hooks/feed-state-hooks/useAggregatedActivities.d.ts +11 -0
- package/dist/@react-bindings/hooks/feed-state-hooks/useIsAggregatedActivityRead.d.ts +6 -0
- package/dist/@react-bindings/hooks/feed-state-hooks/useIsAggregatedActivitySeen.d.ts +6 -0
- package/dist/@react-bindings/hooks/feed-state-hooks/useNotificationStatus.d.ts +13 -0
- package/dist/@react-bindings/wrappers/StreamFeed.d.ts +1 -1
- package/dist/index-react-bindings.browser.cjs +505 -222
- package/dist/index-react-bindings.browser.cjs.map +1 -1
- package/dist/index-react-bindings.browser.js +502 -223
- package/dist/index-react-bindings.browser.js.map +1 -1
- package/dist/index-react-bindings.node.cjs +505 -222
- package/dist/index-react-bindings.node.cjs.map +1 -1
- package/dist/index-react-bindings.node.js +502 -223
- package/dist/index-react-bindings.node.js.map +1 -1
- package/dist/index.browser.cjs +440 -205
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +440 -206
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +440 -205
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +440 -206
- 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-marked.d.ts +11 -0
- 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/activity/index.d.ts +1 -0
- 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/notification-feed/handle-notification-feed-updated.d.ts +8 -1
- package/dist/src/feed/feed.d.ts +2 -2
- package/dist/src/gen/models/index.d.ts +36 -1
- package/dist/src/test-utils/response-generators.d.ts +66 -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/package.json +1 -1
- package/src/feed/event-handlers/activity/activity-marked-utils.test.ts +208 -0
- 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-marked.ts +68 -0
- 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 +95 -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/activity/index.ts +2 -1
- 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/comment/handle-comment-added.test.ts +147 -0
- package/src/feed/event-handlers/comment/handle-comment-deleted.test.ts +133 -0
- package/src/feed/event-handlers/comment/handle-comment-deleted.ts +24 -10
- package/src/feed/event-handlers/comment/handle-comment-reaction.test.ts +315 -0
- package/src/feed/event-handlers/comment/handle-comment-updated.test.ts +131 -0
- package/src/feed/event-handlers/follow/handle-follow-created.test.ts +7 -7
- package/src/feed/event-handlers/follow/handle-follow-deleted.test.ts +2 -2
- package/src/feed/event-handlers/follow/handle-follow-updated.test.ts +1 -1
- package/src/feed/event-handlers/notification-feed/handle-notification-feed-updated.test.ts +120 -0
- package/src/feed/event-handlers/notification-feed/handle-notification-feed-updated.ts +47 -3
- package/src/feed/feed.ts +4 -2
- package/src/gen/model-decoders/decoders.ts +14 -1
- package/src/gen/models/index.ts +73 -2
- package/src/gen/moderation/ModerationApi.ts +1 -0
- package/src/test-utils/response-generators.ts +383 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/update-entity-in-array.ts +51 -0
package/package.json
CHANGED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
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
|
+
});
|
|
@@ -5,73 +5,45 @@ import {
|
|
|
5
5
|
ActivityResponse,
|
|
6
6
|
FeedsReactionResponse,
|
|
7
7
|
} from '../../../gen/models';
|
|
8
|
+
import { addReactionToActivities, removeReactionFromActivities } from './';
|
|
8
9
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
removeReactionFromActivities,
|
|
13
|
-
} from './';
|
|
14
|
-
|
|
15
|
-
const createMockActivity = (id: string): ActivityResponse => ({
|
|
16
|
-
id,
|
|
17
|
-
type: 'test',
|
|
18
|
-
created_at: new Date(),
|
|
19
|
-
updated_at: new Date(),
|
|
20
|
-
visibility: 'public',
|
|
21
|
-
bookmark_count: 0,
|
|
22
|
-
comment_count: 0,
|
|
23
|
-
share_count: 0,
|
|
24
|
-
attachments: [],
|
|
25
|
-
comments: [],
|
|
26
|
-
feeds: [],
|
|
27
|
-
filter_tags: [],
|
|
28
|
-
interest_tags: [],
|
|
29
|
-
latest_reactions: [],
|
|
30
|
-
mentioned_users: [],
|
|
31
|
-
own_bookmarks: [],
|
|
32
|
-
own_reactions: [],
|
|
33
|
-
custom: {},
|
|
34
|
-
reaction_groups: {},
|
|
35
|
-
search_data: {},
|
|
36
|
-
popularity: 0,
|
|
37
|
-
score: 0,
|
|
38
|
-
reaction_count: 0,
|
|
39
|
-
user: {
|
|
40
|
-
id: 'user1',
|
|
41
|
-
created_at: new Date(),
|
|
42
|
-
updated_at: new Date(),
|
|
43
|
-
banned: false,
|
|
44
|
-
language: 'en',
|
|
45
|
-
online: false,
|
|
46
|
-
role: 'user',
|
|
47
|
-
blocked_user_ids: [],
|
|
48
|
-
teams: [],
|
|
49
|
-
custom: {},
|
|
50
|
-
},
|
|
51
|
-
});
|
|
10
|
+
generateActivityResponse,
|
|
11
|
+
generateFeedReactionResponse,
|
|
12
|
+
} from '../../../test-utils';
|
|
52
13
|
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
};
|
|
75
47
|
|
|
76
48
|
const createMockAddedEvent = (
|
|
77
49
|
reaction: FeedsReactionResponse,
|
|
@@ -100,8 +72,12 @@ const createMockDeletedEvent = (
|
|
|
100
72
|
describe('activity-reaction-utils', () => {
|
|
101
73
|
describe('addReactionToActivity', () => {
|
|
102
74
|
it('should add reaction to own_reactions when from current user', () => {
|
|
103
|
-
const activity =
|
|
104
|
-
const reaction =
|
|
75
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
76
|
+
const reaction = generateFeedReactionResponse({
|
|
77
|
+
type: 'like',
|
|
78
|
+
user: { id: 'user1' },
|
|
79
|
+
activity_id: 'activity1',
|
|
80
|
+
});
|
|
105
81
|
const eventActivity = { ...activity };
|
|
106
82
|
eventActivity.latest_reactions = [reaction];
|
|
107
83
|
eventActivity.reaction_groups = {
|
|
@@ -129,8 +105,12 @@ describe('activity-reaction-utils', () => {
|
|
|
129
105
|
});
|
|
130
106
|
|
|
131
107
|
it('should not add reaction to own_reactions when not from current user', () => {
|
|
132
|
-
const activity =
|
|
133
|
-
const reaction =
|
|
108
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
109
|
+
const reaction = generateFeedReactionResponse({
|
|
110
|
+
type: 'like',
|
|
111
|
+
user: { id: 'user2' },
|
|
112
|
+
activity_id: 'activity1',
|
|
113
|
+
});
|
|
134
114
|
const eventActivity = { ...activity };
|
|
135
115
|
eventActivity.latest_reactions = [reaction];
|
|
136
116
|
eventActivity.reaction_groups = {
|
|
@@ -160,8 +140,12 @@ describe('activity-reaction-utils', () => {
|
|
|
160
140
|
|
|
161
141
|
describe('removeReactionFromActivity', () => {
|
|
162
142
|
it('should remove reaction from own_reactions when from current user', () => {
|
|
163
|
-
const activity =
|
|
164
|
-
const reaction =
|
|
143
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
144
|
+
const reaction = generateFeedReactionResponse({
|
|
145
|
+
type: 'like',
|
|
146
|
+
user: { id: 'user1' },
|
|
147
|
+
activity_id: 'activity1',
|
|
148
|
+
});
|
|
165
149
|
const eventActivity = { ...activity };
|
|
166
150
|
eventActivity.latest_reactions = [reaction];
|
|
167
151
|
eventActivity.reaction_groups = {
|
|
@@ -192,8 +176,12 @@ describe('activity-reaction-utils', () => {
|
|
|
192
176
|
});
|
|
193
177
|
|
|
194
178
|
it('should not remove reaction from own_reactions when not from current user', () => {
|
|
195
|
-
const activity =
|
|
196
|
-
const reaction =
|
|
179
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
180
|
+
const reaction = generateFeedReactionResponse({
|
|
181
|
+
type: 'like',
|
|
182
|
+
user: { id: 'user1' },
|
|
183
|
+
activity_id: 'activity1',
|
|
184
|
+
});
|
|
197
185
|
const eventActivity = { ...activity };
|
|
198
186
|
eventActivity.latest_reactions = [reaction];
|
|
199
187
|
eventActivity.reaction_groups = {
|
|
@@ -226,9 +214,13 @@ describe('activity-reaction-utils', () => {
|
|
|
226
214
|
|
|
227
215
|
describe('addReactionToActivities', () => {
|
|
228
216
|
it('should add reaction to activity in activities array', () => {
|
|
229
|
-
const activity =
|
|
217
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
230
218
|
const activities = [activity];
|
|
231
|
-
const reaction =
|
|
219
|
+
const reaction = generateFeedReactionResponse({
|
|
220
|
+
type: 'like',
|
|
221
|
+
user: { id: 'user1' },
|
|
222
|
+
activity_id: 'activity1',
|
|
223
|
+
});
|
|
232
224
|
const eventActivity = { ...activity };
|
|
233
225
|
eventActivity.latest_reactions = [reaction];
|
|
234
226
|
eventActivity.reaction_groups = {
|
|
@@ -244,16 +236,20 @@ describe('activity-reaction-utils', () => {
|
|
|
244
236
|
const result = addReactionToActivities(event, activities, true);
|
|
245
237
|
|
|
246
238
|
expect(result.changed).toBe(true);
|
|
247
|
-
expect(result.
|
|
248
|
-
expect(result.
|
|
249
|
-
expect(result.
|
|
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);
|
|
250
242
|
});
|
|
251
243
|
|
|
252
244
|
it('should return unchanged state if activity not found', () => {
|
|
253
|
-
const activity =
|
|
245
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
254
246
|
const activities = [activity];
|
|
255
|
-
const reaction =
|
|
256
|
-
|
|
247
|
+
const reaction = generateFeedReactionResponse({
|
|
248
|
+
type: 'like',
|
|
249
|
+
user: { id: 'user1' },
|
|
250
|
+
activity_id: 'activity2',
|
|
251
|
+
});
|
|
252
|
+
const eventActivity = generateActivityResponse({ id: 'activity2' });
|
|
257
253
|
eventActivity.latest_reactions = [reaction];
|
|
258
254
|
eventActivity.reaction_groups = {
|
|
259
255
|
[reaction.type]: {
|
|
@@ -268,12 +264,16 @@ describe('activity-reaction-utils', () => {
|
|
|
268
264
|
const result = addReactionToActivities(event, activities, true);
|
|
269
265
|
|
|
270
266
|
expect(result.changed).toBe(false);
|
|
271
|
-
expect(result.
|
|
267
|
+
expect(result.entities).toBe(activities);
|
|
272
268
|
});
|
|
273
269
|
|
|
274
270
|
it('should handle undefined activities', () => {
|
|
275
|
-
const activity =
|
|
276
|
-
const reaction =
|
|
271
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
272
|
+
const reaction = generateFeedReactionResponse({
|
|
273
|
+
type: 'like',
|
|
274
|
+
user: { id: 'user1' },
|
|
275
|
+
activity_id: 'activity1',
|
|
276
|
+
});
|
|
277
277
|
const eventActivity = { ...activity };
|
|
278
278
|
eventActivity.own_reactions = [reaction];
|
|
279
279
|
eventActivity.latest_reactions = [reaction];
|
|
@@ -290,14 +290,18 @@ describe('activity-reaction-utils', () => {
|
|
|
290
290
|
const result = addReactionToActivities(event, undefined, true);
|
|
291
291
|
|
|
292
292
|
expect(result.changed).toBe(false);
|
|
293
|
-
expect(result.
|
|
293
|
+
expect(result.entities).toBeUndefined();
|
|
294
294
|
});
|
|
295
295
|
});
|
|
296
296
|
|
|
297
297
|
describe('removeReactionFromActivities', () => {
|
|
298
298
|
it('should remove reaction from activity in activities array', () => {
|
|
299
|
-
const activity =
|
|
300
|
-
const reaction =
|
|
299
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
300
|
+
const reaction = generateFeedReactionResponse({
|
|
301
|
+
type: 'like',
|
|
302
|
+
user: { id: 'user1' },
|
|
303
|
+
activity_id: 'activity1',
|
|
304
|
+
});
|
|
301
305
|
const eventActivity = { ...activity };
|
|
302
306
|
eventActivity.latest_reactions = [reaction];
|
|
303
307
|
eventActivity.reaction_groups = {
|
|
@@ -323,15 +327,19 @@ describe('activity-reaction-utils', () => {
|
|
|
323
327
|
);
|
|
324
328
|
|
|
325
329
|
expect(result.changed).toBe(true);
|
|
326
|
-
expect(result.
|
|
327
|
-
expect(result.
|
|
330
|
+
expect(result.entities).toHaveLength(1);
|
|
331
|
+
expect(result.entities![0].own_reactions).toHaveLength(0);
|
|
328
332
|
});
|
|
329
333
|
|
|
330
334
|
it('should return unchanged state if activity not found', () => {
|
|
331
|
-
const activity =
|
|
335
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
332
336
|
const activities = [activity];
|
|
333
|
-
const reaction =
|
|
334
|
-
|
|
337
|
+
const reaction = generateFeedReactionResponse({
|
|
338
|
+
type: 'like',
|
|
339
|
+
user: { id: 'user1' },
|
|
340
|
+
activity_id: 'activity2',
|
|
341
|
+
});
|
|
342
|
+
const eventActivity = generateActivityResponse({ id: 'activity2' });
|
|
335
343
|
eventActivity.latest_reactions = [];
|
|
336
344
|
eventActivity.reaction_groups = {};
|
|
337
345
|
const event = createMockDeletedEvent(reaction, eventActivity);
|
|
@@ -339,12 +347,16 @@ describe('activity-reaction-utils', () => {
|
|
|
339
347
|
const result = removeReactionFromActivities(event, activities, true);
|
|
340
348
|
|
|
341
349
|
expect(result.changed).toBe(false);
|
|
342
|
-
expect(result.
|
|
350
|
+
expect(result.entities).toBe(activities);
|
|
343
351
|
});
|
|
344
352
|
|
|
345
353
|
it('should handle undefined activities', () => {
|
|
346
|
-
const activity =
|
|
347
|
-
const reaction =
|
|
354
|
+
const activity = generateActivityResponse({ id: 'activity1' });
|
|
355
|
+
const reaction = generateFeedReactionResponse({
|
|
356
|
+
type: 'like',
|
|
357
|
+
user: { id: 'user1' },
|
|
358
|
+
activity_id: 'activity1',
|
|
359
|
+
});
|
|
348
360
|
const eventActivity = { ...activity };
|
|
349
361
|
eventActivity.latest_reactions = [];
|
|
350
362
|
eventActivity.reaction_groups = {};
|
|
@@ -353,7 +365,7 @@ describe('activity-reaction-utils', () => {
|
|
|
353
365
|
const result = removeReactionFromActivities(event, undefined, true);
|
|
354
366
|
|
|
355
367
|
expect(result.changed).toBe(false);
|
|
356
|
-
expect(result.
|
|
368
|
+
expect(result.entities).toBeUndefined();
|
|
357
369
|
});
|
|
358
370
|
});
|
|
359
371
|
});
|