@amityco/ts-sdk 0.0.1-beta.28 → 0.0.1-beta.29

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 (83) hide show
  1. package/dist/@types/core/payload.d.ts +3 -3
  2. package/dist/@types/core/payload.d.ts.map +1 -1
  3. package/dist/@types/domains/channel.d.ts +12 -0
  4. package/dist/@types/domains/channel.d.ts.map +1 -1
  5. package/dist/@types/domains/community.d.ts +24 -2
  6. package/dist/@types/domains/community.d.ts.map +1 -1
  7. package/dist/@types/domains/content.d.ts +2 -1
  8. package/dist/@types/domains/content.d.ts.map +1 -1
  9. package/dist/@types/index.d.ts +1 -1
  10. package/dist/@types/index.d.ts.map +1 -1
  11. package/dist/channel/api/queryChannels.d.ts +1 -10
  12. package/dist/channel/api/queryChannels.d.ts.map +1 -1
  13. package/dist/channel/observers/index.d.ts +1 -0
  14. package/dist/channel/observers/index.d.ts.map +1 -1
  15. package/dist/channel/observers/liveChannels.d.ts +20 -0
  16. package/dist/channel/observers/liveChannels.d.ts.map +1 -0
  17. package/dist/channel/observers/tests/liveChannels.test.d.ts +2 -0
  18. package/dist/channel/observers/tests/liveChannels.test.d.ts.map +1 -0
  19. package/dist/community/api/createCommunity.d.ts +1 -1
  20. package/dist/community/api/createCommunity.d.ts.map +1 -1
  21. package/dist/community/api/getCommunities.d.ts.map +1 -1
  22. package/dist/community/api/getCommunity.d.ts.map +1 -1
  23. package/dist/community/api/getRecommendedCommunities.d.ts.map +1 -1
  24. package/dist/community/api/getTopTrendingCommunities.d.ts.map +1 -1
  25. package/dist/community/api/queryCommunities.d.ts.map +1 -1
  26. package/dist/community/api/updateCommunity.d.ts +1 -1
  27. package/dist/community/api/updateCommunity.d.ts.map +1 -1
  28. package/dist/community/events/utils.d.ts.map +1 -1
  29. package/dist/community/utils/index.d.ts +2 -0
  30. package/dist/community/utils/index.d.ts.map +1 -0
  31. package/dist/community/utils/payload.d.ts +11 -0
  32. package/dist/community/utils/payload.d.ts.map +1 -0
  33. package/dist/follow/tests/observers/liveFollowers.test.d.ts +2 -0
  34. package/dist/follow/tests/observers/liveFollowers.test.d.ts.map +1 -0
  35. package/dist/follow/tests/observers/liveFollowings.test.d.ts +2 -0
  36. package/dist/follow/tests/observers/liveFollowings.test.d.ts.map +1 -0
  37. package/dist/index.cjs.js +201 -20
  38. package/dist/index.esm.js +198 -21
  39. package/dist/index.umd.js +4 -4
  40. package/dist/utils/tests/dummy/channel.d.ts +25 -2
  41. package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
  42. package/dist/utils/tests/dummy/follow.d.ts +12 -0
  43. package/dist/utils/tests/dummy/follow.d.ts.map +1 -0
  44. package/dist/utils/tests/dummy/index.d.ts +1 -0
  45. package/dist/utils/tests/dummy/index.d.ts.map +1 -1
  46. package/dist/utils/tests/dummy/user.d.ts +3 -0
  47. package/dist/utils/tests/dummy/user.d.ts.map +1 -1
  48. package/dist/utils/tests/index.d.ts +1 -0
  49. package/dist/utils/tests/index.d.ts.map +1 -1
  50. package/dist/utils/tests/utils.d.ts +2 -0
  51. package/dist/utils/tests/utils.d.ts.map +1 -0
  52. package/package.json +1 -1
  53. package/src/@types/core/payload.ts +3 -3
  54. package/src/@types/domains/channel.ts +18 -0
  55. package/src/@types/domains/community.ts +27 -2
  56. package/src/@types/domains/content.ts +2 -1
  57. package/src/@types/index.ts +1 -1
  58. package/src/channel/api/queryChannels.ts +3 -10
  59. package/src/channel/observers/index.ts +1 -0
  60. package/src/channel/observers/liveChannels.ts +178 -0
  61. package/src/channel/observers/tests/liveChannels.test.ts +173 -0
  62. package/src/community/api/createCommunity.ts +9 -3
  63. package/src/community/api/getCommunities.ts +10 -3
  64. package/src/community/api/getCommunity.ts +5 -1
  65. package/src/community/api/getRecommendedCommunities.ts +5 -2
  66. package/src/community/api/getTopTrendingCommunities.ts +4 -1
  67. package/src/community/api/queryCommunities.ts +5 -2
  68. package/src/community/api/updateCommunity.ts +7 -3
  69. package/src/community/events/utils.ts +13 -7
  70. package/src/community/utils/index.ts +1 -0
  71. package/src/community/utils/payload.ts +44 -0
  72. package/src/core/model/identifyModel.ts +1 -1
  73. package/src/follow/observers/liveFollowers.ts +1 -1
  74. package/src/follow/observers/liveFollowings.ts +1 -1
  75. package/src/follow/tests/observers/liveFollowers.test.ts +240 -0
  76. package/src/follow/tests/observers/liveFollowings.test.ts +239 -0
  77. package/src/message/observers/tests/liveMessages.test.ts +202 -22
  78. package/src/utils/tests/dummy/channel.ts +48 -4
  79. package/src/utils/tests/dummy/follow.ts +60 -0
  80. package/src/utils/tests/dummy/index.ts +1 -0
  81. package/src/utils/tests/dummy/user.ts +15 -0
  82. package/src/utils/tests/index.ts +1 -0
  83. package/src/utils/tests/utils.ts +3 -0
