@amityco/ts-sdk 0.0.1-beta.27 → 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.
- package/.eslintrc.json +1 -0
- package/dist/@types/core/payload.d.ts +15 -13
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +17 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +13 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +24 -2
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +27 -3
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +36 -3
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +11 -0
- package/dist/@types/domains/follow.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +1 -0
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +13 -0
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/global.d.ts +1 -0
- package/dist/@types/global.d.ts.map +1 -1
- package/dist/@types/index.d.ts +3 -3
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/banChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/createChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannels.d.ts.map +1 -1
- package/dist/channel/api/joinChannel.d.ts.map +1 -1
- package/dist/channel/api/leaveChannel.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/queryChannels.d.ts +1 -10
- package/dist/channel/api/queryChannels.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/unbanChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/updateChannel.d.ts.map +1 -1
- package/dist/channel/events/index.d.ts +1 -0
- package/dist/channel/events/index.d.ts.map +1 -1
- package/dist/channel/events/onChannelCreated.d.ts.map +1 -1
- package/dist/channel/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channel/events/onChannelJoined.d.ts.map +1 -1
- package/dist/channel/events/onChannelLeft.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberAdded.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberRemoved.d.ts.map +1 -1
- package/dist/channel/events/onChannelUpdated.d.ts.map +1 -1
- package/dist/channel/observers/index.d.ts +2 -0
- package/dist/channel/observers/index.d.ts.map +1 -1
- package/dist/channel/observers/liveChannels.d.ts +20 -0
- package/dist/channel/observers/liveChannels.d.ts.map +1 -0
- package/dist/channel/observers/observeChannel.d.ts +1 -1
- package/dist/channel/observers/observeChannel.d.ts.map +1 -1
- package/dist/channel/observers/observeChannels.d.ts +17 -0
- package/dist/channel/observers/observeChannels.d.ts.map +1 -0
- package/dist/channel/observers/tests/liveChannels.test.d.ts +2 -0
- package/dist/channel/observers/tests/liveChannels.test.d.ts.map +1 -0
- package/dist/channel/tests/utils/prepareChannelPayload.test.d.ts +2 -0
- package/dist/channel/tests/utils/prepareChannelPayload.test.d.ts.map +1 -0
- package/dist/channel/utils/index.d.ts +2 -0
- package/dist/channel/utils/index.d.ts.map +1 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts +3 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts.map +1 -0
- package/dist/client/api/connectClient.d.ts +1 -8
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +8 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getFeedSettings.d.ts +16 -0
- package/dist/client/api/getFeedSettings.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/community/api/createCommunity.d.ts +1 -1
- package/dist/community/api/createCommunity.d.ts.map +1 -1
- package/dist/community/api/getCommunities.d.ts.map +1 -1
- package/dist/community/api/getCommunity.d.ts.map +1 -1
- package/dist/community/api/getRecommendedCommunities.d.ts.map +1 -1
- package/dist/community/api/getTopTrendingCommunities.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/api/updateCommunity.d.ts +1 -1
- package/dist/community/api/updateCommunity.d.ts.map +1 -1
- package/dist/community/events/utils.d.ts.map +1 -1
- package/dist/community/utils/index.d.ts +2 -0
- package/dist/community/utils/index.d.ts.map +1 -0
- package/dist/community/utils/payload.d.ts +11 -0
- package/dist/community/utils/payload.d.ts.map +1 -0
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/query/query.d.ts +1 -1
- package/dist/core/tests/query/query/runQuery.test.d.ts +2 -0
- package/dist/core/tests/query/query/runQuery.test.d.ts.map +1 -0
- package/dist/file/api/createVideo.d.ts +2 -1
- package/dist/file/api/createVideo.d.ts.map +1 -1
- package/dist/follow/api/queryFollowers.d.ts +1 -5
- package/dist/follow/api/queryFollowers.d.ts.map +1 -1
- package/dist/follow/api/queryFollowings.d.ts +1 -5
- package/dist/follow/api/queryFollowings.d.ts.map +1 -1
- package/dist/follow/observers/index.d.ts +2 -0
- package/dist/follow/observers/index.d.ts.map +1 -1
- package/dist/follow/observers/liveFollowers.d.ts +20 -0
- package/dist/follow/observers/liveFollowers.d.ts.map +1 -0
- package/dist/follow/observers/liveFollowings.d.ts +20 -0
- package/dist/follow/observers/liveFollowings.d.ts.map +1 -0
- package/dist/follow/tests/observers/liveFollowers.test.d.ts +2 -0
- package/dist/follow/tests/observers/liveFollowers.test.d.ts.map +1 -0
- package/dist/follow/tests/observers/liveFollowings.test.d.ts +2 -0
- package/dist/follow/tests/observers/liveFollowings.test.d.ts.map +1 -0
- package/dist/index.cjs.js +751 -128
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +737 -129
- package/dist/index.umd.js +4 -4
- package/dist/message/api/queryMessages.d.ts +1 -10
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/message/observers/index.d.ts +1 -0
- package/dist/message/observers/index.d.ts.map +1 -1
- package/dist/message/observers/liveMessages.d.ts +20 -0
- package/dist/message/observers/liveMessages.d.ts.map +1 -0
- package/dist/message/observers/observeMessages.d.ts +0 -1
- package/dist/message/observers/observeMessages.d.ts.map +1 -1
- package/dist/message/observers/tests/liveMessages.test.d.ts +2 -0
- package/dist/message/observers/tests/liveMessages.test.d.ts.map +1 -0
- package/dist/post/observers/livePosts.d.ts.map +1 -1
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/tests/client.d.ts +5 -2
- package/dist/utils/tests/client.d.ts.map +1 -1
- package/dist/utils/tests/dummy/channel.d.ts +33 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -0
- package/dist/utils/tests/dummy/follow.d.ts +12 -0
- package/dist/utils/tests/dummy/follow.d.ts.map +1 -0
- package/dist/utils/tests/dummy/index.d.ts +11 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -0
- package/dist/utils/tests/dummy/message.d.ts +8 -0
- package/dist/utils/tests/dummy/message.d.ts.map +1 -0
- package/dist/utils/tests/{dummy.d.ts → dummy/post.d.ts} +3 -2
- package/dist/utils/tests/dummy/post.d.ts.map +1 -0
- package/dist/utils/tests/dummy/user.d.ts +5 -0
- package/dist/utils/tests/dummy/user.d.ts.map +1 -0
- package/dist/utils/tests/index.d.ts +3 -2
- package/dist/utils/tests/index.d.ts.map +1 -1
- package/dist/utils/tests/utils.d.ts +2 -0
- package/dist/utils/tests/utils.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/core/payload.ts +19 -13
- package/src/@types/domains/channel.ts +34 -1
- package/src/@types/domains/client.ts +17 -0
- package/src/@types/domains/community.ts +27 -2
- package/src/@types/domains/content.ts +35 -3
- package/src/@types/domains/file.ts +42 -3
- package/src/@types/domains/follow.ts +28 -0
- package/src/@types/domains/group.ts +1 -0
- package/src/@types/domains/message.ts +20 -0
- package/src/@types/global.ts +2 -0
- package/src/@types/index.ts +4 -3
- package/src/channel/api/addChannelMembers.ts +6 -5
- package/src/channel/api/addChannelMembersRole.ts +5 -1
- package/src/channel/api/banChannelMembers.ts +7 -3
- package/src/channel/api/createChannel.ts +6 -2
- package/src/channel/api/getChannel.ts +5 -1
- package/src/channel/api/getChannels.ts +5 -1
- package/src/channel/api/joinChannel.ts +5 -1
- package/src/channel/api/leaveChannel.ts +5 -1
- package/src/channel/api/queryChannelMembers.ts +16 -12
- package/src/channel/api/queryChannels.ts +12 -14
- package/src/channel/api/removeChannelMembers.ts +6 -5
- package/src/channel/api/removeChannelMembersRole.ts +5 -1
- package/src/channel/api/unbanChannelMembers.ts +7 -3
- package/src/channel/api/updateChannel.ts +5 -1
- package/src/channel/events/index.ts +1 -0
- package/src/channel/events/onChannelCreated.ts +6 -2
- package/src/channel/events/onChannelDeleted.ts +6 -2
- package/src/channel/events/onChannelJoined.ts +6 -2
- package/src/channel/events/onChannelLeft.ts +6 -2
- package/src/channel/events/onChannelMemberAdded.ts +6 -2
- package/src/channel/events/onChannelMemberRemoved.ts +6 -2
- package/src/channel/events/onChannelUpdated.ts +6 -2
- package/src/channel/observers/index.ts +2 -0
- package/src/channel/observers/liveChannels.ts +178 -0
- package/src/channel/observers/observeChannel.ts +1 -11
- package/src/channel/observers/observeChannels.ts +59 -0
- package/src/channel/observers/tests/liveChannels.test.ts +173 -0
- package/src/channel/tests/utils/prepareChannelPayload.test.ts +120 -0
- package/src/channel/utils/index.ts +1 -0
- package/src/channel/utils/prepareChannelPayload.ts +31 -0
- package/src/client/api/connectClient.ts +4 -9
- package/src/client/api/createClient.ts +19 -4
- package/src/client/api/getFeedSettings.ts +29 -0
- package/src/client/api/index.ts +2 -0
- package/src/community/api/createCommunity.ts +9 -3
- package/src/community/api/getCommunities.ts +10 -3
- package/src/community/api/getCommunity.ts +5 -1
- package/src/community/api/getRecommendedCommunities.ts +5 -2
- package/src/community/api/getTopTrendingCommunities.ts +4 -1
- package/src/community/api/queryCommunities.ts +5 -2
- package/src/community/api/updateCommunity.ts +7 -3
- package/src/community/events/utils.ts +13 -7
- package/src/community/utils/index.ts +1 -0
- package/src/community/utils/payload.ts +44 -0
- package/src/core/events.ts +2 -1
- package/src/core/model/identifyModel.ts +1 -1
- package/src/core/query/query.ts +3 -3
- package/src/core/tests/query/query/runQuery.test.ts +182 -0
- package/src/file/api/createVideo.ts +6 -0
- package/src/follow/api/queryFollowers.ts +3 -5
- package/src/follow/api/queryFollowings.ts +3 -5
- package/src/follow/api/utils.ts +7 -3
- package/src/follow/observers/index.ts +3 -0
- package/src/follow/observers/liveFollowers.ts +149 -0
- package/src/follow/observers/liveFollowings.ts +149 -0
- package/src/follow/tests/observers/liveFollowers.test.ts +240 -0
- package/src/follow/tests/observers/liveFollowings.test.ts +239 -0
- package/src/index.ts +1 -1
- package/src/message/api/queryMessages.ts +3 -10
- package/src/message/observers/index.ts +1 -0
- package/src/message/observers/liveMessages.ts +141 -0
- package/src/message/observers/observeMessages.ts +0 -1
- package/src/message/observers/tests/liveMessages.test.ts +313 -0
- package/src/post/observers/livePosts.ts +2 -1
- package/src/post/tests/api/getPost.test.ts +3 -3
- package/src/post/tests/api/queryPosts.test.ts +4 -4
- package/src/utils/constants.ts +1 -0
- package/src/utils/tests/client.ts +31 -3
- package/src/utils/tests/dummy/channel.ts +96 -0
- package/src/utils/tests/dummy/follow.ts +60 -0
- package/src/utils/tests/dummy/index.ts +8 -0
- package/src/utils/tests/dummy/message.ts +21 -0
- package/src/utils/tests/dummy/post.ts +31 -0
- package/src/utils/tests/dummy/user.ts +26 -0
- package/src/utils/tests/index.ts +3 -2
- package/src/utils/tests/utils.ts +3 -0
- package/dist/utils/tests/dummy.d.ts.map +0 -1
- package/src/utils/tests/dummy.ts +0 -7
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { ASCApiError } from '~/core/errors';
|
|
2
|
+
import { disableCache, enableCache } from '~/cache/api';
|
|
3
|
+
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
4
|
+
|
|
5
|
+
import { liveMessages } from '../liveMessages';
|
|
6
|
+
import { queryMessages } from '~/message/api';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
client,
|
|
10
|
+
connectClient,
|
|
11
|
+
disconnectClient,
|
|
12
|
+
messages,
|
|
13
|
+
message as defaultMessage,
|
|
14
|
+
} from '~/utils/tests';
|
|
15
|
+
|
|
16
|
+
describe('liveMessages', () => {
|
|
17
|
+
beforeAll(async () => {
|
|
18
|
+
await connectClient();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterAll(async () => {
|
|
22
|
+
await disconnectClient();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
enableCache();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(disableCache);
|
|
30
|
+
|
|
31
|
+
const { channelId } = messages;
|
|
32
|
+
const returnValue = [{ messageId: messages.page1[0] }];
|
|
33
|
+
const message = { ...defaultMessage, messageId: returnValue[0].messageId, channelId };
|
|
34
|
+
|
|
35
|
+
test('it should show message if cache not enabled', () => {
|
|
36
|
+
/*
|
|
37
|
+
* NOTE: at the time of writing this test cache is diabled by default, but
|
|
38
|
+
* there is a proposal to enable cache by default. So I'm disabling cache
|
|
39
|
+
* here to ensure cache is disabled
|
|
40
|
+
*/
|
|
41
|
+
disableCache();
|
|
42
|
+
|
|
43
|
+
const callback = jest.fn();
|
|
44
|
+
jest.spyOn(global.console, 'log');
|
|
45
|
+
client.http.get = jest.fn();
|
|
46
|
+
|
|
47
|
+
// call liveMessages check if mocked console get's called with the correct
|
|
48
|
+
// message
|
|
49
|
+
client.use();
|
|
50
|
+
liveMessages({ channelId }, callback);
|
|
51
|
+
|
|
52
|
+
expect(console.log).toBeCalledWith(ENABLE_CACHE_MESSAGE);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('it should return message collection', async () => {
|
|
56
|
+
// mock response of queryMessages and validate
|
|
57
|
+
const callback = jest.fn();
|
|
58
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
59
|
+
data: {
|
|
60
|
+
messages: returnValue,
|
|
61
|
+
paging: {},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
liveMessages({ channelId }, callback);
|
|
66
|
+
|
|
67
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
68
|
+
|
|
69
|
+
// check if cache data returned (should be empty)
|
|
70
|
+
expect(callback).toHaveBeenCalledWith(
|
|
71
|
+
expect.objectContaining({
|
|
72
|
+
data: [],
|
|
73
|
+
error: undefined,
|
|
74
|
+
loading: true,
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
await expect(queryMessages({ channelId })).resolves.toBeTruthy();
|
|
79
|
+
|
|
80
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
81
|
+
|
|
82
|
+
expect(callback).toHaveBeenCalledWith(
|
|
83
|
+
expect.objectContaining({
|
|
84
|
+
data: returnValue,
|
|
85
|
+
error: undefined,
|
|
86
|
+
loading: false,
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
});
|
|
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
|
+
|
|
128
|
+
test('it should filter deleted messages based on param', async () => {
|
|
129
|
+
// mock response of queryMessages with a deleted message
|
|
130
|
+
const returnValue = [
|
|
131
|
+
{ messageId: messages.page1[0], isDeleted: true },
|
|
132
|
+
{ messageId: messages.page1[1], isDeleted: false },
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
// mock response of queryMessages and validate
|
|
136
|
+
const callback = jest.fn();
|
|
137
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
138
|
+
data: {
|
|
139
|
+
messages: returnValue,
|
|
140
|
+
paging: {},
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
liveMessages({ channelId, isDeleted: false }, callback);
|
|
145
|
+
|
|
146
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
147
|
+
|
|
148
|
+
// check if cache data returned (should be empty)
|
|
149
|
+
expect(callback).toHaveBeenCalledWith(
|
|
150
|
+
expect.objectContaining({
|
|
151
|
+
data: [],
|
|
152
|
+
error: undefined,
|
|
153
|
+
loading: true,
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
await expect(queryMessages({ channelId })).resolves.toBeTruthy();
|
|
158
|
+
|
|
159
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
160
|
+
|
|
161
|
+
expect(callback).toHaveBeenCalledWith(
|
|
162
|
+
expect.objectContaining({
|
|
163
|
+
data: [returnValue[1]],
|
|
164
|
+
error: undefined,
|
|
165
|
+
loading: false,
|
|
166
|
+
}),
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('it should return method to fetch next page', async () => {
|
|
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();
|
|
198
|
+
|
|
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
|
+
);
|
|
223
|
+
});
|
|
224
|
+
|
|
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
|
+
);
|
|
256
|
+
});
|
|
257
|
+
|
|
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
|
+
);
|
|
284
|
+
});
|
|
285
|
+
|
|
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
|
+
);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
16
16
|
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
17
|
+
ENABLE_CACHE_MESSAGE,
|
|
17
18
|
} from '~/utils/constants';
|
|
18
19
|
|
|
19
20
|
import {
|
|
@@ -57,7 +58,7 @@ export const livePosts = (
|
|
|
57
58
|
const { log, cache } = getActiveClient();
|
|
58
59
|
|
|
59
60
|
if (!cache) {
|
|
60
|
-
console.log(
|
|
61
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
const timestamp = Date.now();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ASCApiError } from '~/core/errors';
|
|
2
|
-
import { client,
|
|
2
|
+
import { client, posts } from '~/utils/tests';
|
|
3
3
|
import { pushToCache, enableCache, disableCache } from '~/cache/api';
|
|
4
4
|
|
|
5
5
|
import { getPost } from '~/post/api';
|
|
6
6
|
|
|
7
7
|
describe('post/api', () => {
|
|
8
|
-
const post = { postId:
|
|
9
|
-
const post2 = { postId:
|
|
8
|
+
const post = { postId: posts.page1[0] };
|
|
9
|
+
const post2 = { postId: posts.page1[1] };
|
|
10
10
|
|
|
11
11
|
describe('getPost.locally', () => {
|
|
12
12
|
test('should return undefined if cache is turned off', () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { queryPosts } from '~/post/api';
|
|
2
|
-
import { client,
|
|
2
|
+
import { client, posts } from '~/utils/tests';
|
|
3
3
|
|
|
4
4
|
describe('post/api', () => {
|
|
5
5
|
test('should return a post query', async () => {
|
|
6
|
-
const returnValue = [{ postId:
|
|
6
|
+
const returnValue = [{ postId: posts.page1[0] }];
|
|
7
7
|
|
|
8
8
|
client.http.get = jest.fn().mockResolvedValue({
|
|
9
9
|
data: {
|
|
@@ -13,8 +13,8 @@ describe('post/api', () => {
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
const data = await queryPosts({
|
|
16
|
-
targetId:
|
|
17
|
-
targetType:
|
|
16
|
+
targetId: posts.targetId,
|
|
17
|
+
targetType: posts.targetType,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
expect(data).toBeDefined();
|
package/src/utils/constants.ts
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createClient,
|
|
3
|
+
connectClient as sdkConnectClient,
|
|
4
|
+
disconnectClient as sdkDisconnectClient,
|
|
5
|
+
} from '~/client/api';
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
import { user11 } from './dummy';
|
|
4
8
|
|
|
5
|
-
export
|
|
9
|
+
export const client = createClient('key', 'sg');
|
|
10
|
+
|
|
11
|
+
export const connectClient = async () => {
|
|
12
|
+
client.mqtt.connect = jest.fn();
|
|
13
|
+
client.mqtt.subscribe = jest.fn();
|
|
14
|
+
client.http.post = jest.fn().mockReturnValueOnce({
|
|
15
|
+
data: {
|
|
16
|
+
accessToken: 'accessToken',
|
|
17
|
+
refreshToken: 'refreshToken',
|
|
18
|
+
users: [user11],
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
client.ws.emit('connect');
|
|
24
|
+
}, 500);
|
|
25
|
+
|
|
26
|
+
await sdkConnectClient({ userId: 'test' });
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const disconnectClient = async () => {
|
|
30
|
+
sdkDisconnectClient().then(() => client.ws.emit('disconnect'));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { date, rolesAndPermissions, user11 } from '.';
|
|
2
|
+
|
|
3
|
+
export const channelRaw1: Amity.ChannelRaw = {
|
|
4
|
+
messageCount: 1,
|
|
5
|
+
createdAt: date,
|
|
6
|
+
type: 'community',
|
|
7
|
+
channelId: 'channelId11',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const channelRaw2: Amity.ChannelRaw = {
|
|
11
|
+
messageCount: 3,
|
|
12
|
+
createdAt: date,
|
|
13
|
+
type: 'community',
|
|
14
|
+
channelId: 'channelId12',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const channelRaw3: Amity.ChannelRaw = {
|
|
18
|
+
messageCount: 3,
|
|
19
|
+
createdAt: date,
|
|
20
|
+
type: 'community',
|
|
21
|
+
channelId: 'channelId21',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const channel11: Amity.Channel = {
|
|
25
|
+
...channelRaw1,
|
|
26
|
+
hasMention: false,
|
|
27
|
+
unreadCount: 0,
|
|
28
|
+
type: 'community',
|
|
29
|
+
isDeleted: false,
|
|
30
|
+
tags: ['tag2'],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const channel12: Amity.Channel = {
|
|
34
|
+
...channelRaw2,
|
|
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'],
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const channelUser1: Amity.Membership<'channel'> = {
|
|
52
|
+
isMuted: false,
|
|
53
|
+
createdAt: date,
|
|
54
|
+
muteTimeout: '',
|
|
55
|
+
isBanned: false,
|
|
56
|
+
readToSegment: 1,
|
|
57
|
+
lastActivity: date,
|
|
58
|
+
membership: 'member',
|
|
59
|
+
userId: user11.userId,
|
|
60
|
+
...rolesAndPermissions,
|
|
61
|
+
lastMentionedSegment: 0,
|
|
62
|
+
channelId: channel11.channelId,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const channelUser2: Amity.Membership<'channel'> = {
|
|
66
|
+
...channelUser1,
|
|
67
|
+
readToSegment: 1,
|
|
68
|
+
lastMentionedSegment: 2,
|
|
69
|
+
channelId: channel12.channelId,
|
|
70
|
+
};
|
|
71
|
+
|
|
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
|
+
},
|
|
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
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { date, channel11, user11 } from '.';
|
|
2
|
+
|
|
3
|
+
export const message: Amity.Message = {
|
|
4
|
+
reactions: {},
|
|
5
|
+
editedAt: date,
|
|
6
|
+
createdAt: date,
|
|
7
|
+
reactionsCount: 0,
|
|
8
|
+
channelSegment: 1,
|
|
9
|
+
childrenNumber: 0,
|
|
10
|
+
userId: user11.userId,
|
|
11
|
+
messageId: 'message11',
|
|
12
|
+
channelId: channel11.channelId,
|
|
13
|
+
data: { text: 'message1' },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const messages = {
|
|
17
|
+
channelId: 'channelId',
|
|
18
|
+
page1: ['messageId11', 'messageId12', 'messageId13'],
|
|
19
|
+
page2: ['messageId21', 'messageId22', 'messageId23'],
|
|
20
|
+
page3: ['messageId31', 'messageId32', 'messageId33'],
|
|
21
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { user11, date } from '.';
|
|
2
|
+
|
|
3
|
+
export const post1: Amity.Post = {
|
|
4
|
+
path: '',
|
|
5
|
+
feedId: '',
|
|
6
|
+
children: [],
|
|
7
|
+
comments: [],
|
|
8
|
+
flagCount: 0,
|
|
9
|
+
reactions: {},
|
|
10
|
+
hashFlag: null,
|
|
11
|
+
editedAt: date,
|
|
12
|
+
createdAt: date,
|
|
13
|
+
commentsCount: 0,
|
|
14
|
+
reactionsCount: 0,
|
|
15
|
+
postId: 'postId11',
|
|
16
|
+
targetType: 'user',
|
|
17
|
+
parentId: 'postId12',
|
|
18
|
+
data: { text: 'post1' },
|
|
19
|
+
targetId: user11.userId,
|
|
20
|
+
hasFlaggedComment: false,
|
|
21
|
+
hasFlaggedChildren: false,
|
|
22
|
+
postedUserId: user11.userId,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const posts = {
|
|
26
|
+
targetId: user11.userId,
|
|
27
|
+
targetType: 'user' as Amity.PostTargetType,
|
|
28
|
+
page1: [post1.postId, 'postId12', 'postId13'],
|
|
29
|
+
page2: ['postId21', 'postId22', 'postId23'],
|
|
30
|
+
page3: ['postId31', 'postId32', 'postId33'],
|
|
31
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { date, rolesAndPermissions } from '.';
|
|
2
|
+
|
|
3
|
+
export const user11: Amity.User = {
|
|
4
|
+
_id: '',
|
|
5
|
+
path: '',
|
|
6
|
+
flagCount: 0,
|
|
7
|
+
userId: 'test',
|
|
8
|
+
hashFlag: null,
|
|
9
|
+
createdAt: date,
|
|
10
|
+
...rolesAndPermissions,
|
|
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
|
+
};
|
package/src/utils/tests/index.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './utils';
|
|
2
|
+
export * from './dummy';
|
|
3
|
+
export * from './client';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dummy.d.ts","sourceRoot":"","sources":["../../../src/utils/tests/dummy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS;;;;;;CAMrB,CAAC"}
|
package/src/utils/tests/dummy.ts
DELETED