@amityco/ts-sdk 0.0.1-ce7eebc.0 → 0.0.1-ce96c83.0
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/dist/cache/api/tests/enableCache.test.d.ts +2 -0
- package/dist/cache/api/tests/enableCache.test.d.ts.map +1 -0
- package/dist/channel/events/tests/onChannelCreated.test.d.ts +2 -0
- package/dist/channel/events/tests/onChannelCreated.test.d.ts.map +1 -0
- package/dist/channel/events/tests/onChannelJoined.test.d.ts +2 -0
- package/dist/channel/events/tests/onChannelJoined.test.d.ts.map +1 -0
- package/dist/channel/events/tests/onChannelMemberAdded.test.d.ts +2 -0
- package/dist/channel/events/tests/onChannelMemberAdded.test.d.ts.map +1 -0
- package/dist/channel/events/tests/onChannelMemberRemoved.test.d.ts +2 -0
- package/dist/channel/events/tests/onChannelMemberRemoved.test.d.ts.map +1 -0
- package/dist/channel/events/tests/onChannelUpdated.test.d.ts +2 -0
- package/dist/channel/events/tests/onChannelUpdated.test.d.ts.map +1 -0
- package/dist/client/api/tests/createClient.test.d.ts +2 -0
- package/dist/client/api/tests/createClient.test.d.ts.map +1 -0
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/api/test/addCommunityMember.test.d.ts +2 -0
- package/dist/community/api/test/addCommunityMember.test.d.ts.map +1 -0
- package/dist/community/api/test/addCommunityMemberRole.test.d.ts +2 -0
- package/dist/community/api/test/addCommunityMemberRole.test.d.ts.map +1 -0
- package/dist/community/api/test/createCommunity.test.d.ts +2 -0
- package/dist/community/api/test/createCommunity.test.d.ts.map +1 -0
- package/dist/community/api/test/deleteCommunity.test.d.ts +2 -0
- package/dist/community/api/test/deleteCommunity.test.d.ts.map +1 -0
- package/dist/community/api/test/getCommunities.test.d.ts +2 -0
- package/dist/community/api/test/getCommunities.test.d.ts.map +1 -0
- package/dist/community/api/test/getCommunity.test.d.ts +2 -0
- package/dist/community/api/test/getCommunity.test.d.ts.map +1 -0
- package/dist/community/api/test/getRecommendedCommunities.test.d.ts +2 -0
- package/dist/community/api/test/getRecommendedCommunities.test.d.ts.map +1 -0
- package/dist/community/api/test/getTopTrendingCommunities.test.d.ts +2 -0
- package/dist/community/api/test/getTopTrendingCommunities.test.d.ts.map +1 -0
- package/dist/community/api/test/joinCommunity.test.d.ts +2 -0
- package/dist/community/api/test/joinCommunity.test.d.ts.map +1 -0
- package/dist/community/api/test/leaveCommunity.test.d.ts +2 -0
- package/dist/community/api/test/leaveCommunity.test.d.ts.map +1 -0
- package/dist/community/api/test/queryCommunity.test.d.ts +2 -0
- package/dist/community/api/test/queryCommunity.test.d.ts.map +1 -0
- package/dist/community/api/test/removeCommunityMemberRole.test.d.ts +2 -0
- package/dist/community/api/test/removeCommunityMemberRole.test.d.ts.map +1 -0
- package/dist/community/api/test/removeCommunityMembers.test.d.ts +2 -0
- package/dist/community/api/test/removeCommunityMembers.test.d.ts.map +1 -0
- package/dist/community/api/test/updateCommunity.test.d.ts +2 -0
- package/dist/community/api/test/updateCommunity.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityCreated.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityCreated.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityDeleted.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityDeleted.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityJoined.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityJoined.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityLeft.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityLeft.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityUpdated.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityUpdated.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityUserAdded.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityUserAdded.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityUserBanned.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityUserBanned.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityUserRemoved.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityUserRemoved.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityUserUnbaned.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityUserUnbaned.test.d.ts.map +1 -0
- package/dist/community/events/test/utils.test.d.ts +2 -0
- package/dist/community/events/test/utils.test.d.ts.map +1 -0
- package/dist/index.cjs.js +6 -3
- package/dist/index.esm.js +6 -3
- package/dist/index.umd.js +1 -1
- package/dist/post/events/tests/onPostFlagged.test.d.ts +2 -0
- package/dist/post/events/tests/onPostFlagged.test.d.ts.map +1 -0
- package/dist/post/events/tests/onPostReactionAdded.test.d.ts +2 -0
- package/dist/post/events/tests/onPostReactionAdded.test.d.ts.map +1 -0
- package/dist/post/events/tests/onPostReactionRemoved.test.d.ts +2 -0
- package/dist/post/events/tests/onPostReactionRemoved.test.d.ts.map +1 -0
- package/dist/post/events/tests/onPostUnflagged.test.d.ts +2 -0
- package/dist/post/events/tests/onPostUnflagged.test.d.ts.map +1 -0
- package/dist/post/events/tests/onPostUpdated.test.d.ts +2 -0
- package/dist/post/events/tests/onPostUpdated.test.d.ts.map +1 -0
- package/dist/post/observers/livePosts.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +2 -0
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cache/api/tests/enableCache.test.ts +15 -0
- package/src/channel/events/tests/onChannelCreated.test.ts +60 -0
- package/src/channel/events/tests/onChannelJoined.test.ts +60 -0
- package/src/channel/events/tests/onChannelMemberAdded.test.ts +59 -0
- package/src/channel/events/tests/onChannelMemberRemoved.test.ts +59 -0
- package/src/channel/events/tests/onChannelUpdated.test.ts +58 -0
- package/src/client/api/createClient.ts +1 -1
- package/src/client/api/tests/createClient.test.ts +40 -0
- package/src/community/api/queryCommunities.ts +3 -2
- package/src/community/api/test/addCommunityMember.test.ts +71 -0
- package/src/community/api/test/addCommunityMemberRole.test.ts +67 -0
- package/src/community/api/test/createCommunity.test.ts +61 -0
- package/src/community/api/test/deleteCommunity.test.ts +74 -0
- package/src/community/api/test/getCommunities.test.ts +73 -0
- package/src/community/api/test/getCommunity.test.ts +69 -0
- package/src/community/api/test/getRecommendedCommunities.test.ts +102 -0
- package/src/community/api/test/getTopTrendingCommunities.test.ts +102 -0
- package/src/community/api/test/joinCommunity.test.ts +70 -0
- package/src/community/api/test/leaveCommunity.test.ts +78 -0
- package/src/community/api/test/queryCommunity.test.ts +108 -0
- package/src/community/api/test/removeCommunityMemberRole.test.ts +67 -0
- package/src/community/api/test/removeCommunityMembers.test.ts +75 -0
- package/src/community/api/test/updateCommunity.test.ts +65 -0
- package/src/community/events/test/onCommunityCreated.test.ts +46 -0
- package/src/community/events/test/onCommunityDeleted.test.ts +35 -0
- package/src/community/events/test/onCommunityJoined.test.ts +50 -0
- package/src/community/events/test/onCommunityLeft.test.ts +50 -0
- package/src/community/events/test/onCommunityUpdated.test.ts +49 -0
- package/src/community/events/test/onCommunityUserAdded.test.ts +50 -0
- package/src/community/events/test/onCommunityUserBanned.test.ts +50 -0
- package/src/community/events/test/onCommunityUserRemoved.test.ts +50 -0
- package/src/community/events/test/onCommunityUserUnbaned.test.ts +50 -0
- package/src/community/events/test/utils.test.ts +158 -0
- package/src/post/events/tests/onPostFlagged.test.ts +33 -0
- package/src/post/events/tests/onPostReactionAdded.test.ts +40 -0
- package/src/post/events/tests/onPostReactionRemoved.test.ts +40 -0
- package/src/post/events/tests/onPostUnflagged.test.ts +33 -0
- package/src/post/events/tests/onPostUpdated.test.ts +33 -0
- package/src/post/observers/livePosts.ts +3 -0
- package/src/post/observers/tests/livePosts.test.ts +24 -0
- package/src/utils/tests/dummy/community.ts +17 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
2
|
+
import { getResolver } from '~/core/model';
|
|
3
|
+
import { withUser } from '~/group/utils';
|
|
4
|
+
import {
|
|
5
|
+
client,
|
|
6
|
+
community11,
|
|
7
|
+
communityUser11,
|
|
8
|
+
connectClient,
|
|
9
|
+
disconnectClient,
|
|
10
|
+
user11,
|
|
11
|
+
} from '~/utils/tests';
|
|
12
|
+
|
|
13
|
+
import { createCommunityEventSubscriber, createCommunityMemberEventSubscriber } from '../utils';
|
|
14
|
+
|
|
15
|
+
const event = 'community.created';
|
|
16
|
+
const communityToCreate = community11;
|
|
17
|
+
|
|
18
|
+
const eventPayload: Amity.CommunityPayload = {
|
|
19
|
+
communities: [communityToCreate],
|
|
20
|
+
communityUsers: [communityUser11],
|
|
21
|
+
files: [],
|
|
22
|
+
users: [],
|
|
23
|
+
categories: [],
|
|
24
|
+
feeds: [],
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('createCommunityEventSubscriber', () => {
|
|
28
|
+
beforeAll(connectClient);
|
|
29
|
+
afterAll(disconnectClient);
|
|
30
|
+
|
|
31
|
+
test('it should return event subscriber', () => {
|
|
32
|
+
const callback = jest.fn();
|
|
33
|
+
const received = createCommunityEventSubscriber(event, callback);
|
|
34
|
+
|
|
35
|
+
expect(received).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('it should trigger callback with correctly params when cache is disabled', () => {
|
|
39
|
+
disableCache();
|
|
40
|
+
|
|
41
|
+
const callback = jest.fn();
|
|
42
|
+
const unsub = createCommunityEventSubscriber(event, callback);
|
|
43
|
+
client.emitter.emit(event, eventPayload);
|
|
44
|
+
|
|
45
|
+
unsub();
|
|
46
|
+
|
|
47
|
+
expect(callback).toHaveBeenCalled();
|
|
48
|
+
expect(callback).toHaveBeenCalledWith(communityToCreate);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('it should trigger callback with correctly params when cache is enabled', () => {
|
|
52
|
+
enableCache();
|
|
53
|
+
|
|
54
|
+
const callback = jest.fn();
|
|
55
|
+
const unsub = createCommunityEventSubscriber(event, callback);
|
|
56
|
+
client.emitter.emit(event, eventPayload);
|
|
57
|
+
|
|
58
|
+
unsub();
|
|
59
|
+
|
|
60
|
+
expect(callback).toHaveBeenCalled();
|
|
61
|
+
expect(callback).toHaveBeenCalledWith(communityToCreate);
|
|
62
|
+
|
|
63
|
+
disableCache();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('it should ingest cache', () => {
|
|
67
|
+
enableCache();
|
|
68
|
+
|
|
69
|
+
const callback = jest.fn();
|
|
70
|
+
const unsub = createCommunityEventSubscriber(event, callback);
|
|
71
|
+
client.emitter.emit(event, eventPayload);
|
|
72
|
+
|
|
73
|
+
unsub();
|
|
74
|
+
|
|
75
|
+
const recieved = pullFromCache(['community', 'get', communityToCreate.communityId])?.data;
|
|
76
|
+
|
|
77
|
+
expect(recieved).toEqual(communityToCreate);
|
|
78
|
+
|
|
79
|
+
disableCache();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const event2 = 'community.userAdded';
|
|
84
|
+
const communityToAddUser = community11;
|
|
85
|
+
const addedUserRaw = communityUser11;
|
|
86
|
+
const addedUser = withUser(addedUserRaw);
|
|
87
|
+
|
|
88
|
+
const eventPayload2: Amity.CommunityMembershipPayload = {
|
|
89
|
+
communities: [communityToAddUser],
|
|
90
|
+
communityUsers: [addedUserRaw],
|
|
91
|
+
files: [],
|
|
92
|
+
users: [user11],
|
|
93
|
+
categories: [],
|
|
94
|
+
feeds: [],
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
describe('createCommunityMemberEventSubscriber', () => {
|
|
98
|
+
beforeAll(connectClient);
|
|
99
|
+
afterAll(disconnectClient);
|
|
100
|
+
|
|
101
|
+
test('it should return event subscriber', () => {
|
|
102
|
+
const callback = jest.fn();
|
|
103
|
+
const received = createCommunityMemberEventSubscriber(event2, callback);
|
|
104
|
+
|
|
105
|
+
expect(received).toBeDefined();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('it should trigger callback with correctly params when cache is disabled', () => {
|
|
109
|
+
disableCache();
|
|
110
|
+
|
|
111
|
+
const callback = jest.fn();
|
|
112
|
+
const unsub = createCommunityMemberEventSubscriber(event2, callback);
|
|
113
|
+
client.emitter.emit(event2, eventPayload2);
|
|
114
|
+
|
|
115
|
+
unsub();
|
|
116
|
+
|
|
117
|
+
expect(callback).toHaveBeenCalled();
|
|
118
|
+
expect(callback).toHaveBeenCalledWith(communityToAddUser, addedUser);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('it should trigger callback with correctly params when cache is enabled', () => {
|
|
122
|
+
enableCache();
|
|
123
|
+
|
|
124
|
+
const callback = jest.fn();
|
|
125
|
+
const unsub = createCommunityMemberEventSubscriber(event2, callback);
|
|
126
|
+
client.emitter.emit(event2, eventPayload2);
|
|
127
|
+
|
|
128
|
+
unsub();
|
|
129
|
+
|
|
130
|
+
expect(callback).toHaveBeenCalled();
|
|
131
|
+
expect(callback).toHaveBeenCalledWith(communityToAddUser, addedUser);
|
|
132
|
+
|
|
133
|
+
disableCache();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('it should ingest cache', () => {
|
|
137
|
+
enableCache();
|
|
138
|
+
|
|
139
|
+
const callback = jest.fn();
|
|
140
|
+
const unsub = createCommunityMemberEventSubscriber(event2, callback);
|
|
141
|
+
client.emitter.emit(event2, eventPayload2);
|
|
142
|
+
|
|
143
|
+
unsub();
|
|
144
|
+
|
|
145
|
+
const recieved = pullFromCache([
|
|
146
|
+
'communityUsers',
|
|
147
|
+
'get',
|
|
148
|
+
getResolver('communityUsers')({
|
|
149
|
+
communityId: communityToAddUser.communityId,
|
|
150
|
+
userId: addedUser.userId,
|
|
151
|
+
}),
|
|
152
|
+
])?.data;
|
|
153
|
+
|
|
154
|
+
expect(recieved).toEqual(addedUser);
|
|
155
|
+
|
|
156
|
+
disableCache();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { onPostFlagged } from '../onPostFlagged';
|
|
2
|
+
import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
describe('onPostFlagged', () => {
|
|
5
|
+
beforeAll(async () => {
|
|
6
|
+
await connectClient();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
afterAll(async () => {
|
|
10
|
+
await disconnectClient();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('it should got event after post flagged', () => {
|
|
14
|
+
const callback = jest.fn();
|
|
15
|
+
const unsub = onPostFlagged(callback);
|
|
16
|
+
client.emitter.emit('post.flagged', postPayload);
|
|
17
|
+
|
|
18
|
+
unsub();
|
|
19
|
+
|
|
20
|
+
expect(callback).toHaveBeenCalled();
|
|
21
|
+
expect(callback).toHaveBeenCalledWith(post11);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
25
|
+
const callback = jest.fn();
|
|
26
|
+
const unsub = onPostFlagged(callback);
|
|
27
|
+
|
|
28
|
+
unsub();
|
|
29
|
+
|
|
30
|
+
client.emitter.emit('post.flagged', postPayload);
|
|
31
|
+
expect(callback).not.toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { onPostReactionAdded } from '../onPostReactionAdded';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
postPayload,
|
|
7
|
+
post11,
|
|
8
|
+
reaction11,
|
|
9
|
+
} from '~/utils/tests';
|
|
10
|
+
|
|
11
|
+
describe('onPostReactionAdded', () => {
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
await connectClient();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterAll(async () => {
|
|
17
|
+
await disconnectClient();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('it should got event after add reaction to post', () => {
|
|
21
|
+
const callback = jest.fn();
|
|
22
|
+
const unsub = onPostReactionAdded(callback);
|
|
23
|
+
client.emitter.emit('post.addReaction', { ...postPayload, reactor: reaction11 });
|
|
24
|
+
|
|
25
|
+
unsub();
|
|
26
|
+
|
|
27
|
+
expect(callback).toHaveBeenCalled();
|
|
28
|
+
expect(callback).toHaveBeenCalledWith(post11);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
32
|
+
const callback = jest.fn();
|
|
33
|
+
const unsub = onPostReactionAdded(callback);
|
|
34
|
+
|
|
35
|
+
unsub();
|
|
36
|
+
|
|
37
|
+
client.emitter.emit('post.addReaction', { ...postPayload, reactor: reaction11 });
|
|
38
|
+
expect(callback).not.toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { onPostReactionRemoved } from '../onPostReactionRemoved';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
postPayload,
|
|
7
|
+
post11,
|
|
8
|
+
reaction11,
|
|
9
|
+
} from '~/utils/tests';
|
|
10
|
+
|
|
11
|
+
describe('onPostReactionRemoved', () => {
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
await connectClient();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterAll(async () => {
|
|
17
|
+
await disconnectClient();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('it should got event after reaction got removed from post', () => {
|
|
21
|
+
const callback = jest.fn();
|
|
22
|
+
const unsub = onPostReactionRemoved(callback);
|
|
23
|
+
client.emitter.emit('post.removeReaction', { ...postPayload, reactor: reaction11 });
|
|
24
|
+
|
|
25
|
+
unsub();
|
|
26
|
+
|
|
27
|
+
expect(callback).toHaveBeenCalled();
|
|
28
|
+
expect(callback).toHaveBeenCalledWith(post11);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
32
|
+
const callback = jest.fn();
|
|
33
|
+
const unsub = onPostReactionRemoved(callback);
|
|
34
|
+
|
|
35
|
+
unsub();
|
|
36
|
+
|
|
37
|
+
client.emitter.emit('post.removeReaction', { ...postPayload, reactor: reaction11 });
|
|
38
|
+
expect(callback).not.toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { onPostUnflagged } from '../onPostUnflagged';
|
|
2
|
+
import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
describe('onPostUnflagged', () => {
|
|
5
|
+
beforeAll(async () => {
|
|
6
|
+
await connectClient();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
afterAll(async () => {
|
|
10
|
+
await disconnectClient();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('it should got event after post unflagged', () => {
|
|
14
|
+
const callback = jest.fn();
|
|
15
|
+
const unsub = onPostUnflagged(callback);
|
|
16
|
+
client.emitter.emit('post.unflagged', postPayload);
|
|
17
|
+
|
|
18
|
+
unsub();
|
|
19
|
+
|
|
20
|
+
expect(callback).toHaveBeenCalled();
|
|
21
|
+
expect(callback).toHaveBeenCalledWith(post11);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
25
|
+
const callback = jest.fn();
|
|
26
|
+
const unsub = onPostUnflagged(callback);
|
|
27
|
+
|
|
28
|
+
unsub();
|
|
29
|
+
|
|
30
|
+
client.emitter.emit('post.unflagged', postPayload);
|
|
31
|
+
expect(callback).not.toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { onPostUpdated } from '../onPostUpdated';
|
|
2
|
+
import { client, connectClient, disconnectClient, postPayload, post11 } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
describe('onPostUpdated', () => {
|
|
5
|
+
beforeAll(async () => {
|
|
6
|
+
await connectClient();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
afterAll(async () => {
|
|
10
|
+
await disconnectClient();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('it should got event after post updated', () => {
|
|
14
|
+
const callback = jest.fn();
|
|
15
|
+
const unsub = onPostUpdated(callback);
|
|
16
|
+
client.emitter.emit('post.updated', postPayload);
|
|
17
|
+
|
|
18
|
+
unsub();
|
|
19
|
+
|
|
20
|
+
expect(callback).toHaveBeenCalled();
|
|
21
|
+
expect(callback).toHaveBeenCalledWith(post11);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
25
|
+
const callback = jest.fn();
|
|
26
|
+
const unsub = onPostUpdated(callback);
|
|
27
|
+
|
|
28
|
+
unsub();
|
|
29
|
+
|
|
30
|
+
client.emitter.emit('post.updated', postPayload);
|
|
31
|
+
expect(callback).not.toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -120,6 +120,9 @@ export const livePosts = (
|
|
|
120
120
|
if (params.isDeleted) collection.data.unshift(post.postId);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
if (params.feedType === 'reviewing' && action === 'onApproved')
|
|
124
|
+
collection.data = collection.data.filter(p => p !== post.postId);
|
|
125
|
+
|
|
123
126
|
pushToCache(cacheKey, collection);
|
|
124
127
|
|
|
125
128
|
responder(collection);
|
|
@@ -270,4 +270,28 @@ describe('livePosts', () => {
|
|
|
270
270
|
snapshot.data = [deletedPost, ...payload];
|
|
271
271
|
expect(callback).toHaveBeenNthCalledWith(3, expect.objectContaining(snapshot));
|
|
272
272
|
});
|
|
273
|
+
|
|
274
|
+
test('it should remove approved post when feedtype reviewing', async () => {
|
|
275
|
+
const approvedPost = post11;
|
|
276
|
+
const callback = jest.fn();
|
|
277
|
+
client.http.get = jest.fn().mockResolvedValue(postQueryResponsePage2);
|
|
278
|
+
|
|
279
|
+
livePosts({ ...params, feedType: 'reviewing' }, callback);
|
|
280
|
+
|
|
281
|
+
await pause();
|
|
282
|
+
const payload = postQueryResponsePage2.data.posts;
|
|
283
|
+
const snapshot = getSnapshot();
|
|
284
|
+
|
|
285
|
+
snapshot.data = payload;
|
|
286
|
+
snapshot.loading = false;
|
|
287
|
+
|
|
288
|
+
expect(callback).toHaveBeenNthCalledWith(2, expect.objectContaining(snapshot));
|
|
289
|
+
|
|
290
|
+
client.emitter.emit('post.approved', {
|
|
291
|
+
posts: [approvedPost],
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
snapshot.data = payload.filter(({ postId }) => postId !== approvedPost.postId);
|
|
295
|
+
expect(callback).toHaveBeenNthCalledWith(3, expect.objectContaining(snapshot));
|
|
296
|
+
});
|
|
273
297
|
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DefaultCommunityPostSetting } from '~/@types';
|
|
2
|
+
|
|
3
|
+
import { baseMembership, date, user11, user12, file11, user13 } from '.';
|
|
2
4
|
|
|
3
5
|
const mockPage: Amity.Pagination = {
|
|
4
6
|
paging: {
|
|
@@ -19,6 +21,7 @@ export const baseCommunity: Amity.Community = {
|
|
|
19
21
|
path: '',
|
|
20
22
|
postsCount: 0,
|
|
21
23
|
userId: '',
|
|
24
|
+
postSetting: DefaultCommunityPostSetting,
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
export const community11: Amity.Community = {
|
|
@@ -43,6 +46,12 @@ export const community11: Amity.Community = {
|
|
|
43
46
|
categoryIds: [],
|
|
44
47
|
};
|
|
45
48
|
|
|
49
|
+
export const community21: Amity.Community = {
|
|
50
|
+
...baseCommunity,
|
|
51
|
+
communityId: 'community21',
|
|
52
|
+
displayName: 'Community21',
|
|
53
|
+
};
|
|
54
|
+
|
|
46
55
|
export const communityUser11: Amity.MembershipRaw<'community'> = {
|
|
47
56
|
...baseMembership,
|
|
48
57
|
communityMembership: 'member',
|
|
@@ -67,6 +76,13 @@ export const communityUser12: Amity.MembershipRaw<'community'> = {
|
|
|
67
76
|
communityMembership: 'member',
|
|
68
77
|
};
|
|
69
78
|
|
|
79
|
+
export const communityUser21: Amity.MembershipRaw<'community'> = {
|
|
80
|
+
...baseMembership,
|
|
81
|
+
userId: user13.userId,
|
|
82
|
+
communityId: community21.communityId,
|
|
83
|
+
communityMembership: 'member',
|
|
84
|
+
};
|
|
85
|
+
|
|
70
86
|
export const communityPayload: Amity.CommunityPayload = {
|
|
71
87
|
communities: [community11],
|
|
72
88
|
communityUsers: [communityUser11],
|