@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
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { disableCache, enableCache } from '~/cache/api';
|
|
2
|
+
import {
|
|
3
|
+
pause,
|
|
4
|
+
client,
|
|
5
|
+
connectClient,
|
|
6
|
+
disconnectClient,
|
|
7
|
+
generatePost,
|
|
8
|
+
user12,
|
|
9
|
+
} from '~/utils/tests';
|
|
10
|
+
import { getFutureDate } from '~/core/model';
|
|
11
|
+
import { livePost } from '../livePost';
|
|
12
|
+
|
|
13
|
+
describe('livePost', () => {
|
|
14
|
+
const post = generatePost();
|
|
15
|
+
const response = { data: { posts: [post] } };
|
|
16
|
+
|
|
17
|
+
beforeAll(async () => {
|
|
18
|
+
await connectClient();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterAll(async () => {
|
|
22
|
+
await disconnectClient();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
beforeEach(enableCache);
|
|
26
|
+
|
|
27
|
+
afterEach(disableCache);
|
|
28
|
+
|
|
29
|
+
const events: [string, keyof Amity.MqttPostEvents][] = [
|
|
30
|
+
['should get update on post.updated event', 'post.updated'],
|
|
31
|
+
['should get update on post.deleted event', 'post.deleted'],
|
|
32
|
+
['should get update on post.approved event', 'post.approved'],
|
|
33
|
+
['should get update on post.declined event', 'post.declined'],
|
|
34
|
+
['should get update on post.flagged event', 'post.flagged'],
|
|
35
|
+
['should get update on post.unflagged event', 'post.unflagged'],
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
test.each(events)('%s', async (test, event) => {
|
|
39
|
+
const update = {
|
|
40
|
+
...post,
|
|
41
|
+
data: { text: 'new-text' },
|
|
42
|
+
updatedAt: getFutureDate(post.updatedAt),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const callback = jest.fn();
|
|
46
|
+
client.http.get = jest.fn().mockResolvedValue(response);
|
|
47
|
+
|
|
48
|
+
livePost(post.postId, callback);
|
|
49
|
+
await pause();
|
|
50
|
+
client.emitter.emit(event, { posts: [update] });
|
|
51
|
+
await pause();
|
|
52
|
+
|
|
53
|
+
expect(callback).toHaveBeenCalledTimes(3);
|
|
54
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
55
|
+
3,
|
|
56
|
+
expect.objectContaining({
|
|
57
|
+
data: update,
|
|
58
|
+
loading: false,
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test.each([
|
|
64
|
+
['should get update on post.addReaction event', 'post.addReaction'],
|
|
65
|
+
['should get update on post.removeReaction event', 'post.removeReaction'],
|
|
66
|
+
] as [string, keyof Amity.MqttPostEvents][])('%s', async (test, event) => {
|
|
67
|
+
const update = {
|
|
68
|
+
...post,
|
|
69
|
+
data: { text: 'new-text' },
|
|
70
|
+
updatedAt: getFutureDate(post.updatedAt),
|
|
71
|
+
};
|
|
72
|
+
const reactor: Amity.Reaction = {
|
|
73
|
+
createdAt: getFutureDate(post.updatedAt),
|
|
74
|
+
reactionId: 'like',
|
|
75
|
+
reactionName: 'like',
|
|
76
|
+
referenceId: post.postId,
|
|
77
|
+
referenceType: 'post',
|
|
78
|
+
userId: user12.userId,
|
|
79
|
+
};
|
|
80
|
+
const callback = jest.fn();
|
|
81
|
+
client.http.get = jest.fn().mockResolvedValue(response);
|
|
82
|
+
|
|
83
|
+
livePost(post.postId, callback);
|
|
84
|
+
await pause();
|
|
85
|
+
client.emitter.emit(event, { posts: [update], reactor });
|
|
86
|
+
await pause();
|
|
87
|
+
|
|
88
|
+
expect(callback).toHaveBeenCalledTimes(3);
|
|
89
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
90
|
+
3,
|
|
91
|
+
expect.objectContaining({
|
|
92
|
+
data: update,
|
|
93
|
+
loading: false,
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
|
-
import {
|
|
3
|
-
client,
|
|
4
|
-
connectClient,
|
|
5
|
-
disconnectClient,
|
|
6
|
-
streamResponse,
|
|
7
|
-
} from '~/utils/tests';
|
|
2
|
+
import { client, connectClient, disconnectClient, streamResponse } from '~/utils/tests';
|
|
8
3
|
import { createStream } from '../createStream';
|
|
9
4
|
|
|
10
5
|
const bundle: Parameters<typeof createStream>[0] = {
|
|
11
6
|
title: 'my stream',
|
|
12
|
-
|
|
7
|
+
thumbnailFileId: streamResponse.data.videoStreamings[0].thumbnailFileId,
|
|
13
8
|
};
|
|
14
9
|
|
|
15
10
|
describe('createStream', () => {
|
|
@@ -21,10 +16,7 @@ describe('createStream', () => {
|
|
|
21
16
|
|
|
22
17
|
const created = await createStream(bundle);
|
|
23
18
|
|
|
24
|
-
expect(getActiveClient().http.post).toHaveBeenCalledWith(
|
|
25
|
-
`/api/v3/video-streaming`,
|
|
26
|
-
bundle
|
|
27
|
-
);
|
|
19
|
+
expect(getActiveClient().http.post).toHaveBeenCalledWith(`/api/v3/video-streaming`, bundle);
|
|
28
20
|
expect(created.data).toEqual(streamResponse.data.videoStreamings[0]);
|
|
29
21
|
});
|
|
30
22
|
});
|
|
@@ -39,9 +39,11 @@ describe('deleteStream', () => {
|
|
|
39
39
|
await deleteStream(STREAM_ID);
|
|
40
40
|
const recieved = pullFromCache(['stream', 'get', STREAM_ID])?.data;
|
|
41
41
|
|
|
42
|
-
expect(recieved).toEqual(
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
expect(recieved).toEqual(
|
|
43
|
+
expect.objectContaining({
|
|
44
|
+
isDeleted: true,
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
45
47
|
|
|
46
48
|
disableCache();
|
|
47
49
|
});
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { createSubChannel } from '../createSubChannel';
|
|
2
|
-
import {
|
|
3
|
-
client,
|
|
4
|
-
generateRawSubChannel,
|
|
5
|
-
createSubChannelError400301,
|
|
6
|
-
createSubChannelError400400,
|
|
7
|
-
} from '~/utils/tests';
|
|
2
|
+
import { client, generateRawSubChannel } from '~/utils/tests';
|
|
8
3
|
|
|
9
4
|
import { onSubChannelCreated } from '~/subChannel/events';
|
|
10
5
|
|
|
11
|
-
import { disableCache, enableCache, pullFromCache
|
|
6
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
7
|
+
import { ASCApiError } from '~/core/errors';
|
|
12
8
|
|
|
13
9
|
const subChannelId = 'channelId11--sub-channel-id';
|
|
14
10
|
|
|
@@ -38,37 +34,48 @@ describe('createSubChannel', () => {
|
|
|
38
34
|
|
|
39
35
|
// integration_test_id: f5b376b7-32b6-47f3-a5a1-553221340d17
|
|
40
36
|
test('it should return error 400400 when try to create subChannel from wrong parent channel Id', async () => {
|
|
37
|
+
const apiError = new ASCApiError(
|
|
38
|
+
'Channel not found.',
|
|
39
|
+
Amity.ServerError.ITEM_NOT_FOUND,
|
|
40
|
+
Amity.ErrorLevel.ERROR,
|
|
41
|
+
);
|
|
42
|
+
|
|
41
43
|
client.http.post = jest.fn().mockRejectedValue({
|
|
42
44
|
status: 404,
|
|
43
|
-
data:
|
|
45
|
+
data: apiError,
|
|
44
46
|
});
|
|
45
47
|
|
|
46
48
|
try {
|
|
47
49
|
await createSubChannel({
|
|
48
|
-
channelId:
|
|
50
|
+
channelId: 'invalid_channel_id',
|
|
49
51
|
displayName: 'sub channel name',
|
|
50
52
|
});
|
|
51
53
|
} catch ({ status = null, data = null }) {
|
|
52
54
|
expect(status).toEqual(404);
|
|
53
|
-
expect(data).toEqual(
|
|
55
|
+
expect(data).toEqual(apiError);
|
|
54
56
|
}
|
|
55
57
|
});
|
|
56
58
|
|
|
57
59
|
// integration_test_id: 73b59e57-2330-4ed3-95bd-241c9e7a2c43
|
|
58
|
-
test('it should return error 400301 when try to create subChannel from channel Id', async () => {
|
|
60
|
+
test('it should return error 400301 when try to create subChannel from channel Id which current user is not member', async () => {
|
|
61
|
+
const apiError = new ASCApiError(
|
|
62
|
+
'You are not a member of this channel.',
|
|
63
|
+
Amity.ServerError.PERMISSION_DENIED,
|
|
64
|
+
Amity.ErrorLevel.ERROR,
|
|
65
|
+
);
|
|
59
66
|
client.http.post = jest.fn().mockRejectedValue({
|
|
60
67
|
status: 403,
|
|
61
|
-
data:
|
|
68
|
+
data: apiError,
|
|
62
69
|
});
|
|
63
70
|
|
|
64
71
|
try {
|
|
65
72
|
await createSubChannel({
|
|
66
|
-
channelId:
|
|
73
|
+
channelId: 'invalid_channel_id',
|
|
67
74
|
displayName: 'sub channel name',
|
|
68
75
|
});
|
|
69
76
|
} catch ({ status = null, data = null }) {
|
|
70
77
|
expect(status).toEqual(403);
|
|
71
|
-
expect(data).toEqual(
|
|
78
|
+
expect(data).toEqual(apiError);
|
|
72
79
|
}
|
|
73
80
|
});
|
|
74
81
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { deleteSubChannel } from '../deleteSubChannel';
|
|
2
|
+
import { onSubChannelDeleted } from '../../events';
|
|
3
|
+
|
|
4
|
+
import { client, generateRawSubChannel } from '~/utils/tests';
|
|
5
|
+
|
|
6
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
7
|
+
import { ASCApiError } from '~/core/errors';
|
|
8
|
+
|
|
9
|
+
const subChannelId = 'channelId11--sub-channel-id';
|
|
10
|
+
|
|
11
|
+
describe('createSubChannel', () => {
|
|
12
|
+
beforeEach(enableCache);
|
|
13
|
+
|
|
14
|
+
afterEach(disableCache);
|
|
15
|
+
|
|
16
|
+
// integration_test_id: 43ba1273-4560-4cea-93ce-cf5728b2a475
|
|
17
|
+
test('it should delete sub channel', async () => {
|
|
18
|
+
const rawSubChannel = generateRawSubChannel();
|
|
19
|
+
const rawDeleteSubChannel = generateRawSubChannel({ isDeleted: true });
|
|
20
|
+
|
|
21
|
+
// Mock for getSubChannel
|
|
22
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
23
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
client.http.delete = jest.fn().mockResolvedValue({
|
|
27
|
+
data: {
|
|
28
|
+
messageFeeds: [rawDeleteSubChannel],
|
|
29
|
+
messages: [],
|
|
30
|
+
users: [],
|
|
31
|
+
files: [],
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const result = await deleteSubChannel(subChannelId);
|
|
36
|
+
expect(result.isDeleted).toEqual(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// integration_test_id: 57ba785f-484b-4f19-aa38-18e0bd4ec433
|
|
40
|
+
test('it should return error 400400 when try to delete subChannel from invalid subChannelId', async () => {
|
|
41
|
+
const apiError = new ASCApiError(
|
|
42
|
+
'Feed not found',
|
|
43
|
+
Amity.ServerError.ITEM_NOT_FOUND,
|
|
44
|
+
Amity.ErrorLevel.ERROR,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
client.http.get = jest.fn().mockRejectedValue({
|
|
48
|
+
status: 404,
|
|
49
|
+
data: apiError,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
await deleteSubChannel(subChannelId);
|
|
54
|
+
} catch ({ status = null, data = null }) {
|
|
55
|
+
expect(status).toEqual(404);
|
|
56
|
+
expect(data).toEqual(apiError);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('it should return a valid sub channel from cache', async () => {
|
|
61
|
+
const rawSubChannel = generateRawSubChannel();
|
|
62
|
+
const rawDeleteSubChannel = generateRawSubChannel({ isDeleted: true });
|
|
63
|
+
|
|
64
|
+
// Mock for getSubChannel
|
|
65
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
66
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
client.http.delete = jest.fn().mockResolvedValue({
|
|
70
|
+
data: {
|
|
71
|
+
messageFeeds: [rawDeleteSubChannel],
|
|
72
|
+
messages: [],
|
|
73
|
+
users: [],
|
|
74
|
+
files: [],
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await deleteSubChannel(subChannelId);
|
|
79
|
+
|
|
80
|
+
const cache = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
81
|
+
|
|
82
|
+
expect(cache?.data).toEqual(expect.objectContaining({ isDeleted: true }));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('should fire event `onChannelDeleted`', async () => {
|
|
86
|
+
let dispose;
|
|
87
|
+
const rawSubChannel = generateRawSubChannel();
|
|
88
|
+
const rawDeleteSubChannel = generateRawSubChannel({ isDeleted: true });
|
|
89
|
+
|
|
90
|
+
// Mock for getSubChannel
|
|
91
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
92
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
client.http.delete = jest.fn().mockResolvedValue({
|
|
96
|
+
data: {
|
|
97
|
+
messageFeeds: [rawDeleteSubChannel],
|
|
98
|
+
messages: [],
|
|
99
|
+
users: [],
|
|
100
|
+
files: [],
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const callbackPromise = new Promise(resolve => {
|
|
105
|
+
dispose = onSubChannelDeleted(resolve);
|
|
106
|
+
}).finally(dispose);
|
|
107
|
+
|
|
108
|
+
await deleteSubChannel(subChannelId);
|
|
109
|
+
|
|
110
|
+
await expect(callbackPromise).resolves.toEqual(expect.objectContaining({ isDeleted: true }));
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getSubChannel } from '../getSubChannel';
|
|
2
|
+
import { client, generateRawSubChannel } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
5
|
+
import { ASCApiError } from '~/core/errors';
|
|
6
|
+
import { onSubChannelFetched } from '../../events/onSubChannelFetched';
|
|
7
|
+
|
|
8
|
+
const subChannelId = 'channelId11--sub-channel-id';
|
|
9
|
+
|
|
10
|
+
const subChannelPayload = {
|
|
11
|
+
channelId: 'channelId11',
|
|
12
|
+
displayName: 'sub channel name',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('createSubChannel', () => {
|
|
16
|
+
beforeEach(enableCache);
|
|
17
|
+
|
|
18
|
+
afterEach(disableCache);
|
|
19
|
+
|
|
20
|
+
// integration_test_id: 6f019056-921e-43e2-a426-dd5a96f2fdcf
|
|
21
|
+
test('it should return a valid sub channel', async () => {
|
|
22
|
+
const rawSubChannel = generateRawSubChannel();
|
|
23
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
24
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const { data } = await getSubChannel(subChannelId);
|
|
28
|
+
|
|
29
|
+
expect(data.channelId).toEqual(subChannelPayload.channelId);
|
|
30
|
+
expect(data.displayName).toEqual(subChannelPayload.displayName);
|
|
31
|
+
expect(data.subChannelId).toEqual(subChannelId);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// integration_test_id: 0dc440b6-b2bb-41fb-bbe8-1b2a4c71bffc
|
|
35
|
+
test('it should return error 400400 when try to get subChannel from invalid subChannelId', async () => {
|
|
36
|
+
const apiError = new ASCApiError(
|
|
37
|
+
'Feed not found',
|
|
38
|
+
Amity.ServerError.ITEM_NOT_FOUND,
|
|
39
|
+
Amity.ErrorLevel.ERROR,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
client.http.put = jest.fn().mockRejectedValue({
|
|
43
|
+
status: 404,
|
|
44
|
+
data: apiError,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
await getSubChannel(subChannelId);
|
|
49
|
+
} catch ({ status = null, data = null }) {
|
|
50
|
+
expect(status).toEqual(404);
|
|
51
|
+
expect(data).toEqual(apiError);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('it should return a valid sub channel from cache', async () => {
|
|
56
|
+
const rawSubChannel = generateRawSubChannel();
|
|
57
|
+
client.http.put = jest.fn().mockResolvedValue({
|
|
58
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const { data } = await getSubChannel(subChannelId);
|
|
62
|
+
|
|
63
|
+
const cache = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
64
|
+
|
|
65
|
+
expect(cache?.data).toEqual(data);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('it should return a valid sub channel from locally cache', async () => {
|
|
69
|
+
const rawSubChannel = generateRawSubChannel();
|
|
70
|
+
client.http.put = jest.fn().mockResolvedValue({
|
|
71
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await getSubChannel(subChannelId);
|
|
75
|
+
|
|
76
|
+
const cache = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
77
|
+
const locallyData = await getSubChannel.locally(subChannelId);
|
|
78
|
+
|
|
79
|
+
expect(cache?.data).toEqual(locallyData?.data);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('should fire event `onSubChannelFetched`', async () => {
|
|
83
|
+
let dispose;
|
|
84
|
+
const rawSubChannel = generateRawSubChannel();
|
|
85
|
+
client.http.put = jest.fn().mockResolvedValue({
|
|
86
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const callbackPromise = new Promise(resolve => {
|
|
90
|
+
dispose = onSubChannelFetched(resolve);
|
|
91
|
+
}).finally(dispose);
|
|
92
|
+
|
|
93
|
+
const { data } = await getSubChannel(subChannelId);
|
|
94
|
+
|
|
95
|
+
await expect(callbackPromise).resolves.toMatchObject(data);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getSubChannels } from '../getSubChannels';
|
|
2
|
+
import { client, generateRawSubChannel } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
5
|
+
import { ASCApiError } from '~/core/errors';
|
|
6
|
+
import { onSubChannelFetched } from '../../events/onSubChannelFetched';
|
|
7
|
+
|
|
8
|
+
const subChannelId = 'channelId11--sub-channel-id';
|
|
9
|
+
|
|
10
|
+
const subChannelPayload = {
|
|
11
|
+
channelId: 'channelId11',
|
|
12
|
+
displayName: 'sub channel name',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('createSubChannel', () => {
|
|
16
|
+
beforeEach(enableCache);
|
|
17
|
+
|
|
18
|
+
afterEach(disableCache);
|
|
19
|
+
|
|
20
|
+
// integration_test_id: dc771f42-14b9-420e-999d-858151e8ce41
|
|
21
|
+
test('it should return a valid sub channel', async () => {
|
|
22
|
+
const rawSubChannel = generateRawSubChannel();
|
|
23
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
24
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const { data } = await getSubChannels([subChannelId]);
|
|
28
|
+
|
|
29
|
+
expect(data[0].channelId).toEqual(subChannelPayload.channelId);
|
|
30
|
+
expect(data[0].displayName).toEqual(subChannelPayload.displayName);
|
|
31
|
+
expect(data[0].subChannelId).toEqual(subChannelId);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// integration_test_id: 28710df0-e5b6-4e46-b1aa-440d5ea01995
|
|
35
|
+
test('it should return error 400400 when try to get subChannel from invalid subChannelId', async () => {
|
|
36
|
+
const apiError = new ASCApiError(
|
|
37
|
+
'Feed not found',
|
|
38
|
+
Amity.ServerError.ITEM_NOT_FOUND,
|
|
39
|
+
Amity.ErrorLevel.ERROR,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
client.http.get = jest.fn().mockRejectedValue({
|
|
43
|
+
status: 404,
|
|
44
|
+
data: apiError,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
await getSubChannels([subChannelId]);
|
|
49
|
+
} catch ({ status = null, data = null }) {
|
|
50
|
+
expect(status).toEqual(404);
|
|
51
|
+
expect(data).toEqual(apiError);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('it should return a valid sub channel from cache', async () => {
|
|
56
|
+
const rawSubChannel = generateRawSubChannel();
|
|
57
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
58
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const { data } = await getSubChannels([subChannelId]);
|
|
62
|
+
|
|
63
|
+
const cache = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
64
|
+
|
|
65
|
+
expect(cache?.data).toEqual(data[0]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('it should return a valid sub channel from locally cache', async () => {
|
|
69
|
+
const rawSubChannel = generateRawSubChannel();
|
|
70
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
71
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await getSubChannels([subChannelId]);
|
|
75
|
+
|
|
76
|
+
const cache = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
77
|
+
const locallyData = await getSubChannels.locally([subChannelId]);
|
|
78
|
+
|
|
79
|
+
expect(cache?.data).toEqual(locallyData?.data[0]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('should fire event `onSubChannelFetched`', async () => {
|
|
83
|
+
let dispose;
|
|
84
|
+
const rawSubChannel = generateRawSubChannel();
|
|
85
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
86
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const callbackPromise = new Promise(resolve => {
|
|
90
|
+
dispose = onSubChannelFetched(resolve);
|
|
91
|
+
}).finally(dispose);
|
|
92
|
+
|
|
93
|
+
const { data } = await getSubChannels([subChannelId]);
|
|
94
|
+
|
|
95
|
+
await expect(callbackPromise).resolves.toMatchObject(data[0]);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { updateSubChannel } from '../updateSubChannel';
|
|
2
|
+
import { client, generateRawSubChannel } from '~/utils/tests';
|
|
3
|
+
|
|
4
|
+
import { onSubChannelUpdated } from '~/subChannel/events';
|
|
5
|
+
|
|
6
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
7
|
+
import { ASCApiError } from '~/core/errors';
|
|
8
|
+
|
|
9
|
+
const subChannelId = 'channelId11--sub-channel-id';
|
|
10
|
+
|
|
11
|
+
const subChannelPayload = {
|
|
12
|
+
channelId: 'channelId11',
|
|
13
|
+
displayName: 'sub channel name',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('createSubChannel', () => {
|
|
17
|
+
beforeEach(enableCache);
|
|
18
|
+
|
|
19
|
+
afterEach(disableCache);
|
|
20
|
+
|
|
21
|
+
// integration_test_id: 9f50fa02-c26c-4666-8e8b-2d9076a3edd3
|
|
22
|
+
test('it should return a valid sub channel', async () => {
|
|
23
|
+
const rawSubChannel = generateRawSubChannel();
|
|
24
|
+
client.http.put = jest.fn().mockResolvedValue({
|
|
25
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const { data } = await updateSubChannel(subChannelId, subChannelPayload);
|
|
29
|
+
|
|
30
|
+
expect(data.channelId).toEqual(subChannelPayload.channelId);
|
|
31
|
+
expect(data.displayName).toEqual(subChannelPayload.displayName);
|
|
32
|
+
expect(data.subChannelId).toEqual(subChannelId);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// integration_test_id: 118f410c-5476-4c4e-9199-ac166da30840
|
|
36
|
+
test('it should return error 400400 when try to update subChannel from wrong sub channel Id', async () => {
|
|
37
|
+
const apiError = new ASCApiError(
|
|
38
|
+
'Feed not found',
|
|
39
|
+
Amity.ServerError.ITEM_NOT_FOUND,
|
|
40
|
+
Amity.ErrorLevel.ERROR,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
client.http.put = jest.fn().mockRejectedValue({
|
|
44
|
+
status: 404,
|
|
45
|
+
data: apiError,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
await updateSubChannel(subChannelId, {
|
|
50
|
+
displayName: 'sub channel name',
|
|
51
|
+
});
|
|
52
|
+
} catch ({ status = null, data = null }) {
|
|
53
|
+
expect(status).toEqual(404);
|
|
54
|
+
expect(data).toEqual(apiError);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('it should return a valid sub channel from cache', async () => {
|
|
59
|
+
const rawSubChannel = generateRawSubChannel();
|
|
60
|
+
client.http.put = jest.fn().mockResolvedValue({
|
|
61
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const { data } = await updateSubChannel(subChannelId, subChannelPayload);
|
|
65
|
+
|
|
66
|
+
const cache = pullFromCache(['subChannel', 'get', subChannelId]);
|
|
67
|
+
|
|
68
|
+
expect(cache?.data).toEqual(data);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should fire event `onSubChannelUpdated`', async () => {
|
|
72
|
+
let dispose;
|
|
73
|
+
const rawSubChannel = generateRawSubChannel();
|
|
74
|
+
client.http.put = jest.fn().mockResolvedValue({
|
|
75
|
+
data: { messageFeeds: [rawSubChannel], messages: [], users: [], files: [] },
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const callbackPromise = new Promise(resolve => {
|
|
79
|
+
dispose = onSubChannelUpdated(resolve);
|
|
80
|
+
}).finally(dispose);
|
|
81
|
+
|
|
82
|
+
const { data } = await updateSubChannel(subChannelId, subChannelPayload);
|
|
83
|
+
|
|
84
|
+
await expect(callbackPromise).resolves.toMatchObject(data);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createQuery, runQuery } from '~/core/query';
|
|
3
|
-
import { LIVE_OBJECT_ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
4
|
-
import { hasUpdates } from '~/core/model';
|
|
1
|
+
import { liveObject } from '~/utils/liveObject';
|
|
5
2
|
import { getSubChannel } from '../api';
|
|
6
3
|
import { onSubChannelDeleted, onSubChannelUpdated } from '../events';
|
|
7
4
|
import { onSubChannelFetched } from '../events/onSubChannelFetched';
|
|
@@ -29,56 +26,9 @@ export const liveSubChannel = (
|
|
|
29
26
|
subChannelId: Amity.SubChannel['subChannelId'],
|
|
30
27
|
callback: Amity.LiveObjectCallback<Amity.SubChannel>,
|
|
31
28
|
): Amity.Unsubscriber => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let subChannel: Amity.SubChannel;
|
|
41
|
-
const disposers: Amity.Unsubscriber[] = [];
|
|
42
|
-
|
|
43
|
-
const dispatcher = (data: Amity.LiveObject<Amity.SubChannel>) => {
|
|
44
|
-
subChannel = data.data;
|
|
45
|
-
callback(data);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const realtimeRouter = (eventSubChannel: Amity.SubChannel) => {
|
|
49
|
-
if (subChannelId !== eventSubChannel.subChannelId) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (subChannel && !hasUpdates(subChannel, eventSubChannel)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
dispatcher({ loading: false, data: eventSubChannel, origin: 'event' });
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const onFetch = () => {
|
|
61
|
-
const query = createQuery(getSubChannel, subChannelId);
|
|
62
|
-
|
|
63
|
-
runQuery(query, ({ error, data, loading, origin }) => {
|
|
64
|
-
dispatcher({ error, data, loading, origin });
|
|
65
|
-
|
|
66
|
-
if (error) {
|
|
67
|
-
disposers.forEach(fn => fn());
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
disposers.push(
|
|
73
|
-
onSubChannelFetched(realtimeRouter),
|
|
74
|
-
onSubChannelUpdated(realtimeRouter),
|
|
75
|
-
onSubChannelDeleted(realtimeRouter),
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
onFetch();
|
|
79
|
-
|
|
80
|
-
return () => {
|
|
81
|
-
log(`liveSubChannel(tmpid: ${timestamp}) > dispose`);
|
|
82
|
-
disposers.forEach(fn => fn());
|
|
83
|
-
};
|
|
29
|
+
return liveObject(subChannelId, callback, 'subChannelId', getSubChannel, [
|
|
30
|
+
onSubChannelFetched,
|
|
31
|
+
onSubChannelUpdated,
|
|
32
|
+
onSubChannelDeleted,
|
|
33
|
+
]);
|
|
84
34
|
};
|