@amityco/ts-sdk 0.0.1-beta.31 → 0.0.1-beta.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/cache/api/backupCache.d.ts.map +1 -1
  2. package/dist/cache/api/ingestInCache.d.ts +1 -1
  3. package/dist/cache/api/tests/ingestInCache.test.d.ts +2 -0
  4. package/dist/cache/api/tests/ingestInCache.test.d.ts.map +1 -0
  5. package/dist/cache/api/tests/pushToCache.test.d.ts +2 -0
  6. package/dist/cache/api/tests/pushToCache.test.d.ts.map +1 -0
  7. package/dist/channel/api/addChannelMembers.d.ts.map +1 -1
  8. package/dist/channel/api/getChannel.d.ts.map +1 -1
  9. package/dist/channel/api/tests/addChannelMembers.test.d.ts +2 -0
  10. package/dist/channel/api/tests/addChannelMembers.test.d.ts.map +1 -0
  11. package/dist/channel/api/tests/getChannel.test.d.ts +2 -0
  12. package/dist/channel/api/tests/getChannel.test.d.ts.map +1 -0
  13. package/dist/channel/events/onChannelMemberAdded.d.ts.map +1 -1
  14. package/dist/core/events.d.ts +1 -1
  15. package/dist/core/events.d.ts.map +1 -1
  16. package/dist/core/model/idResolvers.d.ts.map +1 -1
  17. package/dist/core/transports/http.d.ts +5 -0
  18. package/dist/core/transports/http.d.ts.map +1 -1
  19. package/dist/core/transports/test/http.test.d.ts +2 -0
  20. package/dist/core/transports/test/http.test.d.ts.map +1 -0
  21. package/dist/index.cjs.js +61 -51
  22. package/dist/index.esm.js +60 -51
  23. package/dist/index.umd.js +4 -4
  24. package/dist/message/api/deleteMessage.d.ts.map +1 -1
  25. package/dist/message/api/tests/deleteMessage.test.d.ts +2 -0
  26. package/dist/message/api/tests/deleteMessage.test.d.ts.map +1 -0
  27. package/dist/message/{tests/api → api/tests}/getMessage.test.d.ts +0 -0
  28. package/dist/message/api/tests/getMessage.test.d.ts.map +1 -0
  29. package/dist/message/api/tests/getMessages.test.d.ts +2 -0
  30. package/dist/message/api/tests/getMessages.test.d.ts.map +1 -0
  31. package/dist/message/api/tests/queryMessages.test.d.ts +2 -0
  32. package/dist/message/api/tests/queryMessages.test.d.ts.map +1 -0
  33. package/dist/message/api/tests/updateMessage.test.d.ts +2 -0
  34. package/dist/message/api/tests/updateMessage.test.d.ts.map +1 -0
  35. package/dist/reaction/api/addReaction.d.ts.map +1 -1
  36. package/dist/reaction/api/removeReaction.d.ts.map +1 -1
  37. package/dist/reaction/api/tests/addReaction.test.d.ts +2 -0
  38. package/dist/reaction/api/tests/addReaction.test.d.ts.map +1 -0
  39. package/dist/reaction/api/tests/removeReaction.test.d.ts +2 -0
  40. package/dist/reaction/api/tests/removeReaction.test.d.ts.map +1 -0
  41. package/dist/user/api/getUser.d.ts.map +1 -1
  42. package/dist/user/api/queryUsers.d.ts.map +1 -1
  43. package/dist/user/api/tests/queryUsers.test.d.ts +2 -0
  44. package/dist/user/api/tests/queryUsers.test.d.ts.map +1 -0
  45. package/dist/utils/tests/dummy/channel.d.ts +6 -0
  46. package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
  47. package/dist/utils/tests/dummy/community.d.ts +4 -0
  48. package/dist/utils/tests/dummy/community.d.ts.map +1 -0
  49. package/dist/utils/tests/dummy/file.d.ts +2 -0
  50. package/dist/utils/tests/dummy/file.d.ts.map +1 -0
  51. package/dist/utils/tests/dummy/follow.d.ts +1 -0
  52. package/dist/utils/tests/dummy/follow.d.ts.map +1 -1
  53. package/dist/utils/tests/dummy/index.d.ts +5 -0
  54. package/dist/utils/tests/dummy/index.d.ts.map +1 -1
  55. package/dist/utils/tests/dummy/message.d.ts +5 -0
  56. package/dist/utils/tests/dummy/message.d.ts.map +1 -1
  57. package/dist/utils/tests/dummy/poll.d.ts +3 -0
  58. package/dist/utils/tests/dummy/poll.d.ts.map +1 -0
  59. package/dist/utils/tests/dummy/post.d.ts +15 -1
  60. package/dist/utils/tests/dummy/post.d.ts.map +1 -1
  61. package/dist/utils/tests/dummy/reaction.d.ts +4 -0
  62. package/dist/utils/tests/dummy/reaction.d.ts.map +1 -0
  63. package/dist/utils/tests/dummy/role.d.ts +4 -0
  64. package/dist/utils/tests/dummy/role.d.ts.map +1 -0
  65. package/dist/utils/tests/dummy/user.d.ts +1 -0
  66. package/dist/utils/tests/dummy/user.d.ts.map +1 -1
  67. package/package.json +2 -1
  68. package/src/cache/api/backupCache.ts +0 -1
  69. package/src/cache/api/ingestInCache.ts +2 -2
  70. package/src/cache/api/tests/ingestInCache.test.ts +87 -0
  71. package/src/cache/api/tests/pushToCache.test.ts +57 -0
  72. package/src/channel/api/addChannelMembers.ts +9 -1
  73. package/src/channel/api/getChannel.ts +20 -5
  74. package/src/channel/api/tests/addChannelMembers.test.ts +95 -0
  75. package/src/channel/api/tests/getChannel.test.ts +108 -0
  76. package/src/channel/api/tests/queryChannels.test.ts +20 -0
  77. package/src/channel/events/onChannelMemberAdded.ts +1 -1
  78. package/src/channel/observers/tests/liveChannels.test.ts +0 -1
  79. package/src/core/events.ts +1 -1
  80. package/src/core/model/idResolvers.ts +1 -1
  81. package/src/core/transports/http.ts +3 -17
  82. package/src/core/transports/test/http.test.ts +83 -0
  83. package/src/message/api/deleteMessage.ts +2 -3
  84. package/src/message/api/tests/createMessage.test.ts +74 -51
  85. package/src/message/api/tests/deleteMessage.test.ts +110 -0
  86. package/src/message/api/tests/getMessage.test.ts +121 -0
  87. package/src/message/api/tests/getMessages.test.ts +108 -0
  88. package/src/message/api/tests/queryMessages.test.ts +115 -0
  89. package/src/message/api/tests/updateMessage.test.ts +100 -0
  90. package/src/post/tests/api/queryPosts.test.ts +117 -18
  91. package/src/reaction/api/addReaction.ts +17 -6
  92. package/src/reaction/api/removeReaction.ts +17 -6
  93. package/src/reaction/api/tests/addReaction.test.ts +73 -0
  94. package/src/reaction/api/tests/removeReaction.test.ts +79 -0
  95. package/src/user/api/getUser.ts +1 -2
  96. package/src/user/api/queryUsers.ts +24 -5
  97. package/src/user/api/tests/queryUsers.test.ts +124 -0
  98. package/src/utils/tests/dummy/channel.ts +9 -1
  99. package/src/utils/tests/dummy/community.ts +44 -0
  100. package/src/utils/tests/dummy/file.ts +20 -0
  101. package/src/utils/tests/dummy/follow.ts +6 -0
  102. package/src/utils/tests/dummy/index.ts +9 -0
  103. package/src/utils/tests/dummy/message.ts +8 -1
  104. package/src/utils/tests/dummy/poll.ts +43 -0
  105. package/src/utils/tests/dummy/post.ts +65 -4
  106. package/src/utils/tests/dummy/reaction.ts +22 -0
  107. package/src/utils/tests/dummy/role.ts +21 -0
  108. package/src/utils/tests/dummy/user.ts +7 -1
  109. package/dist/message/tests/api/getMessage.test.d.ts.map +0 -1
  110. package/src/message/tests/api/getMessage.test.ts +0 -96
