@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,67 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
2
|
+
import { getResolver } from '~/core/model';
|
|
3
|
+
|
|
4
|
+
import { client, community11, communityUser11, user11 } from '~/utils/tests';
|
|
5
|
+
|
|
6
|
+
import { removeCommunityMembersRoles } from '../removeCommunityMembersRoles';
|
|
7
|
+
|
|
8
|
+
const community = community11;
|
|
9
|
+
const roleToRemove = 'some-exist-role';
|
|
10
|
+
const userToRemoveRole = { ...communityUser11, roles: [...communityUser11.roles, roleToRemove] };
|
|
11
|
+
const removedRoleUser = { ...communityUser11 };
|
|
12
|
+
|
|
13
|
+
const resolvedDeleteValue = {
|
|
14
|
+
data: {
|
|
15
|
+
communities: [community],
|
|
16
|
+
communityUsers: [removedRoleUser],
|
|
17
|
+
files: [],
|
|
18
|
+
users: [user11],
|
|
19
|
+
categories: [],
|
|
20
|
+
feeds: [],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('removeCommunityMembersRoles', () => {
|
|
25
|
+
test('should return true', async () => {
|
|
26
|
+
client.http.delete = jest.fn().mockResolvedValue(resolvedDeleteValue);
|
|
27
|
+
|
|
28
|
+
const recieved = removeCommunityMembersRoles(
|
|
29
|
+
community.communityId,
|
|
30
|
+
[roleToRemove],
|
|
31
|
+
[userToRemoveRole.userId],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
await expect(recieved).resolves.toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should throw an error if request fails', async () => {
|
|
38
|
+
client.http.delete = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
39
|
+
|
|
40
|
+
await expect(
|
|
41
|
+
removeCommunityMembersRoles(community.communityId, [roleToRemove], [userToRemoveRole.userId]),
|
|
42
|
+
).rejects.toThrow('error');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('should create cache after added user', async () => {
|
|
46
|
+
enableCache();
|
|
47
|
+
client.http.delete = jest.fn().mockResolvedValue(resolvedDeleteValue);
|
|
48
|
+
|
|
49
|
+
await removeCommunityMembersRoles(
|
|
50
|
+
community.communityId,
|
|
51
|
+
[roleToRemove],
|
|
52
|
+
[userToRemoveRole.userId],
|
|
53
|
+
);
|
|
54
|
+
const recieved = pullFromCache([
|
|
55
|
+
'communityUsers',
|
|
56
|
+
'get',
|
|
57
|
+
getResolver('communityUsers')({
|
|
58
|
+
communityId: community.communityId,
|
|
59
|
+
userId: userToRemoveRole.userId,
|
|
60
|
+
}),
|
|
61
|
+
])?.data;
|
|
62
|
+
|
|
63
|
+
expect(recieved).toEqual(expect.objectContaining(removedRoleUser));
|
|
64
|
+
|
|
65
|
+
disableCache();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
2
|
+
import { getResolver } from '~/core/model';
|
|
3
|
+
|
|
4
|
+
import { client, community11, communityUser11, user11 } from '~/utils/tests';
|
|
5
|
+
|
|
6
|
+
import { onCommunityUserRemoved } from '../../events';
|
|
7
|
+
import { removeCommunityMembers } from '../removeCommunityMembers';
|
|
8
|
+
|
|
9
|
+
const communityToRemoveUser = community11;
|
|
10
|
+
const userToRemove = communityUser11;
|
|
11
|
+
const removedUser = { ...communityUser11, communityMembership: 'none' };
|
|
12
|
+
|
|
13
|
+
const resolvedDeleteValue = {
|
|
14
|
+
data: {
|
|
15
|
+
communities: [communityToRemoveUser],
|
|
16
|
+
communityUsers: [removedUser],
|
|
17
|
+
files: [],
|
|
18
|
+
users: [user11],
|
|
19
|
+
categories: [],
|
|
20
|
+
feeds: [],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
describe('removeCommunityMembers', () => {
|
|
25
|
+
test('should return true value', async () => {
|
|
26
|
+
client.http.delete = jest.fn().mockResolvedValue(resolvedDeleteValue);
|
|
27
|
+
|
|
28
|
+
const recieved = removeCommunityMembers(communityToRemoveUser.communityId, [
|
|
29
|
+
userToRemove.userId,
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
await expect(recieved).resolves.toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should throw an error if request fails', async () => {
|
|
36
|
+
client.http.delete = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
37
|
+
|
|
38
|
+
await expect(
|
|
39
|
+
removeCommunityMembers(communityToRemoveUser.communityId, [userToRemove.userId]),
|
|
40
|
+
).rejects.toThrow('error');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('should create cache after removed user', async () => {
|
|
44
|
+
enableCache();
|
|
45
|
+
client.http.delete = jest.fn().mockResolvedValue(resolvedDeleteValue);
|
|
46
|
+
|
|
47
|
+
await removeCommunityMembers(communityToRemoveUser.communityId, [userToRemove.userId]);
|
|
48
|
+
|
|
49
|
+
const recieved = pullFromCache([
|
|
50
|
+
'communityUsers',
|
|
51
|
+
'get',
|
|
52
|
+
getResolver('communityUsers')({
|
|
53
|
+
communityId: communityToRemoveUser.communityId,
|
|
54
|
+
userId: userToRemove.userId,
|
|
55
|
+
}),
|
|
56
|
+
])?.data;
|
|
57
|
+
|
|
58
|
+
expect(recieved).toEqual(expect.objectContaining(removedUser));
|
|
59
|
+
|
|
60
|
+
disableCache();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('should fire event `onCommunityUserRemoved`', async () => {
|
|
64
|
+
let dispose;
|
|
65
|
+
client.http.delete = jest.fn().mockResolvedValueOnce(resolvedDeleteValue);
|
|
66
|
+
|
|
67
|
+
const callback = new Promise(resolve => {
|
|
68
|
+
dispose = onCommunityUserRemoved(resolve);
|
|
69
|
+
}).finally(dispose);
|
|
70
|
+
|
|
71
|
+
await removeCommunityMembers(communityToRemoveUser.communityId, [userToRemove.userId]);
|
|
72
|
+
|
|
73
|
+
await expect(callback).resolves.toEqual(expect.objectContaining(communityToRemoveUser));
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
2
|
+
import { client, community11, communityUser11, user11 } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
import { updateCommunity } from '../updateCommunity';
|
|
5
|
+
import { onCommunityUpdated } from '../../events';
|
|
6
|
+
|
|
7
|
+
const communityToUpdate = community11;
|
|
8
|
+
const patch = { displayName: 'new-display-name' };
|
|
9
|
+
const updatedCommunity = { ...communityToUpdate, ...patch };
|
|
10
|
+
|
|
11
|
+
const resolvedPutValue = {
|
|
12
|
+
data: {
|
|
13
|
+
communities: [updatedCommunity],
|
|
14
|
+
communityUsers: [communityUser11],
|
|
15
|
+
files: [],
|
|
16
|
+
users: [user11],
|
|
17
|
+
categories: [],
|
|
18
|
+
feeds: [],
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('updateCommunity', () => {
|
|
23
|
+
test('should return updated community', async () => {
|
|
24
|
+
client.http.put = jest.fn().mockResolvedValueOnce(resolvedPutValue);
|
|
25
|
+
|
|
26
|
+
const recieved = updateCommunity(communityToUpdate.communityId, patch);
|
|
27
|
+
|
|
28
|
+
await expect(recieved).resolves.toEqual(expect.objectContaining({ data: updatedCommunity }));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('should throw an error if request fails', async () => {
|
|
32
|
+
client.http.put = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
33
|
+
|
|
34
|
+
await expect(updateCommunity(communityToUpdate.communityId, patch)).rejects.toThrow('error');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should update cache after updated community', async () => {
|
|
38
|
+
enableCache();
|
|
39
|
+
client.http.put = jest.fn().mockResolvedValueOnce(resolvedPutValue);
|
|
40
|
+
|
|
41
|
+
await updateCommunity(communityToUpdate.communityId, patch);
|
|
42
|
+
const recieved = pullFromCache<Amity.Community>([
|
|
43
|
+
'community',
|
|
44
|
+
'get',
|
|
45
|
+
communityToUpdate.communityId,
|
|
46
|
+
])?.data;
|
|
47
|
+
|
|
48
|
+
expect(recieved).toEqual(expect.objectContaining(updatedCommunity));
|
|
49
|
+
|
|
50
|
+
disableCache();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('should fire event `onCommunityUpdated`', async () => {
|
|
54
|
+
let dispose;
|
|
55
|
+
client.http.put = jest.fn().mockResolvedValueOnce(resolvedPutValue);
|
|
56
|
+
|
|
57
|
+
const callbackPromise = new Promise(resolve => {
|
|
58
|
+
dispose = onCommunityUpdated(resolve);
|
|
59
|
+
}).finally(dispose);
|
|
60
|
+
|
|
61
|
+
await updateCommunity(updatedCommunity.communityId, patch);
|
|
62
|
+
|
|
63
|
+
await expect(callbackPromise).resolves.toEqual(expect.objectContaining(updatedCommunity));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
client,
|
|
3
|
+
connectClient,
|
|
4
|
+
disconnectClient,
|
|
5
|
+
community11,
|
|
6
|
+
communityUser11,
|
|
7
|
+
} from '~/utils/tests';
|
|
8
|
+
|
|
9
|
+
import { onCommunityCreated } from '../onCommunityCreated';
|
|
10
|
+
|
|
11
|
+
const communityToCreate = community11;
|
|
12
|
+
|
|
13
|
+
const eventPayload: Amity.CommunityPayload = {
|
|
14
|
+
communities: [communityToCreate],
|
|
15
|
+
communityUsers: [communityUser11],
|
|
16
|
+
files: [],
|
|
17
|
+
users: [],
|
|
18
|
+
categories: [],
|
|
19
|
+
feeds: [],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('onCommunityCreated', () => {
|
|
23
|
+
beforeAll(connectClient);
|
|
24
|
+
afterAll(disconnectClient);
|
|
25
|
+
|
|
26
|
+
test('it should got event after community created', () => {
|
|
27
|
+
const callback = jest.fn();
|
|
28
|
+
const unsub = onCommunityCreated(callback);
|
|
29
|
+
client.emitter.emit('community.created', eventPayload);
|
|
30
|
+
|
|
31
|
+
unsub();
|
|
32
|
+
|
|
33
|
+
expect(callback).toHaveBeenCalled();
|
|
34
|
+
expect(callback).toHaveBeenCalledWith(communityToCreate);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
38
|
+
const callback = jest.fn();
|
|
39
|
+
const unsub = onCommunityCreated(callback);
|
|
40
|
+
|
|
41
|
+
unsub();
|
|
42
|
+
|
|
43
|
+
client.emitter.emit('community.created', eventPayload);
|
|
44
|
+
expect(callback).not.toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { client, connectClient, disconnectClient, community11 } from '~/utils/tests';
|
|
2
|
+
|
|
3
|
+
import { onCommunityDeleted } from '../onCommunityDeleted';
|
|
4
|
+
|
|
5
|
+
const deletedCommunity = { ...community11, isDeleted: true };
|
|
6
|
+
|
|
7
|
+
const eventPayload: Amity.CommunityPayload = {
|
|
8
|
+
communities: [deletedCommunity],
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe('onCommunityDeleted', () => {
|
|
12
|
+
beforeAll(connectClient);
|
|
13
|
+
afterAll(disconnectClient);
|
|
14
|
+
|
|
15
|
+
test('it should got event after community deleted', () => {
|
|
16
|
+
const callback = jest.fn();
|
|
17
|
+
const unsub = onCommunityDeleted(callback);
|
|
18
|
+
client.emitter.emit('community.deleted', eventPayload);
|
|
19
|
+
|
|
20
|
+
unsub();
|
|
21
|
+
|
|
22
|
+
expect(callback).toHaveBeenCalled();
|
|
23
|
+
expect(callback).toHaveBeenCalledWith(deletedCommunity);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
27
|
+
const callback = jest.fn();
|
|
28
|
+
const unsub = onCommunityDeleted(callback);
|
|
29
|
+
|
|
30
|
+
unsub();
|
|
31
|
+
|
|
32
|
+
client.emitter.emit('community.deleted', eventPayload);
|
|
33
|
+
expect(callback).not.toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { withUser } from '~/group/utils';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
community11,
|
|
7
|
+
communityUser11,
|
|
8
|
+
user11,
|
|
9
|
+
} from '~/utils/tests';
|
|
10
|
+
|
|
11
|
+
import { onCommunityJoined } from '../onCommunityJoined';
|
|
12
|
+
|
|
13
|
+
const communityToJoin = community11;
|
|
14
|
+
const joinedUserRaw = communityUser11;
|
|
15
|
+
const joinedUser = withUser(joinedUserRaw);
|
|
16
|
+
|
|
17
|
+
const eventPayload: Amity.CommunityMembershipPayload = {
|
|
18
|
+
communities: [communityToJoin],
|
|
19
|
+
communityUsers: [joinedUserRaw],
|
|
20
|
+
files: [],
|
|
21
|
+
users: [user11],
|
|
22
|
+
categories: [],
|
|
23
|
+
feeds: [],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('onCommunityJoined', () => {
|
|
27
|
+
beforeAll(connectClient);
|
|
28
|
+
afterAll(disconnectClient);
|
|
29
|
+
|
|
30
|
+
test('it should got event after join community', () => {
|
|
31
|
+
const callback = jest.fn();
|
|
32
|
+
const unsub = onCommunityJoined(callback);
|
|
33
|
+
client.emitter.emit('community.joined', eventPayload);
|
|
34
|
+
|
|
35
|
+
unsub();
|
|
36
|
+
|
|
37
|
+
expect(callback).toHaveBeenCalled();
|
|
38
|
+
expect(callback).toHaveBeenCalledWith(communityToJoin, joinedUser);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
42
|
+
const callback = jest.fn();
|
|
43
|
+
const unsub = onCommunityJoined(callback);
|
|
44
|
+
|
|
45
|
+
unsub();
|
|
46
|
+
|
|
47
|
+
client.emitter.emit('community.joined', eventPayload);
|
|
48
|
+
expect(callback).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { withUser } from '~/group/utils';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
community11,
|
|
7
|
+
communityUser11,
|
|
8
|
+
user11,
|
|
9
|
+
} from '~/utils/tests';
|
|
10
|
+
|
|
11
|
+
import { onCommunityLeft } from '../onCommunityLeft';
|
|
12
|
+
|
|
13
|
+
const communityToLeave = community11;
|
|
14
|
+
const leavedUserRaw = { ...communityUser11, communityMembership: 'none' as const };
|
|
15
|
+
const leavedUser = withUser(leavedUserRaw);
|
|
16
|
+
|
|
17
|
+
const eventPayload: Amity.CommunityMembershipPayload = {
|
|
18
|
+
communities: [communityToLeave],
|
|
19
|
+
communityUsers: [leavedUserRaw],
|
|
20
|
+
files: [],
|
|
21
|
+
users: [user11],
|
|
22
|
+
categories: [],
|
|
23
|
+
feeds: [],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('onCommunityLeft', () => {
|
|
27
|
+
beforeAll(connectClient);
|
|
28
|
+
afterAll(disconnectClient);
|
|
29
|
+
|
|
30
|
+
test('it should got event after left community', () => {
|
|
31
|
+
const callback = jest.fn();
|
|
32
|
+
const unsub = onCommunityLeft(callback);
|
|
33
|
+
client.emitter.emit('community.left', eventPayload);
|
|
34
|
+
|
|
35
|
+
unsub();
|
|
36
|
+
|
|
37
|
+
expect(callback).toHaveBeenCalled();
|
|
38
|
+
expect(callback).toHaveBeenCalledWith(communityToLeave, leavedUser);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
42
|
+
const callback = jest.fn();
|
|
43
|
+
const unsub = onCommunityLeft(callback);
|
|
44
|
+
|
|
45
|
+
unsub();
|
|
46
|
+
|
|
47
|
+
client.emitter.emit('community.left', eventPayload);
|
|
48
|
+
expect(callback).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
client,
|
|
3
|
+
connectClient,
|
|
4
|
+
disconnectClient,
|
|
5
|
+
community11,
|
|
6
|
+
communityUser11,
|
|
7
|
+
user11,
|
|
8
|
+
} from '~/utils/tests';
|
|
9
|
+
|
|
10
|
+
import { onCommunityUpdated } from '../onCommunityUpdated';
|
|
11
|
+
|
|
12
|
+
const communityToUpdate = community11;
|
|
13
|
+
const patch = { displayName: 'new-display-name' };
|
|
14
|
+
const updatedCommunity = { ...communityToUpdate, ...patch };
|
|
15
|
+
|
|
16
|
+
const eventPayload: Amity.CommunityPayload = {
|
|
17
|
+
communities: [updatedCommunity],
|
|
18
|
+
communityUsers: [communityUser11],
|
|
19
|
+
files: [],
|
|
20
|
+
users: [user11],
|
|
21
|
+
categories: [],
|
|
22
|
+
feeds: [],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('onCommunityUpdated', () => {
|
|
26
|
+
beforeAll(connectClient);
|
|
27
|
+
afterAll(disconnectClient);
|
|
28
|
+
|
|
29
|
+
test('it should got event after community updated', () => {
|
|
30
|
+
const callback = jest.fn();
|
|
31
|
+
const unsub = onCommunityUpdated(callback);
|
|
32
|
+
client.emitter.emit('community.updated', eventPayload);
|
|
33
|
+
|
|
34
|
+
unsub();
|
|
35
|
+
|
|
36
|
+
expect(callback).toHaveBeenCalled();
|
|
37
|
+
expect(callback).toHaveBeenCalledWith(updatedCommunity);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
41
|
+
const callback = jest.fn();
|
|
42
|
+
const unsub = onCommunityUpdated(callback);
|
|
43
|
+
|
|
44
|
+
unsub();
|
|
45
|
+
|
|
46
|
+
client.emitter.emit('community.updated', eventPayload);
|
|
47
|
+
expect(callback).not.toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { withUser } from '~/group/utils';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
community11,
|
|
7
|
+
communityUser11,
|
|
8
|
+
user11,
|
|
9
|
+
} from '~/utils/tests';
|
|
10
|
+
|
|
11
|
+
import { onCommunityUserAdded } from '../onCommunityUserAdded';
|
|
12
|
+
|
|
13
|
+
const communityToAddUserTo = community11;
|
|
14
|
+
const userToAddRaw = communityUser11;
|
|
15
|
+
const userToAdd = withUser(userToAddRaw);
|
|
16
|
+
|
|
17
|
+
const eventPayload: Amity.CommunityMembershipPayload = {
|
|
18
|
+
communities: [communityToAddUserTo],
|
|
19
|
+
communityUsers: [userToAddRaw],
|
|
20
|
+
files: [],
|
|
21
|
+
users: [user11],
|
|
22
|
+
categories: [],
|
|
23
|
+
feeds: [],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('onCommunityUserAdded', () => {
|
|
27
|
+
beforeAll(connectClient);
|
|
28
|
+
afterAll(disconnectClient);
|
|
29
|
+
|
|
30
|
+
test('it should got event after added community user', () => {
|
|
31
|
+
const callback = jest.fn();
|
|
32
|
+
const unsub = onCommunityUserAdded(callback);
|
|
33
|
+
client.emitter.emit('community.userAdded', eventPayload);
|
|
34
|
+
|
|
35
|
+
unsub();
|
|
36
|
+
|
|
37
|
+
expect(callback).toHaveBeenCalled();
|
|
38
|
+
expect(callback).toHaveBeenCalledWith(communityToAddUserTo, userToAdd);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
42
|
+
const callback = jest.fn();
|
|
43
|
+
const unsub = onCommunityUserAdded(callback);
|
|
44
|
+
|
|
45
|
+
unsub();
|
|
46
|
+
|
|
47
|
+
client.emitter.emit('community.userAdded', eventPayload);
|
|
48
|
+
expect(callback).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { withUser } from '~/group/utils';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
community11,
|
|
7
|
+
communityUser11,
|
|
8
|
+
user11,
|
|
9
|
+
} from '~/utils/tests';
|
|
10
|
+
|
|
11
|
+
import { onCommunityUserBanned } from '../onCommunityUserBanned';
|
|
12
|
+
|
|
13
|
+
const community = community11;
|
|
14
|
+
const banedUserRaw = { ...communityUser11, communityMembership: 'banned' as const };
|
|
15
|
+
const banedUser = withUser(banedUserRaw);
|
|
16
|
+
|
|
17
|
+
const eventPayload: Amity.CommunityMembershipPayload = {
|
|
18
|
+
communities: [community],
|
|
19
|
+
communityUsers: [banedUserRaw],
|
|
20
|
+
files: [],
|
|
21
|
+
users: [user11],
|
|
22
|
+
categories: [],
|
|
23
|
+
feeds: [],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('onCommunityUserBanned', () => {
|
|
27
|
+
beforeAll(connectClient);
|
|
28
|
+
afterAll(disconnectClient);
|
|
29
|
+
|
|
30
|
+
test('it should got event after banned community user', () => {
|
|
31
|
+
const callback = jest.fn();
|
|
32
|
+
const unsub = onCommunityUserBanned(callback);
|
|
33
|
+
client.emitter.emit('community.userBanned', eventPayload);
|
|
34
|
+
|
|
35
|
+
unsub();
|
|
36
|
+
|
|
37
|
+
expect(callback).toHaveBeenCalled();
|
|
38
|
+
expect(callback).toHaveBeenCalledWith(community, banedUser);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
42
|
+
const callback = jest.fn();
|
|
43
|
+
const unsub = onCommunityUserBanned(callback);
|
|
44
|
+
|
|
45
|
+
unsub();
|
|
46
|
+
|
|
47
|
+
client.emitter.emit('community.userBanned', eventPayload);
|
|
48
|
+
expect(callback).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { withUser } from '~/group/utils';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
community11,
|
|
7
|
+
communityUser11,
|
|
8
|
+
user11,
|
|
9
|
+
} from '~/utils/tests';
|
|
10
|
+
|
|
11
|
+
import { onCommunityUserRemoved } from '../onCommunityUserRemoved';
|
|
12
|
+
|
|
13
|
+
const community = community11;
|
|
14
|
+
const removedUserRaw = { ...communityUser11, communityMembership: 'none' as const };
|
|
15
|
+
const removedUser = withUser(removedUserRaw);
|
|
16
|
+
|
|
17
|
+
const eventPayload: Amity.CommunityMembershipPayload = {
|
|
18
|
+
communities: [community],
|
|
19
|
+
communityUsers: [removedUserRaw],
|
|
20
|
+
files: [],
|
|
21
|
+
users: [user11],
|
|
22
|
+
categories: [],
|
|
23
|
+
feeds: [],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('onCommunityUserRemoved', () => {
|
|
27
|
+
beforeAll(connectClient);
|
|
28
|
+
afterAll(disconnectClient);
|
|
29
|
+
|
|
30
|
+
test('it should got event after removed community user', () => {
|
|
31
|
+
const callback = jest.fn();
|
|
32
|
+
const unsub = onCommunityUserRemoved(callback);
|
|
33
|
+
client.emitter.emit('community.userRemoved', eventPayload);
|
|
34
|
+
|
|
35
|
+
unsub();
|
|
36
|
+
|
|
37
|
+
expect(callback).toHaveBeenCalled();
|
|
38
|
+
expect(callback).toHaveBeenCalledWith(community, removedUser);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
42
|
+
const callback = jest.fn();
|
|
43
|
+
const unsub = onCommunityUserRemoved(callback);
|
|
44
|
+
|
|
45
|
+
unsub();
|
|
46
|
+
|
|
47
|
+
client.emitter.emit('community.userRemoved', eventPayload);
|
|
48
|
+
expect(callback).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { withUser } from '~/group/utils';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
community11,
|
|
7
|
+
communityUser11,
|
|
8
|
+
user11,
|
|
9
|
+
} from '~/utils/tests';
|
|
10
|
+
|
|
11
|
+
import { onCommunityUserUnbanned } from '../onCommunityUserUnbanned';
|
|
12
|
+
|
|
13
|
+
const community = community11;
|
|
14
|
+
const unbannedUserRaw = { ...communityUser11, communityMembership: 'member' as const };
|
|
15
|
+
const unbannedUser = withUser(unbannedUserRaw);
|
|
16
|
+
|
|
17
|
+
const eventPayload: Amity.CommunityMembershipPayload = {
|
|
18
|
+
communities: [community],
|
|
19
|
+
communityUsers: [unbannedUserRaw],
|
|
20
|
+
files: [],
|
|
21
|
+
users: [user11],
|
|
22
|
+
categories: [],
|
|
23
|
+
feeds: [],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('onCommunityUserUnbanned', () => {
|
|
27
|
+
beforeAll(connectClient);
|
|
28
|
+
afterAll(disconnectClient);
|
|
29
|
+
|
|
30
|
+
test('it should got event after unbanned community user', () => {
|
|
31
|
+
const callback = jest.fn();
|
|
32
|
+
const unsub = onCommunityUserUnbanned(callback);
|
|
33
|
+
client.emitter.emit('community.userUnbanned', eventPayload);
|
|
34
|
+
|
|
35
|
+
unsub();
|
|
36
|
+
|
|
37
|
+
expect(callback).toHaveBeenCalled();
|
|
38
|
+
expect(callback).toHaveBeenCalledWith(community, unbannedUser);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('it should got nothing if we did unsubscribe before got event', () => {
|
|
42
|
+
const callback = jest.fn();
|
|
43
|
+
const unsub = onCommunityUserUnbanned(callback);
|
|
44
|
+
|
|
45
|
+
unsub();
|
|
46
|
+
|
|
47
|
+
client.emitter.emit('community.userUnbanned', eventPayload);
|
|
48
|
+
expect(callback).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
});
|