@@ -0,0 +1,239 @@
1
+ import { ASCApiError } from '~/core/errors';
2
+ import { disableCache, enableCache } from '~/cache/api';
3
+ import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
4
+
5
+ import { queryFollowings } from '../../api/queryFollowings';
6
+ import { liveFollowings } from '../../observers/liveFollowings';
7
+
8
+ import {
9
+ client,
10
+ connectClient,
11
+ disconnectClient,
12
+ follows,
13
+ encodeJson,
14
+ follow11,
15
+ } from '~/utils/tests';
16
+
17
+ const getSnapshot = () => {
18
+ return {
19
+ loading: true,
20
+ error: undefined as any,
21
+ data: [] as Amity.FollowStatus[],
22
+ };
23
+ };
24
+
25
+ describe('liveFollowings', () => {
26
+ beforeAll(async () => {
27
+ await connectClient();
28
+ });
29
+
30
+ afterAll(async () => {
31
+ await disconnectClient();
32
+ });
33
+
34
+ beforeEach(enableCache);
35
+
36
+ afterEach(disableCache);
37
+
38
+ const { userId } = follows;
39
+ const args: Amity.FollowingLiveCollection = { userId };
40
+
41
+ test('it should show message if cache not enabled', () => {
42
+ /*
43
+ * NOTE: at the time of writing this test cache is diabled by default, but
44
+ * there is a proposal to enable cache by default. So I'm disabling cache
45
+ * here to ensure cache is disabled
46
+ */
47
+ disableCache();
48
+
49
+ const callback = jest.fn();
50
+ jest.spyOn(global.console, 'log');
51
+ client.http.get = jest.fn();
52
+
53
+ // call liveFollowings check if mocked console get's called with the correct
54
+ // message
55
+ client.use();
56
+ liveFollowings(args, callback);
57
+
58
+ expect(console.log).toBeCalledWith(ENABLE_CACHE_MESSAGE);
59
+ });
60
+
61
+ test('it should return following collection', async () => {
62
+ const snapshot = getSnapshot();
63
+ const response = { data: { paging: {}, follows: follows.page1 } };
64
+
65
+ const callback = jest.fn();
66
+ client.http.get = jest.fn().mockResolvedValue(response);
67
+
68
+ liveFollowings(args, callback);
69
+
70
+ expect(callback).toHaveBeenCalledTimes(1);
71
+
72
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining(snapshot));
73
+
74
+ await expect(queryFollowings(args)).resolves.toBeTruthy();
75
+
76
+ expect(callback).toHaveBeenCalledTimes(2);
77
+
78
+ snapshot.loading = false;
79
+ snapshot.data = response.data.follows;
80
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining(snapshot));
81
+ });
82
+
83
+ test('it should return error on api failure', async () => {
84
+ const snapshot = getSnapshot();
85
+ const error = new ASCApiError(
86
+ 'server error!',
87
+ Amity.ServerError.ITEM_NOT_FOUND,
88
+ Amity.ErrorLevel.ERROR,
89
+ );
90
+
91
+ const callback = jest.fn();
92
+ client.http.get = jest.fn().mockRejectedValue(error);
93
+
94
+ liveFollowings(args, callback);
95
+
96
+ expect(callback).toHaveBeenCalledTimes(1);
97
+
98
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining(snapshot));
99
+
100
+ await expect(queryFollowings(args)).rejects.toThrow();
101
+
102
+ expect(callback).toHaveBeenCalledTimes(2);
103
+
104
+ snapshot.error = error;
105
+ snapshot.loading = false;
106
+ expect(callback).toHaveBeenLastCalledWith(expect.objectContaining(snapshot));
107
+ });
108
+
109
+ const statusFilters: [string, Amity.FollowingLiveCollection][] = [
110
+ ['all', { ...args, status: 'all', limit: 10 }],
111
+ ['accepted', { ...args, status: 'accepted', limit: 10 }],
112
+ ['pending', { ...args, status: 'pending', limit: 10 }],
113
+ ];
114
+
115
+ test.each(statusFilters)('it should filter %s follows based on param', async (filter, params) => {
116
+ const snapshot = getSnapshot();
117
+ const response = { data: { paging: {}, follows: follows.page1 } };
118
+
119
+ const callback = jest.fn();
120
+ client.http.get = jest.fn().mockResolvedValue(response);
121
+
122
+ liveFollowings(params, callback);
123
+
124
+ expect(callback).toHaveBeenCalledTimes(1);
125
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining(snapshot));
126
+
127
+ // TODO : why ts gives no shit about args here ? wrong type :D
128
+ const query = queryFollowings(params);
129
+
130
+ await expect(query).resolves.toBeTruthy();
131
+
132
+ expect(callback).toHaveBeenCalledTimes(2);
133
+
134
+ snapshot.loading = false;
135
+ snapshot.data =
136
+ filter === 'all'
137
+ ? response.data.follows
138
+ : response.data.follows.filter(fl => fl.status === filter);
139
+ expect(callback).toHaveBeenCalledWith(expect.objectContaining(snapshot));
140
+ });
141
+
142
+ test('it should return method to fetch next page', async () => {
143
+ const snapshot = getSnapshot();
144
+ const args: Amity.FollowingLiveCollection = { userId, limit: 3 };
145
+ const next = encodeJson({
146
+ limit: 3,
147
+ before: follows.page1[2].from,
148
+ updatedAt: follows.page1[2].updatedAt,
149
+ });
150
+
151
+ const response = { data: { follows: follows.page2, paging: {} } };
152
+ const responseWithNextPage = { data: { follows: follows.page1, paging: { next } } };
153
+
154
+ const callback = jest.fn();
155
+ client.http.get = jest.fn().mockResolvedValue(responseWithNextPage);
156
+
157
+ liveFollowings(args, callback);
158
+
159
+ expect(callback).toHaveBeenCalled();
160
+
161
+ await expect(queryFollowings(args)).resolves.toBeTruthy();
162
+
163
+ expect(callback.mock.lastCall).toHaveLength(1);
164
+
165
+ const { onNextPage, hasNextPage } = callback.mock.lastCall[0];
166
+
167
+ expect(hasNextPage).toBe(true);
168
+ expect(onNextPage).toBeTruthy();
169
+
170
+ client.http.get = jest.fn().mockResolvedValue(response);
171
+
172
+ onNextPage();
173
+
174
+ await expect(queryFollowings(args)).resolves.toBeTruthy();
175
+
176
+ expect(callback).toHaveBeenCalledTimes(4);
177
+
178
+ snapshot.loading = false;
179
+ snapshot.data = [...responseWithNextPage.data.follows, ...response.data.follows];
180
+ expect(callback).toHaveBeenNthCalledWith(4, expect.objectContaining(snapshot));
181
+ });
182
+
183
+ const createEvents: [keyof Amity.Events][] = [
184
+ ['follow.created'],
185
+ ['follow.requested'],
186
+ ['follow.accepted'],
187
+ ];
188
+
189
+ test.each(createEvents)('it should add new follow to collection on %s', async event => {
190
+ const snapshot = getSnapshot();
191
+ const newFollowing: Amity.FollowStatus = {
192
+ ...follow11,
193
+ to: 'some-user',
194
+ };
195
+ const response = { data: { follows: follows.page1, paging: {} } };
196
+
197
+ const callback = jest.fn();
198
+ client.http.get = jest.fn().mockResolvedValue(response);
199
+
200
+ liveFollowings(args, callback);
201
+
202
+ await expect(queryFollowings(args)).resolves.toBeTruthy();
203
+ expect(callback).toHaveBeenCalledTimes(2);
204
+
205
+ client.emitter.emit(event, { follows: [newFollowing] });
206
+
207
+ snapshot.loading = false;
208
+ snapshot.data = [newFollowing, ...response.data.follows];
209
+ expect(callback).toHaveBeenNthCalledWith(3, expect.objectContaining(snapshot));
210
+ });
211
+
212
+ const removeEvents: [keyof Amity.Events][] = [
213
+ ['follow.requestDeclined'],
214
+ ['follow.requestCanceled'],
215
+ ['follow.unfollowed'],
216
+ ['follow.followerDeleted'],
217
+ ];
218
+
219
+ test.each(removeEvents)('it should remove a follow to collection on %s', async event => {
220
+ const snapshot = getSnapshot();
221
+ const response = { data: { follows: follows.page1, paging: {} } };
222
+
223
+ const callback = jest.fn();
224
+ client.http.get = jest.fn().mockResolvedValue(response);
225
+
226
+ liveFollowings(args, callback);
227
+
228
+ await expect(queryFollowings(args)).resolves.toBeTruthy();
229
+ expect(callback).toHaveBeenCalledTimes(2);
230
+
231
+ client.emitter.emit(event, { follows: [response.data.follows[0]] });
232
+
233
+ const [first, ...data] = response.data.follows;
234
+
235
+ snapshot.data = data;
236
+ snapshot.loading = false;
237
+ expect(callback).toHaveBeenNthCalledWith(3, expect.objectContaining(snapshot));
238
+ });
239
+ });
@@ -1,15 +1,37 @@
1
- import { disableCache, enableCache, pushToCache } from '~/cache/api';
1
+ import { ASCApiError } from '~/core/errors';
2
+ import { disableCache, enableCache } from '~/cache/api';
2
3
  import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