@@ -0,0 +1,73 @@
1
+ import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
2
+
3
+ import { onMessageUpdated } from '~/message/events';
4
+ import { addReaction } from '~/reaction/api';
5
+
6
+ import { client, message11 as message, pause } from '~/utils/tests';
7
+ import { UNSYNCED_OBJECT_CACHED_AT_VALUE } from '~/utils/constants';
8
+
9
+ const cacheKey = ['message', 'get', message.messageId];
10
+
11
+ describe('addReaction', () => {
12
+ test('it should add a reaction', async () => {
13
+ client.http.post = jest.fn().mockResolvedValue({ data: { addedId: 'reactionId' } });
14
+
15
+ const success = await addReaction('message', message.messageId, 'like');
16
+
17
+ expect(success).toEqual(true);
18
+ });
19
+
20
+ test('it should update cache after adding reaction', async () => {
21
+ enableCache();
22
+
23
+ pushToCache(cacheKey, message);
24
+ client.http.post = jest.fn().mockResolvedValue({ data: { addedId: 'reactionId' } });
25
+
26
+ const success = await addReaction('message', message.messageId, 'like');
27
+
28
+ expect(success).toEqual(true);
29
+ expect(pullFromCache(cacheKey)?.cachedAt).toBeDefined();
30
+ expect(pullFromCache(cacheKey)?.cachedAt).not.toBe(UNSYNCED_OBJECT_CACHED_AT_VALUE);
31
+ expect(pullFromCache(cacheKey)?.cachedAt).not.toBe(-1);
32
+
33
+ disableCache();
34
+ });
35
+ });
36
+
37
+ describe('addReaction > optimistically', () => {
38
+ beforeEach(enableCache);
39
+
40
+ afterEach(disableCache);
41
+
42
+ test('it should return undefined if cache disabled', () => {
43
+ disableCache();
44
+
45
+ expect(addReaction.optimistically('message', message.messageId, 'like')).toBeUndefined();
46
+ });
47
+
48
+ test('it should optimistically add a reaction', async () => {
49
+ const callback = jest.fn();
50
+ pushToCache(cacheKey, message);
51
+ onMessageUpdated(callback);
52
+
53
+ const success = addReaction.optimistically('message', message.messageId, 'like');
54
+
55
+ expect(success).toEqual(true);
56
+ expect(pullFromCache(cacheKey)?.data).toMatchObject({
57
+ myReactions: ['like'],
58
+ reactions: { like: 1 },
59
+ reactionsCount: 1,
60
+ });
61
+ await pause();
62
+ expect(callback).toBeCalledTimes(1);
63
+ });
64
+
65
+ test('it should mark optimistic object as unsynced', async () => {
66
+ pushToCache(cacheKey, message);
67
+
68
+ const success = addReaction.optimistically('message', message.messageId, 'like');
69
+
70
+ expect(success).toEqual(true);
71
+ expect(pullFromCache(cacheKey)?.cachedAt).toBe(UNSYNCED_OBJECT_CACHED_AT_VALUE);
72
+ });
73
+ });
@@ -0,0 +1,79 @@
1
+ import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
2
+
3
+ import { onMessageUpdated } from '~/message/events';
4
+ import { removeReaction } from '~/reaction/api';
5
+
6
+ import { UNSYNCED_OBJECT_CACHED_AT_VALUE } from '~/utils/constants';
7
+ import { client, message11, pause } from '~/utils/tests';
8
+
9
+ const message = {
10
+ ...message11,
11
+ myReactions: ['like'],
12
+ reactions: { like: 1 },
13
+ reactionsCount: 1,
14
+ };
15
+ const cacheKey = ['message', 'get', message.messageId];
16
+
17
+ describe('removeReaction', () => {
18
+ test('it should remove a reaction', async () => {
19
+ client.http.delete = jest.fn().mockResolvedValue({ data: { removedId: 'reactionId' } });
20
+
21
+ const success = await removeReaction('message', message.messageId, 'like');
22
+
23
+ expect(success).toEqual(true);
24
+ });
25
+
26
+ test('it should update cache after adding reaction', async () => {
27
+ enableCache();
28
+
29
+ pushToCache(cacheKey, message);
30
+ client.http.post = jest.fn().mockResolvedValue({ data: { addedId: 'reactionId' } });
31
+
32
+ const success = await removeReaction('message', message.messageId, 'like');
33
+
34
+ expect(success).toEqual(true);
35
+ expect(pullFromCache(cacheKey)?.cachedAt).toBeDefined();
36
+ expect(pullFromCache(cacheKey)?.cachedAt).not.toBe(UNSYNCED_OBJECT_CACHED_AT_VALUE);
37
+ expect(pullFromCache(cacheKey)?.cachedAt).not.toBe(-1);
38
+
39
+ disableCache();
40
+ });
41
+ });
42
+
43
+ describe('removeReaction > optimistically', () => {
44
+ beforeEach(enableCache);
45
+
46
+ afterEach(disableCache);
47
+
48
+ test('it should return undefined if cache disabled', () => {
49
+ disableCache();
50
+
51
+ expect(removeReaction.optimistically('message', message.messageId, 'like')).toBeUndefined();
52
+ });
53
+
54
+ test('it should optimistically remove a reaction', async () => {
55
+ const callback = jest.fn();
56
+ pushToCache(cacheKey, message);
57
+ onMessageUpdated(callback);
58
+
59
+ const success = removeReaction.optimistically('message', message.messageId, 'like');
60
+
61
+ expect(success).toEqual(true);
62
+ expect(pullFromCache(cacheKey)?.data).toMatchObject({
63
+ myReactions: [],
64
+ reactions: { like: 0 },
65
+ reactionsCount: 0,
66
+ });
67
+ await pause();
68
+ expect(callback).toBeCalledTimes(1);
69
+ });
70
+
71
+ test('it should mark optimistic object as unsynced', async () => {
72
+ pushToCache(cacheKey, message);
73
+
74
+ const success = removeReaction.optimistically('message', message.messageId, 'like');
75
+
76
+ expect(success).toEqual(true);
77
+ expect(pullFromCache(cacheKey)?.cachedAt).toBe(UNSYNCED_OBJECT_CACHED_AT_VALUE);
78
+ });
79
+ });
@@ -1,6 +1,6 @@
1
1
  import { getActiveClient } from '~/client/api';
