@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,74 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
|
+
import { client, community11, communityUser11, user11 } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
import { deleteCommunity } from '../deleteCommunity';
|
|
5
|
+
import { onCommunityDeleted } from '../../events';
|
|
6
|
+
|
|
7
|
+
const communityToDelete = community11;
|
|
8
|
+
const { communityId: deleteId } = communityToDelete;
|
|
9
|
+
const deletedCommunity = { ...communityToDelete, isDeleted: true };
|
|
10
|
+
const { updatedAt, ...deletedCommunityWithoutTS } = deletedCommunity;
|
|
11
|
+
|
|
12
|
+
const resolvedDeleteValue = {
|
|
13
|
+
data: {
|
|
14
|
+
success: true,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const resolvedGetValue = {
|
|
19
|
+
data: {
|
|
20
|
+
communities: [deletedCommunity],
|
|
21
|
+
communityUsers: [communityUser11],
|
|
22
|
+
files: [],
|
|
23
|
+
users: [user11],
|
|
24
|
+
categories: [],
|
|
25
|
+
feeds: [],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe('deleteCommunity', () => {
|
|
30
|
+
test('should return deleted community', async () => {
|
|
31
|
+
client.http.delete = jest.fn().mockResolvedValueOnce(resolvedDeleteValue);
|
|
32
|
+
client.http.get = jest.fn().mockResolvedValueOnce(resolvedGetValue);
|
|
33
|
+
|
|
34
|
+
await expect(deleteCommunity(deleteId)).resolves.toEqual(
|
|
35
|
+
expect.objectContaining(deletedCommunityWithoutTS),
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should throw an error if request fails', async () => {
|
|
40
|
+
client.http.delete = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
41
|
+
|
|
42
|
+
await expect(deleteCommunity(deleteId)).rejects.toThrow('error');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('should update cache after deleted community', async () => {
|
|
46
|
+
enableCache();
|
|
47
|
+
client.http.delete = jest.fn().mockResolvedValueOnce(resolvedDeleteValue);
|
|
48
|
+
client.http.get = jest.fn().mockResolvedValueOnce(resolvedGetValue);
|
|
49
|
+
pushToCache(['community', 'get', deleteId], communityToDelete);
|
|
50
|
+
|
|
51
|
+
await deleteCommunity(deleteId);
|
|
52
|
+
const recieved = pullFromCache(['community', 'get', deleteId])?.data;
|
|
53
|
+
|
|
54
|
+
expect(recieved).toEqual(expect.objectContaining(deletedCommunityWithoutTS));
|
|
55
|
+
|
|
56
|
+
disableCache();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('should fire event `onCommunityDeleted`', async () => {
|
|
60
|
+
let dispose;
|
|
61
|
+
client.http.delete = jest.fn().mockResolvedValueOnce(resolvedDeleteValue);
|
|
62
|
+
client.http.get = jest.fn().mockResolvedValueOnce(resolvedGetValue);
|
|
63
|
+
|
|
64
|
+
const callbackPromise = new Promise(resolve => {
|
|
65
|
+
dispose = onCommunityDeleted(resolve);
|
|
66
|
+
}).finally(dispose);
|
|
67
|
+
|
|
68
|
+
await deleteCommunity(deleteId);
|
|
69
|
+
|
|
70
|
+
await expect(callbackPromise).resolves.toEqual(
|
|
71
|
+
expect.objectContaining(deletedCommunityWithoutTS),
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
|
+
import { client, community11, community21 } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
import { getCommunities } from '../getCommunities';
|
|
5
|
+
|
|
6
|
+
const communitiesToGet = [community11, community21];
|
|
7
|
+
const getIds = communitiesToGet.map(({ communityId }) => communityId);
|
|
8
|
+
|
|
9
|
+
const resolvedGetValue = {
|
|
10
|
+
data: {
|
|
11
|
+
communities: communitiesToGet,
|
|
12
|
+
communityUsers: [community11, community21],
|
|
13
|
+
files: [],
|
|
14
|
+
users: [],
|
|
15
|
+
categories: [],
|
|
16
|
+
feeds: [],
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('getCommunities', () => {
|
|
21
|
+
test('should return fetched communities', async () => {
|
|
22
|
+
client.http.get = jest.fn().mockResolvedValueOnce(resolvedGetValue);
|
|
23
|
+
|
|
24
|
+
await expect(getCommunities(getIds)).resolves.toEqual(
|
|
25
|
+
expect.objectContaining({ data: communitiesToGet }),
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should update cache after fetching communities', async () => {
|
|
30
|
+
enableCache();
|
|
31
|
+
client.http.get = jest.fn().mockResolvedValue(resolvedGetValue);
|
|
32
|
+
|
|
33
|
+
await getCommunities(getIds);
|
|
34
|
+
|
|
35
|
+
const recieved = getIds.map(id => pullFromCache(['community', 'get', id])?.data);
|
|
36
|
+
|
|
37
|
+
expect(recieved).toEqual(communitiesToGet);
|
|
38
|
+
|
|
39
|
+
disableCache();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('should throw an error if request fails', async () => {
|
|
43
|
+
client.http.get = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
44
|
+
|
|
45
|
+
await expect(getCommunities(getIds)).rejects.toThrow('error');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('getCommunities.locally', () => {
|
|
50
|
+
beforeEach(() => enableCache());
|
|
51
|
+
afterEach(() => disableCache());
|
|
52
|
+
|
|
53
|
+
test('should return cached communities', () => {
|
|
54
|
+
communitiesToGet.forEach(community =>
|
|
55
|
+
pushToCache(['community', 'get', community.communityId], community),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect(getCommunities.locally(getIds)?.data).toEqual(communitiesToGet);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('it should return undefined if communities not in cache', () => {
|
|
62
|
+
expect(getCommunities.locally(['non-existent-communities'])).toBeUndefined();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('should return undefined if cache not enabled', () => {
|
|
66
|
+
disableCache();
|
|
67
|
+
communitiesToGet.forEach(community =>
|
|
68
|
+
pushToCache(['community', 'get', community.communityId], community),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(getCommunities.locally(getIds)).toBeUndefined();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
|
+
import { client, community11 } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
import { getCommunity } from '../getCommunity';
|
|
5
|
+
|
|
6
|
+
const communityToGet = community11;
|
|
7
|
+
const getId = community11.communityId;
|
|
8
|
+
|
|
9
|
+
const resolvedGetValue = {
|
|
10
|
+
data: {
|
|
11
|
+
communities: [communityToGet],
|
|
12
|
+
communityUsers: [community11],
|
|
13
|
+
files: [],
|
|
14
|
+
users: [],
|
|
15
|
+
categories: [],
|
|
16
|
+
feeds: [],
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('getCommunity', () => {
|
|
21
|
+
test('should return fetched community', async () => {
|
|
22
|
+
client.http.get = jest.fn().mockResolvedValueOnce(resolvedGetValue);
|
|
23
|
+
|
|
24
|
+
await expect(getCommunity(getId)).resolves.toEqual(
|
|
25
|
+
expect.objectContaining({ data: communityToGet }),
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should update cache after fetching community', async () => {
|
|
30
|
+
enableCache();
|
|
31
|
+
client.http.get = jest.fn().mockResolvedValue(resolvedGetValue);
|
|
32
|
+
|
|
33
|
+
await getCommunity(getId);
|
|
34
|
+
|
|
35
|
+
const recieved = pullFromCache(['community', 'get', getId])?.data;
|
|
36
|
+
|
|
37
|
+
expect(recieved).toEqual(communityToGet);
|
|
38
|
+
|
|
39
|
+
disableCache();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('should throw an error if request fails', async () => {
|
|
43
|
+
client.http.get = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
44
|
+
|
|
45
|
+
await expect(getCommunity(getId)).rejects.toThrow('error');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('getCommunity.locally', () => {
|
|
50
|
+
beforeEach(() => enableCache());
|
|
51
|
+
afterEach(() => disableCache());
|
|
52
|
+
|
|
53
|
+
test('should return cached community', () => {
|
|
54
|
+
pushToCache(['community', 'get', getId], communityToGet);
|
|
55
|
+
|
|
56
|
+
expect(getCommunity.locally(getId)?.data).toEqual(communityToGet);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('it should return undefined if community not in cache', () => {
|
|
60
|
+
expect(getCommunity.locally('non-existent-community')).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('should return undefined if cache not enabled', () => {
|
|
64
|
+
disableCache();
|
|
65
|
+
pushToCache(['community', 'get', getId], communityToGet);
|
|
66
|
+
|
|
67
|
+
expect(getCommunity.locally(getId)).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
|
+
import { client, community11, community21 } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
import { getRecommendedCommunities } from '../getRecommendedCommunities';
|
|
5
|
+
|
|
6
|
+
const recommendedCommunities = [community11, community21];
|
|
7
|
+
const recommendedIds = recommendedCommunities.map(({ communityId }) => communityId);
|
|
8
|
+
|
|
9
|
+
const pagingToken = {
|
|
10
|
+
previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
11
|
+
next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const pagingCriteria = { limit: 10 };
|
|
15
|
+
|
|
16
|
+
const resolvedGetValue = {
|
|
17
|
+
data: {
|
|
18
|
+
communities: recommendedCommunities,
|
|
19
|
+
communityUsers: [community11, community21],
|
|
20
|
+
files: [],
|
|
21
|
+
users: [],
|
|
22
|
+
categories: [],
|
|
23
|
+
feeds: [],
|
|
24
|
+
paging: pagingToken,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('getRecommendedCommunities', () => {
|
|
29
|
+
test('should return fetched recommended communities with correct paging', async () => {
|
|
30
|
+
client.http.get = jest.fn().mockResolvedValueOnce(resolvedGetValue);
|
|
31
|
+
|
|
32
|
+
await expect(getRecommendedCommunities(pagingCriteria)).resolves.toEqual(
|
|
33
|
+
expect.objectContaining({ data: recommendedCommunities }),
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should update cache after fetching recommended communities', async () => {
|
|
38
|
+
enableCache();
|
|
39
|
+
client.http.get = jest.fn().mockResolvedValue(resolvedGetValue);
|
|
40
|
+
|
|
41
|
+
await getRecommendedCommunities(pagingCriteria);
|
|
42
|
+
|
|
43
|
+
const recieved = pullFromCache([
|
|
44
|
+
'community',
|
|
45
|
+
'recommended',
|
|
46
|
+
{ params: { options: pagingCriteria } },
|
|
47
|
+
])?.data;
|
|
48
|
+
|
|
49
|
+
expect(recieved).toEqual({ communities: recommendedIds });
|
|
50
|
+
|
|
51
|
+
disableCache();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('should throw an error if request fails', async () => {
|
|
55
|
+
client.http.get = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
56
|
+
|
|
57
|
+
await expect(getRecommendedCommunities(pagingCriteria)).rejects.toThrow('error');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('getRecommendedCommunities.locally', () => {
|
|
62
|
+
beforeEach(() => enableCache());
|
|
63
|
+
afterEach(() => disableCache());
|
|
64
|
+
|
|
65
|
+
test('should return cached recommended communities', () => {
|
|
66
|
+
recommendedCommunities.forEach(community =>
|
|
67
|
+
pushToCache(['community', 'get', community.communityId], community),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
pushToCache(['community', 'recommended', { params: { options: pagingCriteria } }], {
|
|
71
|
+
communities: recommendedIds,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(getRecommendedCommunities.locally(pagingCriteria)?.data).toEqual(recommendedCommunities);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('it should return undefined if recommended communities not in cache', () => {
|
|
78
|
+
recommendedCommunities.forEach(community =>
|
|
79
|
+
pushToCache(['community', 'get', community.communityId], community),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
pushToCache(['community', 'recommended', { params: { options: pagingCriteria } }], {
|
|
83
|
+
communities: recommendedIds,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(getRecommendedCommunities.locally({ limit: -1 })).toBeUndefined();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('should return undefined if cache not enabled', () => {
|
|
90
|
+
disableCache();
|
|
91
|
+
|
|
92
|
+
recommendedCommunities.forEach(community =>
|
|
93
|
+
pushToCache(['community', 'get', community.communityId], community),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
pushToCache(['community', 'recommended', { params: { options: pagingCriteria } }], {
|
|
97
|
+
communities: recommendedIds,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(getRecommendedCommunities.locally(pagingCriteria)).toBeUndefined();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
|
+
import { client, community11, community21 } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
import { getTopTrendingCommunities } from '../getTopTrendingCommunities';
|
|
5
|
+
|
|
6
|
+
const topTrendCommunities = [community11, community21];
|
|
7
|
+
const topTrendIds = topTrendCommunities.map(({ communityId }) => communityId);
|
|
8
|
+
|
|
9
|
+
const pagingToken = {
|
|
10
|
+
previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
11
|
+
next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const pagingCriteria = { limit: 10 };
|
|
15
|
+
|
|
16
|
+
const resolvedGetValue = {
|
|
17
|
+
data: {
|
|
18
|
+
communities: topTrendCommunities,
|
|
19
|
+
communityUsers: [community11, community21],
|
|
20
|
+
files: [],
|
|
21
|
+
users: [],
|
|
22
|
+
categories: [],
|
|
23
|
+
feeds: [],
|
|
24
|
+
paging: pagingToken,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('getTopTrendingCommunities', () => {
|
|
29
|
+
test('should return fetched top trend communities with correct paging', async () => {
|
|
30
|
+
client.http.get = jest.fn().mockResolvedValueOnce(resolvedGetValue);
|
|
31
|
+
|
|
32
|
+
await expect(getTopTrendingCommunities(pagingCriteria)).resolves.toEqual(
|
|
33
|
+
expect.objectContaining({ data: topTrendCommunities }),
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should update cache after fetching top trend communities', async () => {
|
|
38
|
+
enableCache();
|
|
39
|
+
client.http.get = jest.fn().mockResolvedValue(resolvedGetValue);
|
|
40
|
+
|
|
41
|
+
await getTopTrendingCommunities(pagingCriteria);
|
|
42
|
+
|
|
43
|
+
const recieved = pullFromCache([
|
|
44
|
+
'community',
|
|
45
|
+
'top-trending',
|
|
46
|
+
{ params: { options: pagingCriteria } },
|
|
47
|
+
])?.data;
|
|
48
|
+
|
|
49
|
+
expect(recieved).toEqual({ communities: topTrendIds });
|
|
50
|
+
|
|
51
|
+
disableCache();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('should throw an error if request fails', async () => {
|
|
55
|
+
client.http.get = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
56
|
+
|
|
57
|
+
await expect(getTopTrendingCommunities(pagingCriteria)).rejects.toThrow('error');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('getTopTrendingCommunities.locally', () => {
|
|
62
|
+
beforeEach(() => enableCache());
|
|
63
|
+
afterEach(() => disableCache());
|
|
64
|
+
|
|
65
|
+
test('should return cached top trend communities', () => {
|
|
66
|
+
topTrendCommunities.forEach(community =>
|
|
67
|
+
pushToCache(['community', 'get', community.communityId], community),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
pushToCache(['community', 'top-trending', { params: { options: pagingCriteria } }], {
|
|
71
|
+
communities: topTrendIds,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(getTopTrendingCommunities.locally(pagingCriteria)?.data).toEqual(topTrendCommunities);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('it should return undefined if top trend communities not in cache', () => {
|
|
78
|
+
topTrendCommunities.forEach(community =>
|
|
79
|
+
pushToCache(['community', 'get', community.communityId], community),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
pushToCache(['community', 'top-trending', { params: { options: pagingCriteria } }], {
|
|
83
|
+
communities: topTrendIds,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(getTopTrendingCommunities.locally({ limit: -1 })).toBeUndefined();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('should return undefined if cache not enabled', () => {
|
|
90
|
+
disableCache();
|
|
91
|
+
|
|
92
|
+
topTrendCommunities.forEach(community =>
|
|
93
|
+
pushToCache(['community', 'get', community.communityId], community),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
pushToCache(['community', 'top-trending', { params: { options: pagingCriteria } }], {
|
|
97
|
+
communities: topTrendIds,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(getTopTrendingCommunities.locally(pagingCriteria)).toBeUndefined();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { onCommunityJoined } from '../../events';
|
|
7
|
+
import { joinCommunity } from '../joinCommunity';
|
|
8
|
+
|
|
9
|
+
const communityToJoin = community11;
|
|
10
|
+
const joinedUser = communityUser11;
|
|
11
|
+
|
|
12
|
+
const resolvedPostValue = {
|
|
13
|
+
data: {
|
|
14
|
+
communities: [communityToJoin],
|
|
15
|
+
communityUsers: [joinedUser],
|
|
16
|
+
files: [],
|
|
17
|
+
users: [user11],
|
|
18
|
+
categories: [],
|
|
19
|
+
feeds: [],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('joinCommunity', () => {
|
|
24
|
+
test('should return true value', async () => {
|
|
25
|
+
client.http.post = jest.fn().mockResolvedValue(resolvedPostValue);
|
|
26
|
+
|
|
27
|
+
const recieved = joinCommunity(communityToJoin.communityId);
|
|
28
|
+
|
|
29
|
+
await expect(recieved).resolves.toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('should throw an error if request fails', async () => {
|
|
33
|
+
client.http.post = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
34
|
+
|
|
35
|
+
await expect(joinCommunity(communityToJoin.communityId)).rejects.toThrow('error');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('should create cache after join community', async () => {
|
|
39
|
+
enableCache();
|
|
40
|
+
client.http.post = jest.fn().mockResolvedValue(resolvedPostValue);
|
|
41
|
+
|
|
42
|
+
await joinCommunity(communityToJoin.communityId);
|
|
43
|
+
|
|
44
|
+
const recieved = pullFromCache([
|
|
45
|
+
'communityUsers',
|
|
46
|
+
'get',
|
|
47
|
+
getResolver('communityUsers')({
|
|
48
|
+
communityId: communityToJoin.communityId,
|
|
49
|
+
userId: joinedUser.userId,
|
|
50
|
+
}),
|
|
51
|
+
])?.data;
|
|
52
|
+
|
|
53
|
+
expect(recieved).toEqual(expect.objectContaining(joinedUser));
|
|
54
|
+
|
|
55
|
+
disableCache();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('should fire event `onCommunityJoined`', async () => {
|
|
59
|
+
let dispose;
|
|
60
|
+
client.http.post = jest.fn().mockResolvedValueOnce(resolvedPostValue);
|
|
61
|
+
|
|
62
|
+
const callback = new Promise(resolve => {
|
|
63
|
+
dispose = onCommunityJoined(resolve);
|
|
64
|
+
}).finally(dispose);
|
|
65
|
+
|
|
66
|
+
await joinCommunity(communityToJoin.communityId);
|
|
67
|
+
|
|
68
|
+
await expect(callback).resolves.toEqual(expect.objectContaining(communityToJoin));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
|
+
import { getResolver } from '~/core/model';
|
|
3
|
+
import { client, community11, communityUser11, user11 } from '~/utils/tests';
|
|
4
|
+
|
|
5
|
+
import { leaveCommunity } from '../leaveCommunity';
|
|
6
|
+
import { onCommunityLeft } from '../../events';
|
|
7
|
+
|
|
8
|
+
const communityToLeave = community11;
|
|
9
|
+
const toLeaveUser = { ...communityUser11, communityMembership: 'member' };
|
|
10
|
+
const leavedUser = { ...communityUser11, communityMembership: 'none' };
|
|
11
|
+
|
|
12
|
+
const resolvedDeleteValue = {
|
|
13
|
+
data: {
|
|
14
|
+
communities: [communityToLeave],
|
|
15
|
+
communityUsers: [leavedUser],
|
|
16
|
+
files: [],
|
|
17
|
+
users: [user11],
|
|
18
|
+
categories: [],
|
|
19
|
+
feeds: [],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('leaveCommunity', () => {
|
|
24
|
+
test('should return true value', async () => {
|
|
25
|
+
client.http.delete = jest.fn().mockResolvedValueOnce(resolvedDeleteValue);
|
|
26
|
+
|
|
27
|
+
await expect(leaveCommunity(communityToLeave.communityId)).resolves.toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('should throw an error if request fails', async () => {
|
|
31
|
+
client.http.delete = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
32
|
+
|
|
33
|
+
await expect(leaveCommunity(communityToLeave.communityId)).rejects.toThrow('error');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('should update cache after leaved community', async () => {
|
|
37
|
+
enableCache();
|
|
38
|
+
client.http.delete = jest.fn().mockResolvedValueOnce(resolvedDeleteValue);
|
|
39
|
+
pushToCache(
|
|
40
|
+
[
|
|
41
|
+
'communityUsers',
|
|
42
|
+
'get',
|
|
43
|
+
getResolver('communityUsers')({
|
|
44
|
+
communityId: communityToLeave.communityId,
|
|
45
|
+
userId: toLeaveUser.userId,
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
toLeaveUser,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
await leaveCommunity(communityToLeave.communityId);
|
|
52
|
+
const recieved = pullFromCache([
|
|
53
|
+
'communityUsers',
|
|
54
|
+
'get',
|
|
55
|
+
getResolver('communityUsers')({
|
|
56
|
+
communityId: communityToLeave.communityId,
|
|
57
|
+
userId: toLeaveUser.userId,
|
|
58
|
+
}),
|
|
59
|
+
])?.data;
|
|
60
|
+
|
|
61
|
+
expect(recieved).toEqual(expect.objectContaining(leavedUser));
|
|
62
|
+
|
|
63
|
+
disableCache();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('should fire event `onCommunityLeft`', async () => {
|
|
67
|
+
let dispose;
|
|
68
|
+
client.http.delete = jest.fn().mockResolvedValueOnce(resolvedDeleteValue);
|
|
69
|
+
|
|
70
|
+
const callbackPromise = new Promise(resolve => {
|
|
71
|
+
dispose = onCommunityLeft(resolve);
|
|
72
|
+
}).finally(dispose);
|
|
73
|
+
|
|
74
|
+
await leaveCommunity(toLeaveUser.userId);
|
|
75
|
+
|
|
76
|
+
await expect(callbackPromise).resolves.toEqual(expect.objectContaining(communityToLeave));
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
|
+
|
|
3
|
+
import { client, community11, community21, communityUser11 } from '~/utils/tests';
|
|
4
|
+
|
|
5
|
+
import { queryCommunities } from '../queryCommunities';
|
|
6
|
+
|
|
7
|
+
const communities = [community11, community21];
|
|
8
|
+
|
|
9
|
+
const pagingToken = {
|
|
10
|
+
previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
11
|
+
next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const communitiesToQuery = [community11];
|
|
15
|
+
const communityIdsToQuery = communitiesToQuery.map(community => community.communityId);
|
|
16
|
+
const communityUsersToQuery = [communityUser11];
|
|
17
|
+
const queryCriteriaWithoutPage = { displayName: communities[0].displayName };
|
|
18
|
+
const pagingCriteria = { limit: 10 };
|
|
19
|
+
const queryCriteria = { ...queryCriteriaWithoutPage, page: pagingCriteria };
|
|
20
|
+
|
|
21
|
+
const resolvedGetValue = {
|
|
22
|
+
data: {
|
|
23
|
+
communities: communitiesToQuery,
|
|
24
|
+
communityUsers: communityUsersToQuery,
|
|
25
|
+
files: [],
|
|
26
|
+
users: [],
|
|
27
|
+
categories: [],
|
|
28
|
+
feeds: [],
|
|
29
|
+
paging: pagingToken,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
describe('queryCommunities', () => {
|
|
34
|
+
test('should return fetched communities with correct paging', async () => {
|
|
35
|
+
client.http.get = jest.fn().mockResolvedValueOnce(resolvedGetValue);
|
|
36
|
+
|
|
37
|
+
await expect(queryCommunities(queryCriteria)).resolves.toEqual(
|
|
38
|
+
expect.objectContaining({
|
|
39
|
+
data: communitiesToQuery,
|
|
40
|
+
prevPage: { before: 55, limit: 10 },
|
|
41
|
+
nextPage: { before: 55, limit: 10 },
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('should update cache after fetching communities', async () => {
|
|
47
|
+
enableCache();
|
|
48
|
+
client.http.get = jest.fn().mockResolvedValue(resolvedGetValue);
|
|
49
|
+
|
|
50
|
+
await queryCommunities(queryCriteria);
|
|
51
|
+
|
|
52
|
+
const recieved = pullFromCache([
|
|
53
|
+
'community',
|
|
54
|
+
'query',
|
|
55
|
+
{ ...queryCriteriaWithoutPage, options: pagingCriteria },
|
|
56
|
+
])?.data;
|
|
57
|
+
|
|
58
|
+
expect(recieved).toEqual({
|
|
59
|
+
communities: communityIdsToQuery,
|
|
60
|
+
paging: pagingToken,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
disableCache();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('should throw an error if request fails', async () => {
|
|
67
|
+
client.http.get = jest.fn().mockRejectedValueOnce(new Error('error'));
|
|
68
|
+
|
|
69
|
+
await expect(queryCommunities(queryCriteria)).rejects.toThrow('error');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe.skip('queryCommunities.locally', () => {
|
|
74
|
+
beforeEach(() => enableCache());
|
|
75
|
+
afterEach(() => disableCache());
|
|
76
|
+
|
|
77
|
+
test('should return cached communities', () => {
|
|
78
|
+
communities.forEach(community =>
|
|
79
|
+
pushToCache(['community', 'get', community.communityId], community),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
pushToCache(['community', 'query', { ...queryCriteriaWithoutPage, options: pagingCriteria }], {
|
|
83
|
+
communities: communitiesToQuery,
|
|
84
|
+
paging: pagingToken,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(queryCommunities.locally(queryCriteria)).toEqual(
|
|
88
|
+
expect.objectContaining({
|
|
89
|
+
data: communitiesToQuery,
|
|
90
|
+
prevPage: { before: 55, limit: 10 },
|
|
91
|
+
nextPage: { before: 55, limit: 10 },
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test(`shouldn't return if individual communities cache not exist`, () => {
|
|
97
|
+
pushToCache(['community', 'query', { ...queryCriteriaWithoutPage, options: pagingCriteria }], {
|
|
98
|
+
communities: communitiesToQuery,
|
|
99
|
+
paging: pagingToken,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(queryCommunities.locally(queryCriteria)).toBeUndefined();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('it should return undefined if communities not in cache', () => {
|
|
106
|
+
expect(queryCommunities.locally({ displayName: 'non-existent' })).toBeUndefined();
|
|
107
|
+
});
|
|
108
|
+
});
|