3
4
 
4
5
  import { liveMessages } from '../liveMessages';
5
-
6
- import { client, messages } from '~/utils/tests';
7
6
  import { queryMessages } from '~/message/api';
8
7
 
8
+ import {
9
+ client,
10
+ connectClient,
11
+ disconnectClient,
12
+ messages,
13
+ message as defaultMessage,
14
+ } from '~/utils/tests';
15
+
9
16
  describe('liveMessages', () => {
10
- beforeEach(enableCache);
17
+ beforeAll(async () => {
18
+ await connectClient();
19
+ });
20
+
21
+ afterAll(async () => {
22
+ await disconnectClient();
23
+ });
24
+
25
+ beforeEach(async () => {
26
+ enableCache();
27
+ });
28
+
11
29
  afterEach(disableCache);
12
30
 
31
+ const { channelId } = messages;
32
+ const returnValue = [{ messageId: messages.page1[0] }];
33
+ const message = { ...defaultMessage, messageId: returnValue[0].messageId, channelId };
34
+
13
35
  test('it should show message if cache not enabled', () => {
14
36
  /*
15
37
  * NOTE: at the time of writing this test cache is diabled by default, but
@@ -25,14 +47,12 @@ describe('liveMessages', () => {
25
47
  // call liveMessages check if mocked console get's called with the correct
26
48
  // message
27
49
  client.use();
28
- liveMessages({ channelId: messages.channelId }, callback);
50
+ liveMessages({ channelId }, callback);
29
51
 
30
52
  expect(console.log).toBeCalledWith(ENABLE_CACHE_MESSAGE);
31
53
  });
32
54
 
33
55
  test('it should return message collection', async () => {
34
- const returnValue = [{ messageId: messages.page1[0] }];
35
-
36
56
  // mock response of queryMessages and validate
37
57
  const callback = jest.fn();
38
58
  client.http.get = jest.fn().mockResolvedValue({
@@ -42,7 +62,7 @@ describe('liveMessages', () => {
42
62
  },
43
63
  });
44
64
 
45
- liveMessages({ channelId: messages.channelId }, callback);
65
+ liveMessages({ channelId }, callback);
46
66
 
47
67
  expect(callback).toHaveBeenCalledTimes(1);
48
68
 
@@ -55,7 +75,7 @@ describe('liveMessages', () => {
55
75
  }),
56
76
  );
57
77
 
58
- await expect(queryMessages({ channelId: messages.channelId })).resolves.toBeTruthy();
78
+ await expect(queryMessages({ channelId })).resolves.toBeTruthy();
59
79
 
60
80
  expect(callback).toHaveBeenCalledTimes(2);
61
81
 
@@ -68,6 +88,43 @@ describe('liveMessages', () => {
68
88
  );
69
89
  });
70
90
 
91
+ test('it should return error on api failure', async () => {
92
+ const error = new ASCApiError(
93
+ 'server error!',
94
+ Amity.ServerError.ITEM_NOT_FOUND,
95
+ Amity.ErrorLevel.ERROR,
96
+ );
97
+
98
+ // mock response of queryMessages and validate
99
+ const callback = jest.fn();
100
+ client.http.get = jest.fn().mockRejectedValue(error);
101
+
102
+ liveMessages({ channelId }, callback);
103
+
104
+ expect(callback).toHaveBeenCalledTimes(1);
105
+
106
+ // check if cache data returned (should be empty)
107
+ expect(callback).toHaveBeenCalledWith(
108
+ expect.objectContaining({
109
+ data: [],
110
+ error: undefined,
111
+ loading: true,
112
+ }),
113
+ );
114
+
115
+ await expect(queryMessages({ channelId })).rejects.toThrow();
116
+
117
+ expect(callback).toHaveBeenCalledTimes(2);
118
+
119
+ expect(callback).toHaveBeenLastCalledWith(
120
+ expect.objectContaining({
121
+ error,
122
+ data: [],
123
+ loading: false,
124
+ }),
125
+ );
126
+ });
127
+
71
128
  test('it should filter deleted messages based on param', async () => {
72
129
  // mock response of queryMessages with a deleted message
73
130
  const returnValue = [
@@ -84,7 +141,7 @@ describe('liveMessages', () => {
84
141
  },
85
142
  });
86
143
 
87
- liveMessages({ channelId: messages.channelId, isDeleted: false }, callback);
144
+ liveMessages({ channelId, isDeleted: false }, callback);
88
145
 
89
146
  expect(callback).toHaveBeenCalledTimes(1);
90
147
 
@@ -97,7 +154,7 @@ describe('liveMessages', () => {
97
154
  }),
98
155
  );
99
156
 
100
- await expect(queryMessages({ channelId: messages.channelId })).resolves.toBeTruthy();
157
+ await expect(queryMessages({ channelId })).resolves.toBeTruthy();
101
158
 
102
159
  expect(callback).toHaveBeenCalledTimes(2);
103
160
 
@@ -111,23 +168,146 @@ describe('liveMessages', () => {
111
168
  });
112
169
 
113
170
  test('it should return method to fetch next page', async () => {
114
- // mock nextPage()
115
- });
171
+ const returnValue2 = [{ messageId: messages.page2[0] }];
172
+
173
+ const callback = jest.fn();
174
+ client.http.get = jest
175
+ .fn()
176
+ .mockResolvedValue({
177
+ data: {
178
+ messages: returnValue,
179
+ paging: {
180
+ previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
181
+ next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
182
+ },
183
+ },
184
+ })
185
+ .mockResolvedValueOnce({
186
+ data: {
187
+ messages: returnValue2,
188
+ paging: {
189
+ previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
190
+ next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
191
+ },
192
+ },
193
+ });
194
+
195
+ liveMessages({ channelId }, callback);
196
+
197
+ expect(callback).toHaveBeenCalled();
116
198
 
117
- test('it should add new message to collection onCreate', () => {
118
- // new message should be added to top of collection
199
+ await expect(queryMessages({ channelId })).resolves.toBeTruthy();
200
+
201
+ expect(callback.mock.lastCall).toHaveLength(1);
202
+
203
+ const { onNextPage, hasNextPage } = callback.mock.lastCall[0];
204
+
205
+ expect(hasNextPage).toBe(true);
206
+ expect(onNextPage).toBeTruthy();
207
+
208
+ onNextPage();
209
+
210
+ await expect(queryMessages({ channelId })).resolves.toBeTruthy();
211
+
212
+ // 4 -> becuase 1 local & server call each per call (2)
213
+ expect(callback).toHaveBeenCalledTimes(4);
214
+
215
+ expect(callback).toHaveBeenNthCalledWith(
216
+ 4,
217
+ expect.objectContaining({
218
+ data: [...returnValue2, ...returnValue],
219
+ error: undefined,
220
+ loading: false,
221
+ }),
222
+ );
119
223
  });
120
224
 
121
- test('it should update message in collection onUpdate', () => {
122
- // updated message should be reflected in collection
225
+ test('it should add new message to collection onCreate', async () => {
226
+ const newMessage = {
227
+ ...message,
228
+ messageId: 'new-messageId',
229
+ };
230
+
231
+ // mock response of queryMessages and validate
232
+ const callback = jest.fn();
233
+ client.http.get = jest.fn().mockResolvedValue({
234
+ data: {
235
+ messages: returnValue,
236
+ paging: {},
237
+ },
238
+ });
239
+
240
+ liveMessages({ channelId }, callback);
241
+
242
+ await expect(queryMessages({ channelId })).resolves.toBeTruthy();
243
+ expect(callback).toHaveBeenCalledTimes(2);
244
+
245
+ // fire new message creation event
246
+ client.emitter.emit('v3.message.didCreate', { messages: [newMessage] });
247
+
248
+ expect(callback).toHaveBeenNthCalledWith(
249
+ 3,
250
+ expect.objectContaining({
251
+ data: [newMessage, ...returnValue],
252
+ error: undefined,
253
+ loading: false,
254
+ }),
255
+ );
123
256
  });
124
257
 
125
- test('it should delete message from collection onDelete', () => {
126
- // should remove message from collection on delete
258
+ test('it should add new message to collection onUpdate', async () => {
259
+ // mock response of queryMessages and validate
260
+ const callback = jest.fn();
261
+ client.http.get = jest.fn().mockResolvedValue({
262
+ data: {
263
+ messages: returnValue,
264
+ paging: {},
265
+ },
266
+ });
267
+
268
+ liveMessages({ channelId }, callback);
269
+
270
+ await expect(queryMessages({ channelId })).resolves.toBeTruthy();
271
+ expect(callback).toHaveBeenCalledTimes(2);
272
+
273
+ // fire new message creation event
274
+ client.emitter.emit('v3.message.didUpdate', { messages: [message] });
275
+
276
+ expect(callback).toHaveBeenNthCalledWith(
277
+ 3,
278
+ expect.objectContaining({
279
+ data: [message],
280
+ error: undefined,
281
+ loading: false,
282
+ }),
283
+ );
127
284
  });
128
285
 
129
- test('it should get messages from cache if present', () => {
130
- // push message with Id in collection response to cache
131
- // get request to get that messageId should not be called
286
+ test('it should add new message to collection onDelete', async () => {
287
+ // mock response of queryMessages and validate
288
+ const callback = jest.fn();
289
+ client.http.get = jest.fn().mockResolvedValue({
290
+ data: {
291
+ messages: returnValue,
292
+ paging: {},
293
+ },
294
+ });
295
+
296
+ liveMessages({ channelId }, callback);
297
+
298
+ await expect(queryMessages({ channelId })).resolves.toBeTruthy();
299
+ expect(callback).toHaveBeenCalledTimes(2);
300
+
301
+ // fire new message creation event
302
+ client.emitter.emit('v3.message.didDelete', { messages: [message] });
303
+
304
+ expect(callback).toHaveBeenNthCalledWith(
305
+ 3,
306
+ expect.objectContaining({
307
+ data: [],
308
+ error: undefined,
309
+ loading: false,
310
+ }),
311
+ );
132
312
  });
133
313
  });
@@ -14,16 +14,38 @@ export const channelRaw2: Amity.ChannelRaw = {
14
14
  channelId: 'channelId12',
15
15
  };
16
16
 
17
+ export const channelRaw3: Amity.ChannelRaw = {
18
+ messageCount: 3,
19
+ createdAt: date,
20
+ type: 'community',
21
+ channelId: 'channelId21',
22
+ };
23
+
17
24
  export const channel11: Amity.Channel = {
18
25
  ...channelRaw1,
19
26
  hasMention: false,
20
27
  unreadCount: 0,
28
+ type: 'community',
29
+ isDeleted: false,
30
+ tags: ['tag2'],
21
31
  };
22
32
 
23
33
  export const channel12: Amity.Channel = {
24
34
  ...channelRaw2,
25
- hasMention: true,
26
- unreadCount: 2,
35
+ hasMention: false,
36
+ unreadCount: 0,
37
+ type: 'conversation',
38
+ isDeleted: true,
39
+ tags: ['tag1'],
40
+ };
41
+
42
+ export const channel21: Amity.Channel = {
43
+ ...channelRaw3,
44
+ hasMention: false,
45
+ unreadCount: 0,
46
+ type: 'conversation',
47
+ isDeleted: true,
48
+ tags: ['tag1'],
27
49
  };
28
50
 
29
51
  export const channelUser1: Amity.Membership<'channel'> = {
@@ -47,6 +69,28 @@ export const channelUser2: Amity.Membership<'channel'> = {
47
69
  channelId: channel12.channelId,
48
70
  };
49
71
 
50
- export const channels = {
51
- page1: [channel11.channelId, channel12.channelId],
72
+ export const channelQueryResponse = {
73
+ data: {
74
+ channels: [channel11, channel12],
75
+ channelUsers: [],
76
+ files: [],
77
+ users: [],
78
+ paging: {
79
+ previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
80
+ next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
81
+ },
82
+ },
83
+ };
84
+
85
+ export const channelQueryResponsePage2 = {
86
+ data: {
87
+ channels: [channel21],
88
+ channelUsers: [],
89
+ files: [],
90
+ users: [],
91
+ paging: {
92
+ previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
93
+ next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
94
+ },
95
+ },
52
96
  };
@@ -0,0 +1,60 @@
1
+ import { date, user11, user12, user13, user14 } from '.';
2
+
3
+ const timeStamps: Amity.Timestamps = {
4
+ createdAt: date,
5
+ updatedAt: date,
6
+ };
7
+
8
+ // user11 follows user12
9
+ export const follow11: Amity.FollowStatus = {
10
+ ...timeStamps,
11
+ to: user12.userId,
12
+ status: 'accepted',
13
+ from: user11.userId,
14
+ };
15
+
16
+ // user11 pineding user13
17
+ export const follow12: Amity.FollowStatus = {
18
+ ...timeStamps,
19
+ status: 'pending',
20
+ to: user13.userId,
21
+ from: user11.userId,
22
+ };
23
+
24
+ // user14 declined user11
25
+ export const follow13: Amity.FollowStatus = {
26
+ ...timeStamps,
27
+ status: 'none',
28
+ to: user14.userId,
29
+ from: user11.userId,
30
+ };
31
+
32
+ // user12 follows user11
33
+ export const follow21: Amity.FollowStatus = {
34
+ ...timeStamps,
35
+ status: 'accepted',
36
+ to: user11.userId,
37
+ from: user12.userId,
38
+ };
39
+
40
+ // user13 pineding user11
41
+ export const follow22: Amity.FollowStatus = {
42
+ ...timeStamps,
43
+ status: 'pending',
44
+ to: user11.userId,
45
+ from: user13.userId,
46
+ };
47
+
48
+ // user11 declined user14
49
+ export const follow23: Amity.FollowStatus = {
50
+ ...timeStamps,
51
+ status: 'none',
52
+ to: user11.userId,
53
+ from: user14.userId,
54
+ };
55
+
56
+ export const follows = {
57
+ userId: user11.userId,
58
+ page1: [follow11, follow12, follow13],
59
+ page2: [follow21, follow22, follow23],
60
+ };
@@ -3,5 +3,6 @@ export const rolesAndPermissions = { roles: [], permissions: [] };
3
3
 
4
4
  export * from './user';
5
5
  export * from './post';
6
+ export * from './follow';
6
7
  export * from './channel';
7
8
  export * from './message';
@@ -9,3 +9,18 @@ export const user11: Amity.User = {
9
9
  createdAt: date,
10
10
  ...rolesAndPermissions,
11
11
  };
12
+
13
+ export const user12: Amity.User = {
14
+ ...user11,
15
+ userId: 'user2',
16
+ };
17
+
18
+ export const user13: Amity.User = {
19
+ ...user11,
20
+ userId: 'user3',
21
+ };
22
+
23
+ export const user14: Amity.User = {
24
+ ...user11,
25
+ userId: 'user4',
26
+ };
@@ -1,2 +1,3 @@
1
+ export * from './utils';
1
2
  export * from './dummy';
2
3
  export * from './client';
@@ -0,0 +1,3 @@
1
+ import { encode } from 'js-base64';
2
+
3
+ export const encodeJson = (value: Record<string, any>) => encode(JSON.stringify(value));