2
2
 
3
- import { pullFromCache, dropFromCache } from '~/cache/api';
3
+ import { pullFromCache } from '~/cache/api';
4
4
  import { ingestInCache } from '~/cache/api/ingestInCache';
5
5
  import { fireEvent } from '~/core/events';
6
6
 
@@ -38,7 +38,6 @@ export const getUser = async (
38
38
  let data: Amity.UserPayload;
39
39
 
40
40
  try {
41
- // API-FIX: endpoint should not be /list, parameters should be querystring.
42
41
  const response = await client.http.get<Amity.UserPayload>(
43
42
  `/api/v3/users/${encodeURIComponent(userId)}`,
44
43
  );
@@ -33,9 +33,14 @@ export const queryUsers = async (
33
33
  const client = getActiveClient();
34
34
  client.log('user/queryUsers', query);
35
35
 
36
- const { page, displayName, filter = 'all', sortBy = 'displayName', ...params } = query;
36
+ const {
37
+ page = { limit: 10 },
38
+ displayName,
39
+ filter = 'all',
40
+ sortBy = 'displayName',
41
+ ...params
42
+ } = query;
37
43
 
38
- // API-FIX: parameters should be querystring.
39
44
  const { data } = await client.http.get<Amity.UserPayload & Amity.Pagination>(`/api/v3/users`, {
40
45
  params: {
41
46
  ...params,
@@ -57,7 +62,11 @@ export const queryUsers = async (
57
62
  if (client.cache) {
58
63
  ingestInCache(payload as Amity.UserPayload, { cachedAt });
59
64
 
60
- const cacheKey = ['user', 'query', query as Amity.Serializable];
65
+ /*
66
+ * using query as cache key over params because if the keyword, filter, sort
67
+ * change the API will NOT cache results, when it should
68
+ */
69
+ const cacheKey = ['user', 'query', { ...query, options: { ...page } } as Amity.Serializable];
61
70
  pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
62
71
  }
63
72
 
@@ -91,9 +100,19 @@ queryUsers.locally = (
91
100
 
92
101
  if (!client.cache) return;
93
102
 
94
- const queryKey = ['user', 'query', query as Amity.Serializable];
103
+ const { page = { limit: 10 } } = query ?? {};
104
+
105
+ const cacheKey = [
106
+ 'user',
107
+ 'query',
108
+ {
109
+ ...query,
110
+ options: { ...page },
111
+ } as Amity.Serializable,
112
+ ];
113
+
95
114
  const { data, cachedAt } =
96
- pullFromCache<{ users: Pick<Amity.User, 'userId'>[] } & Amity.Pagination>(queryKey) ?? {};
115
+ pullFromCache<{ users: Pick<Amity.User, 'userId'>[] } & Amity.Pagination>(cacheKey) ?? {};
97
116
 
98
117
  const users: Amity.User[] =
99
118
  data?.users
@@ -0,0 +1,124 @@
1
+ import { getResolver } from '~/core/model';
2
+
3
+ import { disableCache, enableCache, pushToCache } from '~/cache/api';
4
+ import { ingestInCache } from '~/cache/api/ingestInCache';
5
+
6
+ import { client, userQueryResponse } from '~/utils/tests';
7
+
8
+ import { queryUsers } from '../queryUsers';
9
+
10
+ describe('queryUsers', () => {
11
+ test('it should return users', async () => {
12
+ const { users: expected } = userQueryResponse.data;
13
+ client.http.get = jest.fn().mockResolvedValue(userQueryResponse);
14
+
15
+ const { data } = await queryUsers();
16
+
17
+ expect(data).toEqual(expected);
18
+ });
19
+
20
+ test('it should throw error', async () => {
21
+ client.http.get = jest.fn().mockRejectedValueOnce(new Error('error'));
22
+
23
+ await expect(queryUsers()).rejects.toThrow('error');
24
+ });
25
+
26
+ test('it should update cache upon fetching data from server', async () => {
27
+ enableCache();
28
+
29
+ client.http.get = jest.fn().mockResolvedValue(userQueryResponse);
30
+
31
+ const { data: expected } = await queryUsers();
32
+ const { data: received } = queryUsers.locally()!;
33
+
34
+ expect(received).toBeDefined();
35
+ expect(received).toEqual(expected);
36
+
37
+ disableCache();
38
+ });
39
+ });
40
+
41
+ describe('queryUsers.locally', () => {
42
+ const cacheKey = [
43
+ 'user',
44
+ 'query',
45
+ { options: { limit: 10, after: undefined } } as Amity.Serializable,
46
+ ];
47
+
48
+ test('it should fetch query locally if present in cache', () => {
49
+ enableCache();
50
+
51
+ const { data } = userQueryResponse;
52
+ const { users: expected, paging } = data;
53
+
54
+ ingestInCache(data as Amity.UserPayload);
55
+
56
+ pushToCache(cacheKey, { users: expected.map(getResolver('user')), paging });
57
+
58
+ const { data: received } = queryUsers.locally()!;
59
+
60
+ expect(received).toBeDefined();
61
+ expect(received).toEqual(expected);
62
+
63
+ disableCache();
64
+ });
65
+
66
+ test('it should return undefined if only partial data in cache', () => {
67
+ enableCache();
68
+
69
+ const { data } = userQueryResponse;
70
+ const { users, paging } = data;
71
+
72
+ // ingest incomplete data
73
+ ingestInCache({
74
+ ...data,
75
+ users: [data.users[0]],
76
+ } as Amity.UserPayload);
77
+
78
+ pushToCache(cacheKey, {
79
+ users: users.map(getResolver('user')),
80
+ paging,
81
+ });
82
+
83
+ const received = queryUsers.locally()!;
84
+
85
+ expect(received).toBeUndefined();
86
+
87
+ disableCache();
88
+ });
89
+
90
+ // added because of comment above cache key in queryUsers
91
+ test('it should return undefined if params do not match', () => {
92
+ enableCache();
93
+
94
+ const { data } = userQueryResponse;
95
+ const { users: expected, paging } = data;
96
+
97
+ ingestInCache(data as Amity.UserPayload);
98
+
99
+ pushToCache(cacheKey, { users: expected.map(getResolver('user')), paging });
100
+
101
+ const { data: received } = queryUsers.locally()!;
102
+ const received2 = queryUsers.locally({ displayName: 'test' })!;
103
+
104
+ expect(received).toBeDefined();
105
+ expect(received).toEqual(expected);
106
+ expect(received2).toBeUndefined();
107
+
108
+ disableCache();
109
+ });
110
+
111
+ test('it should return undefined if data not in cache', () => {
112
+ enableCache();
113
+
114
+ const received = queryUsers.locally();
115
+
116
+ expect(received).toBeUndefined();
117
+
118
+ disableCache();
119
+ });
120
+
121
+ test('it should return undefined if cache disabled', () => {
122
+ expect(queryUsers.locally()).toBeUndefined();
123
+ });
124
+ });
@@ -1,4 +1,4 @@
1
- import { date, rolesAndPermissions, user11, user12, user13 } from '.';
1
+ import { date, rolesAndPermissions, user11, user12, user13, file11 } from '.';
2
2
 
3
3
  const mockPage = {
4
4
  paging: {
@@ -177,3 +177,11 @@ export const channelUserQueryResponsePage3 = {
177
177
  ...mockPage,
178
178
  },
179
179
  };
180
+
181
+ // for testing ingest in cache
182
+ export const channelPayload = {
183
+ channels: [channel11],
184
+ channelUsers: [channelUser7, channelUser6],
185
+ users: [user11],
186
+ files: [file11],
187
+ };
@@ -0,0 +1,44 @@
1
+ import { file11, user11 } from '.';
2
+
3
+ export const community11: Amity.Community = {
4
+ path: '',
5
+ isOfficial: false,
6
+ isPublic: true,
7
+ postsCount: 7,
8
+ membersCount: 1,
9
+ updatedAt: '2022-10-31T05:06:57.999Z',
10
+ createdAt: '2022-10-31T02:48:34.978Z',
11
+ isDeleted: false,
12
+ displayName: 'HardDelete1',
13
+ tags: [],
14
+ metadata: {},
15
+ hasFlaggedComment: false,
16
+ hasFlaggedPost: true,
17
+ communityId: 'community11',
18
+ channelId: '635f3782064bf304f786707d',
19
+ userId: user11.userId,
20
+ isJoined: false,
21
+ avatarFileId: undefined,
22
+ categoryIds: [],
23
+ };
24
+
25
+ export const communityUser11: Amity.Membership<'community'> = {
26
+ communityMembership: 'member',
27
+ lastActivity: '2022-10-25T11:10:13.048Z',
28
+ updatedAt: '2022-10-25T11:10:13.048Z',
29
+ createdAt: '2022-10-25T11:10:13.048Z',
30
+ muteTimeout: '2022-10-25T11:10:13.048Z',
31
+ isMuted: false,
32
+ isBanned: false,
33
+ userId: 'test',
34
+ communityId: community11.communityId,
35
+ roles: ['channel-moderator', 'community-moderator'],
36
+ permissions: [Amity.Permission.CreateRolePermission],
37
+ };
38
+
39
+ export const communityPayload: Amity.CommunityPayload = {
40
+ communities: [community11],
41
+ communityUsers: [communityUser11],
42
+ files: [file11],
43
+ users: [user11],
44
+ };
@@ -0,0 +1,20 @@
1
+ export const file11: Amity.File<'image'> = {
2
+ fileId: 'file-Id',
3
+ fileUrl: 'https://fileUrl.com/test-file',
4
+ type: 'image',
5
+ createdAt: '2022-10-28T08:01:51.996Z',
6
+ updatedAt: '2022-10-28T08:01:51.996Z',
7
+ attributes: {
8
+ name: 'test.png',
9
+ extension: 'png',
10
+ size: '166904',
11
+ mimeType: 'image/png',
12
+ metadata: {
13
+ height: 966,
14
+ width: 1918,
15
+ isFull: false,
16
+ exif: {},
17
+ gps: {},
18
+ },
19
+ },
20
+ };
@@ -58,3 +58,9 @@ export const follows = {
58
58
  page1: [follow11, follow12, follow13],
59
59
  page2: [follow21, follow22, follow23],
60
60
  };
61
+
62
+ export const followPayload: Amity.FollowersPayload = {
63
+ users: [user11, user12],
64
+ files: [],
65
+ follows: [follow11, follow12],
66
+ };
@@ -2,7 +2,16 @@ export const date = new Date().toISOString();
2
2
  export const rolesAndPermissions = { roles: [], permissions: [] };
3
3
 
4
4
  export * from './user';
5
+ export * from './role';
6
+ export * from './file';
7
+
5
8
  export * from './post';
9
+
10
+ export * from './poll';
6
11
  export * from './follow';
12
+ export * from './reaction';
13
+
7
14
  export * from './channel';
15
+ export * from './community';
16
+
8
17
  export * from './message';
@@ -1,4 +1,4 @@
1
- import { date, channel11, user11 } from '.';
1
+ import { date, channel11, user11, file11 } from '.';
2
2
 
3
3
  export const message11: Amity.Message = {
4
4
  fileId: null,
@@ -33,3 +33,10 @@ export const messageQueryResponse = {
33
33
  },
34
34
  },
35
35
  };
36
+
37
+ // for testing ingest in cache
38
+ export const messagePayload = {
39
+ messages: [message11],
40
+ files: [file11],
41
+ users: [user11],
42
+ };
@@ -0,0 +1,43 @@
1
+ import { user11 } from '.';
2
+
3
+ export const poll11: Amity.Poll = {
4
+ pollId: 'c7b7c3e52be052be3fd5b5f0b4033d501667195535489',
5
+ userId: 'test',
6
+ question: 'Yellow',
7
+ answers: [
8
+ {
9
+ dataType: 'text',
10
+ data: '1',
11
+ isVotedByUser: false,
12
+ voteCount: 0,
13
+ id: '635f628f651eeb361624a8b6',
14
+ },
15
+ {
16
+ dataType: 'text',
17
+ data: '2',
18
+ isVotedByUser: false,
19
+ voteCount: 0,
20
+ id: '635f628f651eeb619424a8b7',
21
+ },
22
+ {
23
+ dataType: 'text',
24
+ data: '3',
25
+ isVotedByUser: false,
26
+ voteCount: 0,
27
+ id: '635f628f651eeb391f24a8b8',
28
+ },
29
+ ],
30
+ answerType: 'single',
31
+ closedAt: '2022-11-30T05:52:15.489Z',
32
+ createdAt: '2022-10-31T05:52:15.493Z',
33
+ updatedAt: '2022-10-31T05:52:15.493Z',
34
+ isVoted: false,
35
+ status: 'open',
36
+ closedIn: 2592000000,
37
+ isDeleted: false,
38
+ };
39
+
40
+ export const pollPayload: Amity.PollPayload = {
41
+ polls: [poll11],
42
+ users: [user11],
43
+ };
@@ -1,6 +1,7 @@
1
- import { user11, date } from '.';
1
+ import { user11, file11, communityUser11, date } from '.';
2
+ import { encodeJson } from '..';
2
3
 
3
- export const post1: Amity.Post = {
4
+ export const post11: Amity.Post = {
4
5
  path: '',
5
6
  feedId: '',
6
7
  children: [],
@@ -15,17 +16,77 @@ export const post1: Amity.Post = {
15
16
  postId: 'postId11',
16
17
  targetType: 'user',
17
18
  parentId: 'postId12',
18
- data: { text: 'post1' },
19
+ data: { text: 'post11' },
19
20
  targetId: user11.userId,
20
21
  hasFlaggedComment: false,
21
22
  hasFlaggedChildren: false,
22
23
  postedUserId: user11.userId,
23
24
  };
24
25
 
26
+ export const comment11: Amity.Comment = {
27
+ path: '',
28
+ referenceType: 'post',
29
+ dataType: 'text',
30
+ rootId: 'test',
31
+ data: {
32
+ text: 'yellow new world',
33
+ },
34
+ childrenNumber: 0,
35
+ isDeleted: false,
36
+ editedAt: '2022-10-31T05:57:45.661Z',
37
+ updatedAt: '2022-10-31T05:57:45.670Z',
38
+ createdAt: '2022-10-31T05:57:45.661Z',
39
+ segmentNumber: 2,
40
+ commentId: 'comment11',
41
+ userId: 'test',
42
+ referenceId: post11.postId,
43
+ flagCount: 0,
44
+ hashFlag: null,
45
+ children: [],
46
+ mentionees: [],
47
+ reactions: {},
48
+ reactionsCount: 0,
49
+ };
50
+
51
+ export const post12: Amity.Post = {
52
+ ...post11,
53
+ postId: 'post12',
54
+ };
55
+
56
+ export const post13: Amity.Post = {
57
+ ...post11,
58
+ postId: 'post13',
59
+ };
60
+
25
61
  export const posts = {
26
62
  targetId: user11.userId,
27
63
  targetType: 'user' as Amity.PostTargetType,
28
- page1: [post1.postId, 'postId12', 'postId13'],
64
+ page1: [post11.postId, post12.postId, post13.postId],
29
65
  page2: ['postId21', 'postId22', 'postId23'],
30
66
  page3: ['postId31', 'postId32', 'postId33'],
31
67
  };
68
+
69
+ export const commentPayload: Amity.CommentPayload = {
70
+ comments: [comment11],
71
+ users: [user11],
72
+ };
73
+
74
+ export const postPayload: Amity.PostPayload = {
75
+ posts: [post11],
76
+ users: [user11],
77
+ files: [file11],
78
+ comments: [comment11],
79
+ communityUsers: [],
80
+ };
81
+
82
+ const nextPage = encodeJson({ before: post13.postId, limit: 10 });
83
+
84
+ export const postQueryResponse = {
85
+ data: {
86
+ posts: [post11, post12, post13],
87
+ files: [],
88
+ paging: {
89
+ next: nextPage,
90
+ },
91
+ },
92
+ };
@@ -0,0 +1,22 @@
1
+ import { post11, user11 } from '.';
2
+
3
+ export const reaction11: Amity.Reaction = {
4
+ reactionName: 'reaction11',
5
+ reactionId: 'reaction11',
6
+ referenceId: post11.postId,
7
+ referenceType: 'post',
8
+ userId: user11.userId,
9
+ createdAt: '',
10
+ };
11
+
12
+ export const reactor11: Amity.Reactor = {
13
+ reactionName: 'reaction11',
14
+ reactionId: 'reaction11',
15
+ userId: user11.userId,
16
+ createdAt: '',
17
+ };
18
+
19
+ export const reactionPayload: Amity.ReactionPayload = {
20
+ reactions: [{ ...reaction11, reactors: [reactor11] }],
21
+ users: [user11],
22
+ };
@@ -0,0 +1,21 @@
1
+ export const role11: Amity.Role = {
2
+ roleId: 'channel moderator',
3
+ displayName: 'channel moderator',
4
+ createdAt: '2022-10-31T04:03:56.786Z',
5
+ updatedAt: '2022-10-31T04:03:56.786Z',
6
+ permissions: [],
7
+ isDeleted: false,
8
+ };
9
+
10
+ export const role12: Amity.Role = {
11
+ roleId: 'test',
12
+ displayName: 'test',
13
+ createdAt: '2022-10-26T04:33:17.344Z',
14
+ updatedAt: '2022-10-26T04:33:17.344Z',
15
+ permissions: [],
16
+ isDeleted: false,
17
+ };
18
+
19
+ export const rolePayload: Amity.RolePayload = {
20
+ roles: [role11, role12],
21
+ };
@@ -27,7 +27,7 @@ export const user14: Amity.User = {
27
27
 
28
28
  export const userQueryResponse = {
29
29
  data: {
30
- users: [user11],
30
+ users: [user11, user12],
31
31
  files: [],
32
32
  paging: {
33
33
  previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
@@ -35,3 +35,9 @@ export const userQueryResponse = {
35
35
  },
36
36
  },
37
37
  };
38
+
39
+ // user payload with file
40
+ export const userPayload: Amity.UserPayload = {
41
+ users: [user11, user12],
42
+ files: [{ fileId: 'test-file-id' } as Amity.File<'image'>],
43
+ };
@@ -1 +0,0 @@
1
- {"version":3,"file":"getMessage.test.d.ts","sourceRoot":"","sources":["../../../../src/message/tests/api/getMessage.test.ts"],"names":[],"mappings":""}