@amityco/ts-sdk 0.0.1-beta.37 → 0.0.1-beta.38
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 +3 -5
- package/dist/@types/core/events.d.ts +1 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/category.d.ts +7 -0
- package/dist/@types/domains/category.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +12 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/global.d.ts +5 -0
- package/dist/@types/global.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts +1 -5
- package/dist/category/api/queryCategories.d.ts.map +1 -1
- package/dist/category/observers/index.d.ts +2 -0
- package/dist/category/observers/index.d.ts.map +1 -0
- package/dist/category/observers/liveCategories.d.ts +18 -0
- package/dist/category/observers/liveCategories.d.ts.map +1 -0
- package/dist/category/observers/tests/liveCategories.test.d.ts +2 -0
- package/dist/category/observers/tests/liveCategories.test.d.ts.map +1 -0
- package/dist/channel/api/tests/getChannels.test.d.ts +2 -0
- package/dist/channel/api/tests/getChannels.test.d.ts.map +1 -0
- package/dist/channel/api/tests/leaveChannel.test.d.ts +2 -0
- package/dist/channel/api/tests/leaveChannel.test.d.ts.map +1 -0
- package/dist/channel/observers/liveChannel.d.ts.map +1 -1
- package/dist/client/api/accessTokenExpiryWatcher.d.ts +4 -1
- package/dist/client/api/accessTokenExpiryWatcher.d.ts.map +1 -1
- package/dist/client/api/getToken.d.ts +3 -1
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/client/utils/setClientToken.d.ts +3 -3
- package/dist/comment/api/deleteComment.d.ts.map +1 -1
- package/dist/comment/api/getComment.d.ts.map +1 -1
- package/dist/comment/observers/index.d.ts +1 -0
- package/dist/comment/observers/index.d.ts.map +1 -1
- package/dist/comment/observers/liveComment.d.ts +21 -0
- package/dist/comment/observers/liveComment.d.ts.map +1 -0
- package/dist/comment/observers/tests/liveComment.test.d.ts +2 -0
- package/dist/comment/observers/tests/liveComment.test.d.ts.map +1 -0
- package/dist/community/api/queryCommunities.d.ts +1 -10
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/events/index.d.ts +1 -0
- package/dist/community/events/index.d.ts.map +1 -1
- package/dist/community/events/onCommunityUserChanged.d.ts +17 -0
- package/dist/community/events/onCommunityUserChanged.d.ts.map +1 -0
- package/dist/community/events/utils.d.ts +1 -0
- package/dist/community/events/utils.d.ts.map +1 -1
- package/dist/community/observers/index.d.ts +1 -0
- package/dist/community/observers/index.d.ts.map +1 -1
- package/dist/community/observers/liveCommunities.d.ts +20 -0
- package/dist/community/observers/liveCommunities.d.ts.map +1 -0
- package/dist/community/observers/tests/liveCommunities.test.d.ts +2 -0
- package/dist/community/observers/tests/liveCommunities.test.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/sorting.d.ts +6 -0
- package/dist/core/query/sorting.d.ts.map +1 -1
- package/dist/core/transports/http.d.ts +0 -5
- package/dist/core/transports/http.d.ts.map +1 -1
- package/dist/file/api/test/createImage.test.d.ts +2 -0
- package/dist/file/api/test/createImage.test.d.ts.map +1 -0
- package/dist/file/api/test/createVideo.test.d.ts +2 -0
- package/dist/file/api/test/createVideo.test.d.ts.map +1 -0
- package/dist/index.cjs.js +441 -195
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +436 -195
- package/dist/index.umd.js +4 -4
- package/dist/message/observers/liveMessage.d.ts.map +1 -1
- package/dist/post/observers/index.d.ts +1 -0
- package/dist/post/observers/index.d.ts.map +1 -1
- package/dist/post/observers/livePost.d.ts +21 -0
- package/dist/post/observers/livePost.d.ts.map +1 -0
- package/dist/post/observers/tests/livePost.test.d.ts +2 -0
- package/dist/post/observers/tests/livePost.test.d.ts.map +1 -0
- package/dist/subChannel/api/tests/deleteSubChannel.test.d.ts +2 -0
- package/dist/subChannel/api/tests/deleteSubChannel.test.d.ts.map +1 -0
- package/dist/subChannel/api/tests/getSubChannel.test.d.ts +2 -0
- package/dist/subChannel/api/tests/getSubChannel.test.d.ts.map +1 -0
- package/dist/subChannel/api/tests/getSubChannels.test.d.ts +2 -0
- package/dist/subChannel/api/tests/getSubChannels.test.d.ts.map +1 -0
- package/dist/subChannel/api/tests/updateSubChannel.test.d.ts +2 -0
- package/dist/subChannel/api/tests/updateSubChannel.test.d.ts.map +1 -0
- package/dist/subChannel/observers/liveSubChannel.d.ts.map +1 -1
- package/dist/user/api/tests/updateUser.test.d.ts +2 -0
- package/dist/user/api/tests/updateUser.test.d.ts.map +1 -0
- package/dist/user/observers/liveUser.d.ts.map +1 -1
- package/dist/utils/liveObject.d.ts +2 -0
- package/dist/utils/liveObject.d.ts.map +1 -0
- package/dist/utils/tests/dummy/category.d.ts +64 -0
- package/dist/utils/tests/dummy/category.d.ts.map +1 -0
- package/dist/utils/tests/dummy/channel.d.ts +50 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +132 -0
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/dist/utils/tests/dummy/file.d.ts +3 -0
- package/dist/utils/tests/dummy/file.d.ts.map +1 -1
- package/dist/utils/tests/dummy/index.d.ts +1 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -1
- package/dist/utils/tests/dummy/post.d.ts +2 -0
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/dist/utils/tests/dummy/subChannel.d.ts +0 -20
- package/dist/utils/tests/dummy/subChannel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/user.d.ts +18 -0
- package/dist/utils/tests/dummy/user.d.ts.map +1 -1
- package/dist/utils/tests/liveObject.test.d.ts +2 -0
- package/dist/utils/tests/liveObject.test.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/@types/core/events.ts +1 -0
- package/src/@types/domains/category.ts +13 -0
- package/src/@types/domains/community.ts +25 -0
- package/src/@types/global.ts +5 -0
- package/src/category/api/queryCategories.ts +3 -5
- package/src/category/observers/index.ts +1 -0
- package/src/category/observers/liveCategories.ts +141 -0
- package/src/category/observers/tests/liveCategories.test.ts +147 -0
- package/src/channel/api/tests/createChannel.test.ts +30 -6
- package/src/channel/api/tests/getChannel.test.ts +3 -1
- package/src/channel/api/tests/getChannels.test.ts +97 -0
- package/src/channel/api/tests/joinChannel.test.ts +62 -3
- package/src/channel/api/tests/leaveChannel.test.ts +90 -0
- package/src/channel/api/tests/queryChannels.test.ts +38 -1
- package/src/channel/observers/liveChannel.ts +8 -80
- package/src/client/api/accessTokenExpiryWatcher.ts +7 -5
- package/src/client/api/tests/accessTokenExpiryWatcher.test.ts +8 -5
- package/src/comment/api/deleteComment.ts +5 -5
- package/src/comment/api/getComment.ts +8 -3
- package/src/comment/observers/index.ts +1 -0
- package/src/comment/observers/liveComment.ts +43 -0
- package/src/comment/observers/tests/liveComment.test.ts +95 -0
- package/src/community/api/queryCommunities.ts +3 -10
- package/src/community/api/test/addCommunityMember.test.ts +14 -2
- package/src/community/api/test/joinCommunity.test.ts +14 -2
- package/src/community/api/test/leaveCommunity.test.ts +11 -1
- package/src/community/api/test/removeCommunityMembers.test.ts +11 -1
- package/src/community/events/index.ts +1 -0
- package/src/community/events/onCommunityUserChanged.ts +20 -0
- package/src/community/events/test/onCommunityJoined.test.ts +1 -1
- package/src/community/events/test/onCommunityUserAdded.test.ts +1 -1
- package/src/community/events/test/onCommunityUserBanned.test.ts +1 -1
- package/src/community/events/test/onCommunityUserUnbaned.test.ts +1 -1
- package/src/community/events/test/utils.test.ts +52 -3
- package/src/community/events/utils.ts +49 -0
- package/src/community/observers/index.ts +1 -0
- package/src/community/observers/liveCommunities.ts +188 -0
- package/src/community/observers/tests/liveCommunities.test.ts +284 -0
- package/src/core/query/sorting.ts +8 -0
- package/src/core/transports/http.ts +17 -13
- package/src/core/transports/test/http.test.ts +49 -60
- package/src/file/api/createFile.ts +1 -1
- package/src/file/api/createImage.ts +1 -1
- package/src/file/api/createVideo.ts +1 -1
- package/src/file/api/test/createImage.test.ts +69 -0
- package/src/file/api/test/createVideo.test.ts +81 -0
- package/src/index.ts +1 -0
- package/src/message/observers/liveMessage.ts +11 -83
- package/src/message/tests/observers/liveMessage.test.ts +1 -143
- package/src/post/observers/index.ts +1 -0
- package/src/post/observers/livePost.ts +47 -0
- package/src/post/observers/tests/livePost.test.ts +97 -0
- package/src/stream/api/tests/createStream.test.ts +3 -11
- package/src/stream/api/tests/deleteStream.test.ts +5 -3
- package/src/subChannel/api/tests/createSubChannel.test.ts +21 -14
- package/src/subChannel/api/tests/deleteSubChannel.test.ts +112 -0
- package/src/subChannel/api/tests/getSubChannel.test.ts +97 -0
- package/src/subChannel/api/tests/getSubChannels.test.ts +97 -0
- package/src/subChannel/api/tests/updateSubChannel.test.ts +86 -0
- package/src/subChannel/observers/liveSubChannel.ts +6 -56
- package/src/subChannel/observers/tests/liveSubChannel.test.ts +0 -82
- package/src/user/api/tests/updateUser.test.ts +60 -0
- package/src/user/observers/liveUser.ts +9 -61
- package/src/user/tests/observers/liveUser.test.ts +1 -154
- package/src/utils/liveObject.ts +86 -0
- package/src/utils/tests/dummy/category.ts +57 -0
- package/src/utils/tests/dummy/channel.ts +51 -1
- package/src/utils/tests/dummy/community.ts +94 -0
- package/src/utils/tests/dummy/file.ts +32 -0
- package/src/utils/tests/dummy/index.ts +1 -0
- package/src/utils/tests/dummy/post.ts +56 -45
- package/src/utils/tests/dummy/stream.ts +73 -73
- package/src/utils/tests/dummy/subChannel.ts +0 -22
- package/src/utils/tests/dummy/user.ts +21 -0
- package/src/utils/tests/liveObject.test.ts +172 -0
|
@@ -106,3 +106,97 @@ export const communityUserModel = [
|
|
|
106
106
|
{ ...communityUser11, user: user11 },
|
|
107
107
|
{ ...communityUser12, user: user12 },
|
|
108
108
|
];
|
|
109
|
+
|
|
110
|
+
export const communityRaw1 = {
|
|
111
|
+
path: '631f16be1e440400da5663b0/social/community/63c8e023d2474637568ece5e',
|
|
112
|
+
isOfficial: false,
|
|
113
|
+
isPublic: true,
|
|
114
|
+
onlyAdminCanPost: false,
|
|
115
|
+
postsCount: 0,
|
|
116
|
+
membersCount: 1,
|
|
117
|
+
moderatorMemberCount: 1,
|
|
118
|
+
updatedAt: '2023-01-19T06:16:03.818Z',
|
|
119
|
+
createdAt: '2023-01-19T06:16:03.818Z',
|
|
120
|
+
isDeleted: true,
|
|
121
|
+
needApprovalOnPostCreation: false,
|
|
122
|
+
displayName: 'community 1',
|
|
123
|
+
tags: ['test-community-tag'],
|
|
124
|
+
metadata: {},
|
|
125
|
+
hasFlaggedComment: false,
|
|
126
|
+
hasFlaggedPost: true,
|
|
127
|
+
communityId: '63c8e023d2474637568ece5e',
|
|
128
|
+
channelId: '63c8e023d2474637568ece5e',
|
|
129
|
+
userId: user11.userId,
|
|
130
|
+
isJoined: true,
|
|
131
|
+
avatarFileId: '',
|
|
132
|
+
categoryIds: ['test-category-id'],
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const communityRaw2 = {
|
|
136
|
+
path: '631f16be1e440400da5663b0/social/community/63c8cd098309f85d2ec7dad7',
|
|
137
|
+
isOfficial: false,
|
|
138
|
+
isPublic: true,
|
|
139
|
+
onlyAdminCanPost: false,
|
|
140
|
+
postsCount: 0,
|
|
141
|
+
membersCount: 1,
|
|
142
|
+
moderatorMemberCount: 1,
|
|
143
|
+
updatedAt: '2023-01-19T04:54:57.078Z',
|
|
144
|
+
createdAt: '2023-01-19T04:54:33.716Z',
|
|
145
|
+
isDeleted: false,
|
|
146
|
+
needApprovalOnPostCreation: false,
|
|
147
|
+
displayName: 'new community ....1',
|
|
148
|
+
tags: [],
|
|
149
|
+
metadata: {},
|
|
150
|
+
hasFlaggedComment: false,
|
|
151
|
+
hasFlaggedPost: false,
|
|
152
|
+
communityId: '63c8cd098309f85d2ec7dad7',
|
|
153
|
+
channelId: '63c8cd098309f85d2ec7dad7',
|
|
154
|
+
userId: user12.userId,
|
|
155
|
+
isJoined: false,
|
|
156
|
+
avatarFileId: '',
|
|
157
|
+
categoryIds: [],
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const communityQueryResponse = {
|
|
161
|
+
data: {
|
|
162
|
+
communities: [communityRaw1, communityRaw2],
|
|
163
|
+
communityUsers: [communityUser11],
|
|
164
|
+
categories: [
|
|
165
|
+
{
|
|
166
|
+
name: '$testing category',
|
|
167
|
+
metadata: {},
|
|
168
|
+
updatedAt: '2022-11-25T03:56:06.238Z',
|
|
169
|
+
createdAt: '2022-11-25T03:56:06.238Z',
|
|
170
|
+
isDeleted: false,
|
|
171
|
+
categoryId: '88d175da65cbfeb39b81e722b322430d',
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
users: [user11, user12],
|
|
175
|
+
feeds: [],
|
|
176
|
+
paging: {
|
|
177
|
+
next: 'eyJza2lwIjoxMCwibGltaXQiOjEwfQ==',
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export const communityQueryResponsePage2 = {
|
|
183
|
+
data: {
|
|
184
|
+
communities: [communityRaw1],
|
|
185
|
+
communityUsers: [communityUser11],
|
|
186
|
+
categories: [
|
|
187
|
+
{
|
|
188
|
+
name: '$testing category',
|
|
189
|
+
metadata: {},
|
|
190
|
+
updatedAt: '2022-11-25T03:56:06.238Z',
|
|
191
|
+
createdAt: '2022-11-25T03:56:06.238Z',
|
|
192
|
+
isDeleted: false,
|
|
193
|
+
categoryId: '88d175da65cbfeb39b81e722b322430d',
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
users: [user11, user12],
|
|
197
|
+
feeds: [],
|
|
198
|
+
paging: {
|
|
199
|
+
next: 'eyJza2lwIjoxMCwibGltaXQiOjEwfQ==',
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import MockFormData from 'form-data';
|
|
2
|
+
|
|
1
3
|
export const file11: Amity.File<'image'> = {
|
|
2
4
|
fileId: 'file-Id',
|
|
3
5
|
fileUrl: 'https://fileUrl.com/test-file',
|
|
@@ -18,3 +20,33 @@ export const file11: Amity.File<'image'> = {
|
|
|
18
20
|
},
|
|
19
21
|
},
|
|
20
22
|
};
|
|
23
|
+
|
|
24
|
+
export const file12: Amity.File<'video'> = {
|
|
25
|
+
fileId: 'file-Id-12',
|
|
26
|
+
feedType: 'post',
|
|
27
|
+
status: 'uploaded',
|
|
28
|
+
fileUrl: 'https://fileUrl.com/test-file',
|
|
29
|
+
type: 'video',
|
|
30
|
+
createdAt: '2023-01-20T18:37:19.583Z',
|
|
31
|
+
updatedAt: '2023-01-20T18:37:19.583Z',
|
|
32
|
+
attributes: {
|
|
33
|
+
name: 'test.mp4',
|
|
34
|
+
extension: 'mp4',
|
|
35
|
+
size: '3652304',
|
|
36
|
+
mimeType: 'video/mp4',
|
|
37
|
+
metadata: {},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const createFileFormData = () => {
|
|
42
|
+
const fd = new MockFormData() as unknown as FormData;
|
|
43
|
+
fd.append('files', 'file');
|
|
44
|
+
fd.getAll = jest.fn().mockImplementation(() => ['file']);
|
|
45
|
+
return fd;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const createEmptyFormData = () => {
|
|
49
|
+
const fd = new MockFormData() as unknown as FormData;
|
|
50
|
+
fd.getAll = jest.fn().mockImplementation(() => []);
|
|
51
|
+
return fd;
|
|
52
|
+
};
|
|
@@ -1,52 +1,63 @@
|
|
|
1
1
|
import { user11, file11, communityUser11, date } from '.';
|
|
2
2
|
import { encodeJson } from '..';
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
export function generatePost(params?: Partial<Amity.Post>): Amity.Post {
|
|
5
|
+
return {
|
|
6
|
+
children: [],
|
|
7
|
+
comments: [],
|
|
8
|
+
commentsCount: 0,
|
|
9
|
+
createdAt: date,
|
|
10
|
+
data: { text: 'post11' },
|
|
11
|
+
editedAt: date,
|
|
12
|
+
feedId: '',
|
|
13
|
+
flagCount: 0,
|
|
14
|
+
hashFlag: null,
|
|
15
|
+
hasFlaggedComment: false,
|
|
16
|
+
hasFlaggedChildren: false,
|
|
17
|
+
parentId: 'postId12',
|
|
18
|
+
path: '',
|
|
19
|
+
postedUserId: user11.userId,
|
|
20
|
+
postId: 'postId11',
|
|
21
|
+
reactions: {},
|
|
22
|
+
reactionsCount: 0,
|
|
23
|
+
targetId: user11.userId,
|
|
24
|
+
targetType: 'user',
|
|
25
|
+
updatedAt: date,
|
|
26
|
+
...params,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
25
29
|
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
export function generateComment(params?: Partial<Amity.Comment>): Amity.Comment {
|
|
31
|
+
return {
|
|
32
|
+
path: '',
|
|
33
|
+
referenceType: 'post',
|
|
34
|
+
dataType: 'text',
|
|
35
|
+
rootId: 'test',
|
|
36
|
+
data: {
|
|
37
|
+
text: 'yellow new world',
|
|
38
|
+
},
|
|
39
|
+
childrenNumber: 0,
|
|
40
|
+
isDeleted: false,
|
|
41
|
+
editedAt: '2022-10-31T05:57:45.661Z',
|
|
42
|
+
updatedAt: '2022-10-31T05:57:45.670Z',
|
|
43
|
+
createdAt: '2022-10-31T05:57:45.661Z',
|
|
44
|
+
segmentNumber: 2,
|
|
45
|
+
commentId: 'comment11',
|
|
46
|
+
userId: 'test',
|
|
47
|
+
referenceId: 'postId11',
|
|
48
|
+
flagCount: 0,
|
|
49
|
+
hashFlag: null,
|
|
50
|
+
children: [],
|
|
51
|
+
mentionees: [],
|
|
52
|
+
reactions: {},
|
|
53
|
+
reactionsCount: 0,
|
|
54
|
+
...params,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const post11: Amity.Post = generatePost();
|
|
59
|
+
|
|
60
|
+
export const comment11: Amity.Comment = generateComment();
|
|
50
61
|
|
|
51
62
|
export const post12: Amity.Post = {
|
|
52
63
|
...post11,
|
|
@@ -1,86 +1,86 @@
|
|
|
1
1
|
export const streamResponse = {
|
|
2
2
|
data: {
|
|
3
|
-
|
|
3
|
+
videoStreamings: [
|
|
4
4
|
{
|
|
5
|
-
streamId:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
streamId: '123',
|
|
6
|
+
userId: '123',
|
|
7
|
+
thumbnailFileId: '123',
|
|
8
|
+
title: 'Test Stream',
|
|
9
|
+
status: 'idle',
|
|
10
|
+
isLive: true,
|
|
11
|
+
isDeleted: true,
|
|
12
|
+
description: 'Test Stream Description',
|
|
13
|
+
platform: {
|
|
14
|
+
name: 'x86',
|
|
15
|
+
version: '123',
|
|
16
16
|
},
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
17
|
+
startedAt: '2023-01-17T07:19:06.414Z',
|
|
18
|
+
endedAt: '2023-01-17T07:19:06.414Z',
|
|
19
|
+
createdAt: '2023-01-17T07:19:06.414Z',
|
|
20
|
+
updatedAt: '2023-01-17T07:19:06.414Z',
|
|
21
|
+
metadata: {},
|
|
22
|
+
resolution: 'SD',
|
|
23
|
+
streamerUrl: {
|
|
24
|
+
url: 'https://test-stream.test',
|
|
25
|
+
components: {
|
|
26
|
+
origin: 'origin',
|
|
27
|
+
appName: 'stream app',
|
|
28
|
+
streamName: 'stream name',
|
|
29
|
+
query: '123',
|
|
30
|
+
},
|
|
31
31
|
},
|
|
32
|
-
|
|
32
|
+
recordings: [
|
|
33
33
|
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
flv: {
|
|
35
|
+
url: 'https://test-stream-flv.test',
|
|
36
|
+
duration: 0,
|
|
37
|
+
startTime: 0,
|
|
38
|
+
stopTime: 0,
|
|
39
|
+
},
|
|
40
|
+
mp4: {
|
|
41
|
+
url: 'https://test-stream-mp4.test',
|
|
42
|
+
duration: 0,
|
|
43
|
+
startTime: 0,
|
|
44
|
+
stopTime: 0,
|
|
39
45
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
m3u8: {
|
|
47
|
+
url: 'https://test-stream-m3u8.test',
|
|
48
|
+
duration: 0,
|
|
49
|
+
startTime: 0,
|
|
50
|
+
stopTime: 0,
|
|
45
51
|
},
|
|
46
|
-
|
|
47
|
-
"url": "https://test-stream-m3u8.test",
|
|
48
|
-
"duration": 0,
|
|
49
|
-
"startTime": 0,
|
|
50
|
-
"stopTime": 0
|
|
51
|
-
}
|
|
52
|
-
}
|
|
52
|
+
},
|
|
53
53
|
],
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
54
|
+
watcherUrl: {
|
|
55
|
+
flv: {
|
|
56
|
+
url: 'https://test-stream-flv.test',
|
|
57
|
+
components: {
|
|
58
|
+
origin: '1',
|
|
59
|
+
appName: '2',
|
|
60
|
+
streamName: '3',
|
|
61
|
+
query: '4',
|
|
62
|
+
},
|
|
63
63
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
64
|
+
hls: {
|
|
65
|
+
url: 'https://test-stream-hls.test',
|
|
66
|
+
components: {
|
|
67
|
+
origin: '1',
|
|
68
|
+
appName: '2',
|
|
69
|
+
streamName: '3',
|
|
70
|
+
query: '4',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
rtmp: {
|
|
74
|
+
url: 'https://test-stream-rtmp.test',
|
|
75
|
+
components: {
|
|
76
|
+
origin: '1',
|
|
77
|
+
appName: '2',
|
|
78
|
+
streamName: '3',
|
|
79
|
+
query: '4',
|
|
80
|
+
},
|
|
72
81
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"components": {
|
|
76
|
-
"origin": "1",
|
|
77
|
-
"appName": "2",
|
|
78
|
-
"streamName": "3",
|
|
79
|
-
"query": "4"
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
84
|
],
|
|
85
|
-
}
|
|
85
|
+
},
|
|
86
86
|
};
|
|
@@ -27,25 +27,3 @@ export function generateSubChannel(params?: Record<string, any>): Amity.SubChann
|
|
|
27
27
|
...params,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
export const createSubChannelError400400 = {
|
|
32
|
-
status: 'error',
|
|
33
|
-
message: 'Channel not found.',
|
|
34
|
-
code: 400400,
|
|
35
|
-
data: {
|
|
36
|
-
detail: {
|
|
37
|
-
channelId: '63d0ccbc5defa46a1cab73a',
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const createSubChannelError400301 = {
|
|
43
|
-
status: 'error',
|
|
44
|
-
message: 'You are not a member of this channel.',
|
|
45
|
-
code: 400301,
|
|
46
|
-
data: {
|
|
47
|
-
detail: {
|
|
48
|
-
channelId: '63be2ef7827ef6bfc6798192',
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
};
|
|
@@ -36,6 +36,27 @@ export const userQueryResponse = {
|
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
|
+
|
|
40
|
+
export const userUpdateResponse = {
|
|
41
|
+
data: {
|
|
42
|
+
users: [
|
|
43
|
+
{
|
|
44
|
+
isDeleted: false,
|
|
45
|
+
displayName: 'updated-display-name',
|
|
46
|
+
userId: 'test-user',
|
|
47
|
+
metadata: {},
|
|
48
|
+
roles: [],
|
|
49
|
+
permissions: [],
|
|
50
|
+
flagCount: 0,
|
|
51
|
+
hashFlag: null,
|
|
52
|
+
avatarCustomUrl: 'updated-avatarUrl',
|
|
53
|
+
avatarFileId: null,
|
|
54
|
+
isGlobalBan: false,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
files: [],
|
|
58
|
+
},
|
|
59
|
+
};
|
|
39
60
|
export const users = [user11, user12, user13, user14];
|
|
40
61
|
|
|
41
62
|
// user payload with file
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { generatePost } from '~/utils/tests/dummy';
|
|
2
|
+
import { pause } from '~/utils/tests/utils';
|
|
3
|
+
import { connectClient, disconnectClient } from '~/utils/tests/client';
|
|
4
|
+
import { disableCache, enableCache } from '~/cache/api';
|
|
5
|
+
import { getFutureDate, getPastDate } from '~/core/model';
|
|
6
|
+
import { LIVE_OBJECT_ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
7
|
+
import { liveObject } from '../liveObject';
|
|
8
|
+
|
|
9
|
+
describe('liveObject', () => {
|
|
10
|
+
let post: Amity.Post;
|
|
11
|
+
let fetcher: jest.Mock;
|
|
12
|
+
let callback: jest.Mock;
|
|
13
|
+
let eventCallback: Amity.Listener<Amity.Post>;
|
|
14
|
+
let eventUnsubscriber: jest.Mock;
|
|
15
|
+
const onEvent = (fn: Amity.Listener<Amity.Post>) => {
|
|
16
|
+
eventCallback = fn;
|
|
17
|
+
eventUnsubscriber = jest.fn();
|
|
18
|
+
|
|
19
|
+
return eventUnsubscriber;
|
|
20
|
+
};
|
|
21
|
+
let unsubscribe: Amity.Unsubscriber;
|
|
22
|
+
|
|
23
|
+
beforeAll(async () => {
|
|
24
|
+
await connectClient();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterAll(async () => {
|
|
28
|
+
await disconnectClient();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
enableCache();
|
|
33
|
+
|
|
34
|
+
callback = jest.fn();
|
|
35
|
+
post = generatePost({ postId: 'my-post-id' });
|
|
36
|
+
fetcher = jest.fn().mockResolvedValue(post);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
disableCache();
|
|
41
|
+
unsubscribe();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('it should show message if cache not enabled', () => {
|
|
45
|
+
/*
|
|
46
|
+
* NOTE: at the time of writing this test cache is disabled by default, but
|
|
47
|
+
* there is a proposal to enable cache by default. So I'm disabling cache
|
|
48
|
+
* here to ensure cache is disabled
|
|
49
|
+
*/
|
|
50
|
+
disableCache();
|
|
51
|
+
jest.spyOn(global.console, 'log');
|
|
52
|
+
|
|
53
|
+
unsubscribe = liveObject<Amity.Post, 'postId'>(post.postId, callback, 'postId', fetcher, []);
|
|
54
|
+
|
|
55
|
+
expect(console.log).toBeCalledWith(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should fetch the model', async () => {
|
|
59
|
+
unsubscribe = liveObject<Amity.Post, 'postId'>(post.postId, callback, 'postId', fetcher, []);
|
|
60
|
+
await pause();
|
|
61
|
+
|
|
62
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
63
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
64
|
+
1,
|
|
65
|
+
expect.objectContaining({ data: undefined, loading: true }),
|
|
66
|
+
);
|
|
67
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
68
|
+
2,
|
|
69
|
+
expect.objectContaining({
|
|
70
|
+
data: post,
|
|
71
|
+
loading: false,
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should provide the error if fetch is failed', async () => {
|
|
77
|
+
const error = new Error('can not fetch');
|
|
78
|
+
|
|
79
|
+
unsubscribe = liveObject<Amity.Post, 'postId'>(
|
|
80
|
+
post.postId,
|
|
81
|
+
callback,
|
|
82
|
+
'postId',
|
|
83
|
+
() => {
|
|
84
|
+
return Promise.reject(error);
|
|
85
|
+
},
|
|
86
|
+
[onEvent],
|
|
87
|
+
);
|
|
88
|
+
await pause();
|
|
89
|
+
|
|
90
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
91
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
92
|
+
1,
|
|
93
|
+
expect.objectContaining({ data: undefined, loading: true }),
|
|
94
|
+
);
|
|
95
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
96
|
+
2,
|
|
97
|
+
expect.objectContaining({
|
|
98
|
+
data: undefined,
|
|
99
|
+
error,
|
|
100
|
+
loading: false,
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
expect(eventUnsubscriber).toHaveBeenCalledTimes(1);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should update the model on the event', async () => {
|
|
107
|
+
const update = {
|
|
108
|
+
...post,
|
|
109
|
+
data: { text: 'new-text' },
|
|
110
|
+
updatedAt: getFutureDate(post.updatedAt),
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
unsubscribe = liveObject<Amity.Post, 'postId'>(post.postId, callback, 'postId', fetcher, [
|
|
114
|
+
onEvent,
|
|
115
|
+
]);
|
|
116
|
+
await pause();
|
|
117
|
+
eventCallback(update);
|
|
118
|
+
await pause();
|
|
119
|
+
|
|
120
|
+
expect(callback).toHaveBeenCalledTimes(3);
|
|
121
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
122
|
+
3,
|
|
123
|
+
expect.objectContaining({
|
|
124
|
+
data: update,
|
|
125
|
+
loading: false,
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should not update the model on the event if the model is already the latest', async () => {
|
|
131
|
+
const update = {
|
|
132
|
+
...post,
|
|
133
|
+
data: { text: 'new-text' },
|
|
134
|
+
updatedAt: getPastDate(post.updatedAt),
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
unsubscribe = liveObject<Amity.Post, 'postId'>(post.postId, callback, 'postId', fetcher, [
|
|
138
|
+
onEvent,
|
|
139
|
+
]);
|
|
140
|
+
await pause();
|
|
141
|
+
eventCallback(update);
|
|
142
|
+
await pause();
|
|
143
|
+
|
|
144
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should not update the model on the event if the model has different id', async () => {
|
|
148
|
+
const post2 = generatePost({
|
|
149
|
+
postId: 'my-post-id-2',
|
|
150
|
+
updatedAt: getFutureDate(post.updatedAt),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
unsubscribe = liveObject<Amity.Post, 'postId'>(post.postId, callback, 'postId', fetcher, [
|
|
154
|
+
onEvent,
|
|
155
|
+
]);
|
|
156
|
+
await pause();
|
|
157
|
+
eventCallback(post2);
|
|
158
|
+
await pause();
|
|
159
|
+
|
|
160
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('should unsubscribe from events on liveObject disposing', async () => {
|
|
164
|
+
unsubscribe = liveObject<Amity.Post, 'postId'>(post.postId, callback, 'postId', fetcher, [
|
|
165
|
+
onEvent,
|
|
166
|
+
]);
|
|
167
|
+
await pause();
|
|
168
|
+
unsubscribe();
|
|
169
|
+
|
|
170
|
+
expect(eventUnsubscriber).toHaveBeenCalledTimes(1);
|
|
171
|
+
});
|
|
172
|
+
});
|