@amityco/ts-sdk 0.0.1-beta.41.1 → 0.0.1-beta.42.2
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/dist/@types/core/model.d.ts +3 -1
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/domains/category.d.ts +1 -1
- package/dist/@types/domains/category.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -1
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +1 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +1 -1
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +1 -1
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/subChannel.d.ts +1 -1
- package/dist/@types/domains/subChannel.d.ts.map +1 -1
- package/dist/cache/utils/index.d.ts +1 -0
- package/dist/cache/utils/index.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts.map +1 -1
- package/dist/category/observers/liveCategories.d.ts.map +1 -1
- package/dist/channel/observers/liveChannel.d.ts.map +1 -1
- package/dist/channel/observers/liveChannels.d.ts.map +1 -1
- package/dist/comment/api/queryComments.d.ts.map +1 -1
- package/dist/comment/api/tests/queryComments.test.d.ts +2 -0
- package/dist/comment/api/tests/queryComments.test.d.ts.map +1 -0
- package/dist/comment/observers/liveComments.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/observers/liveCommunities.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/core/model/index.d.ts +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/follow/api/getFollowInfo.d.ts.map +1 -1
- package/dist/follow/observers/index.d.ts +1 -0
- package/dist/follow/observers/index.d.ts.map +1 -1
- package/dist/follow/observers/liveFollowInfo.d.ts +21 -0
- package/dist/follow/observers/liveFollowInfo.d.ts.map +1 -0
- package/dist/follow/observers/tests/liveFollowInfo.test.d.ts +2 -0
- package/dist/follow/observers/tests/liveFollowInfo.test.d.ts.map +1 -0
- package/dist/index.cjs.js +112 -63
- package/dist/index.esm.js +112 -64
- package/dist/index.umd.js +4 -4
- package/dist/message/api/createMessage.d.ts +2 -1
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/observers/liveMessages.d.ts.map +1 -1
- package/dist/message/utils/index.d.ts +3 -2
- package/dist/message/utils/index.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/post/observers/livePosts.d.ts.map +1 -1
- package/dist/subChannel/api/querySubChannels.d.ts.map +1 -1
- package/dist/subChannel/observers/liveSubChannels.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/liveObject.d.ts +1 -1
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +77 -0
- package/dist/utils/tests/dummy/comment.d.ts.map +1 -0
- package/dist/utils/tests/dummy/community.d.ts +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 +0 -12
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/model.ts +3 -1
- package/src/@types/domains/category.ts +1 -1
- package/src/@types/domains/comment.ts +1 -1
- package/src/@types/domains/community.ts +1 -1
- package/src/@types/domains/message.ts +1 -1
- package/src/@types/domains/post.ts +1 -1
- package/src/@types/domains/subChannel.ts +1 -1
- package/src/cache/utils/index.ts +5 -2
- package/src/category/api/queryCategories.ts +2 -1
- package/src/category/observers/liveCategories.ts +3 -1
- package/src/category/observers/tests/liveCategories.test.ts +1 -3
- package/src/channel/api/tests/addChannelMembers.test.ts +13 -0
- package/src/channel/api/tests/queryChannelMembers.test.ts +1 -0
- package/src/channel/api/tests/removeChannelMembers.test.ts +9 -2
- package/src/channel/observers/liveChannel.ts +16 -1
- package/src/channel/observers/liveChannels.ts +11 -9
- package/src/comment/api/queryComments.ts +2 -1
- package/src/comment/api/tests/createComment.test.ts +17 -112
- package/src/comment/api/tests/queryComments.test.ts +147 -0
- package/src/comment/api/tests/updateComment.test.ts +14 -85
- package/src/comment/observers/liveComments.ts +12 -7
- package/src/community/api/queryCommunities.ts +2 -1
- package/src/community/api/test/queryCommunity.test.ts +30 -0
- package/src/community/observers/liveCommunities.ts +13 -7
- package/src/community/observers/tests/liveCommunities.test.ts +2 -2
- package/src/core/model/idResolvers.ts +1 -0
- package/src/core/model/identifyModel.ts +2 -1
- package/src/core/model/index.ts +11 -2
- package/src/follow/api/getFollowInfo.ts +4 -8
- package/src/follow/observers/index.ts +1 -0
- package/src/follow/observers/liveFollowInfo.ts +29 -0
- package/src/follow/observers/tests/liveFollowInfo.test.ts +198 -0
- package/src/message/api/createMessage.ts +17 -5
- package/src/message/api/tests/createMessage.test.ts +36 -5
- package/src/message/api/tests/deleteMessage.test.ts +10 -3
- package/src/message/api/tests/getMessage.test.ts +9 -3
- package/src/message/api/tests/queryMessages.test.ts +30 -0
- package/src/message/api/tests/updateMessage.test.ts +9 -2
- package/src/message/observers/liveMessages.ts +15 -15
- package/src/message/tests/observers/liveMessages.test.ts +2 -2
- package/src/message/utils/index.ts +10 -1
- package/src/post/api/queryPosts.ts +2 -1
- package/src/post/api/tests/queryPosts.test.ts +30 -0
- package/src/post/observers/livePosts.ts +16 -11
- package/src/post/observers/tests/livePosts.test.ts +4 -5
- package/src/reaction/api/tests/addReaction.test.ts +13 -0
- package/src/reaction/api/tests/removeReaction.test.ts +13 -0
- package/src/subChannel/api/querySubChannels.ts +2 -1
- package/src/subChannel/observers/liveSubChannels.ts +6 -5
- package/src/subChannel/observers/tests/liveSubChannels.test.ts +5 -2
- package/src/utils/constants.ts +2 -1
- package/src/utils/liveObject.ts +1 -4
- package/src/utils/tests/dummy/comment.ts +268 -0
- package/src/utils/tests/dummy/index.ts +1 -0
- package/src/utils/tests/dummy/post.ts +0 -114
- package/dist/post/tests/api/getPost.test.d.ts +0 -2
- package/dist/post/tests/api/getPost.test.d.ts.map +0 -1
- package/dist/post/tests/api/queryPosts.test.d.ts +0 -2
- package/dist/post/tests/api/queryPosts.test.d.ts.map +0 -1
- package/src/post/tests/api/getPost.test.ts +0 -98
- package/src/post/tests/api/queryPosts.test.ts +0 -123
|
@@ -7,122 +7,27 @@ import {
|
|
|
7
7
|
imageComment11,
|
|
8
8
|
textImageComment11,
|
|
9
9
|
textMentionComment11,
|
|
10
|
-
|
|
10
|
+
comment12,
|
|
11
11
|
post11,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
imageCommentResponse,
|
|
13
|
+
textCommentParentIdResponse,
|
|
14
|
+
textCommentResponse,
|
|
15
|
+
textImageCommentResponse,
|
|
16
|
+
textMentionCommentResponse,
|
|
17
|
+
imageCommentRequestPayload,
|
|
18
|
+
textCommentParentIdRequestPayload,
|
|
19
|
+
textCommentRequestPayload,
|
|
20
|
+
textCommentWithMentionRequestPayload,
|
|
21
|
+
textImageCommentRequestPayload,
|
|
21
22
|
} from '~/utils/tests';
|
|
22
23
|
import { ASCApiError } from '~/core/errors';
|
|
23
24
|
import { createComment } from '../createComment';
|
|
24
25
|
|
|
25
|
-
const createTextCommentResponse = {
|
|
26
|
-
data: {
|
|
27
|
-
...textCommentPayload,
|
|
28
|
-
files: [],
|
|
29
|
-
commentChildren: [],
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const createImageCommentResponse = {
|
|
34
|
-
data: {
|
|
35
|
-
...imageCommentPayload,
|
|
36
|
-
files: [],
|
|
37
|
-
commentChildren: [],
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const createTextImageCommentResponse = {
|
|
42
|
-
data: {
|
|
43
|
-
...textImageCommentPayload,
|
|
44
|
-
files: [],
|
|
45
|
-
commentChildren: [],
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const createTextMentionCommentResponse = {
|
|
50
|
-
data: {
|
|
51
|
-
...textCommentMentionPayload,
|
|
52
|
-
files: [],
|
|
53
|
-
commentChildren: [],
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const createTextCommentParentIdResponse = {
|
|
58
|
-
data: {
|
|
59
|
-
...textCommentParentIdPayload,
|
|
60
|
-
files: [],
|
|
61
|
-
commentChildren: [],
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
26
|
const getPostResponse = {
|
|
66
27
|
data: post11,
|
|
67
28
|
cachedAt: 1673337034544,
|
|
68
29
|
};
|
|
69
30
|
|
|
70
|
-
const textCommentRequestPayload: Parameters<typeof createComment>[0] = {
|
|
71
|
-
referenceId: post11.postId,
|
|
72
|
-
referenceType: 'post',
|
|
73
|
-
data: {
|
|
74
|
-
text: 'test',
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const textCommentParentIdRequestPayload: Parameters<typeof createComment>[0] = {
|
|
79
|
-
referenceId: post11.postId,
|
|
80
|
-
referenceType: 'post',
|
|
81
|
-
parentId: post12.postId,
|
|
82
|
-
data: {
|
|
83
|
-
text: 'test',
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const imageCommentRequestPayload: Parameters<typeof createComment>[0] = {
|
|
88
|
-
referenceId: post11.postId,
|
|
89
|
-
referenceType: 'post',
|
|
90
|
-
attachments: [
|
|
91
|
-
{
|
|
92
|
-
type: 'image',
|
|
93
|
-
fileId: file11.fileId,
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const textImageCommentRequestPayload: Parameters<typeof createComment>[0] = {
|
|
99
|
-
referenceId: post11.postId,
|
|
100
|
-
referenceType: 'post',
|
|
101
|
-
data: {
|
|
102
|
-
text: 'test',
|
|
103
|
-
},
|
|
104
|
-
attachments: [
|
|
105
|
-
{
|
|
106
|
-
type: 'image',
|
|
107
|
-
fileId: file11.fileId,
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const textCommentWithMentionRequestPayload: Parameters<typeof createComment>[0] = {
|
|
113
|
-
referenceId: post11.postId,
|
|
114
|
-
referenceType: 'post',
|
|
115
|
-
data: {
|
|
116
|
-
text: 'test',
|
|
117
|
-
},
|
|
118
|
-
mentionees: [
|
|
119
|
-
{
|
|
120
|
-
type: 'user',
|
|
121
|
-
userIds: [user11._id, user12._id],
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
};
|
|
125
|
-
|
|
126
31
|
jest.mock('~/post/api/getPost', () => ({
|
|
127
32
|
getPost: jest.fn(() => Promise.resolve(getPostResponse)),
|
|
128
33
|
}));
|
|
@@ -133,7 +38,7 @@ describe('createComment', () => {
|
|
|
133
38
|
|
|
134
39
|
// integration_test_id: 2f83eabc-46db-43d8-89c6-1b5339d6a273
|
|
135
40
|
it('creates a text comment and returns the new valid comment', async () => {
|
|
136
|
-
client.http.post = jest.fn().mockResolvedValueOnce(
|
|
41
|
+
client.http.post = jest.fn().mockResolvedValueOnce(textCommentResponse);
|
|
137
42
|
|
|
138
43
|
const newComment = await createComment(textCommentRequestPayload);
|
|
139
44
|
|
|
@@ -146,7 +51,7 @@ describe('createComment', () => {
|
|
|
146
51
|
|
|
147
52
|
// integration_test_id: 81e7d5bc-6881-4f9b-b8d4-deb5fe67200c
|
|
148
53
|
it('creates a image comment and returns the new valid comment', async () => {
|
|
149
|
-
client.http.post = jest.fn().mockResolvedValueOnce(
|
|
54
|
+
client.http.post = jest.fn().mockResolvedValueOnce(imageCommentResponse);
|
|
150
55
|
|
|
151
56
|
const newComment = await createComment(imageCommentRequestPayload);
|
|
152
57
|
|
|
@@ -159,7 +64,7 @@ describe('createComment', () => {
|
|
|
159
64
|
|
|
160
65
|
// integration_test_id: 015838a8-3267-4253-920a-9ae83197cf22
|
|
161
66
|
it('creates an image + text comment and returns the new valid comment', async () => {
|
|
162
|
-
client.http.post = jest.fn().mockResolvedValueOnce(
|
|
67
|
+
client.http.post = jest.fn().mockResolvedValueOnce(textImageCommentResponse);
|
|
163
68
|
|
|
164
69
|
const newComment = await createComment(textImageCommentRequestPayload);
|
|
165
70
|
|
|
@@ -172,7 +77,7 @@ describe('createComment', () => {
|
|
|
172
77
|
|
|
173
78
|
// integration_test_id: c2285355-f3b6-4e22-926b-11bcf0393161
|
|
174
79
|
it('creates text comment with mention and returns the new valid comment', async () => {
|
|
175
|
-
client.http.post = jest.fn().mockResolvedValueOnce(
|
|
80
|
+
client.http.post = jest.fn().mockResolvedValueOnce(textMentionCommentResponse);
|
|
176
81
|
|
|
177
82
|
const newComment = await createComment(textCommentWithMentionRequestPayload);
|
|
178
83
|
|
|
@@ -185,7 +90,7 @@ describe('createComment', () => {
|
|
|
185
90
|
|
|
186
91
|
// integration_test_id: cb1bfe11-c11a-4324-aeb5-03370da820ad
|
|
187
92
|
it('creates text comment with parent_id and returns the new valid comment', async () => {
|
|
188
|
-
client.http.post = jest.fn().mockResolvedValueOnce(
|
|
93
|
+
client.http.post = jest.fn().mockResolvedValueOnce(textCommentParentIdResponse);
|
|
189
94
|
|
|
190
95
|
const newComment = await createComment(textCommentParentIdRequestPayload);
|
|
191
96
|
|
|
@@ -193,7 +98,7 @@ describe('createComment', () => {
|
|
|
193
98
|
'/api/v3/comments',
|
|
194
99
|
textCommentParentIdRequestPayload,
|
|
195
100
|
);
|
|
196
|
-
expect(newComment.data).toEqual(
|
|
101
|
+
expect(newComment.data).toEqual(comment12);
|
|
197
102
|
});
|
|
198
103
|
|
|
199
104
|
// integration_test_id: 7f411488-abba-46d1-8707-a1d8adbd7242
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { queryComments } from '../queryComments';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
client,
|
|
5
|
+
connectClient,
|
|
6
|
+
disconnectClient,
|
|
7
|
+
textCommentPayload,
|
|
8
|
+
imageCommentPayload,
|
|
9
|
+
post11,
|
|
10
|
+
textCommentResponse,
|
|
11
|
+
imageCommentResponse,
|
|
12
|
+
textAndImageCommentMixedPayload,
|
|
13
|
+
textCommentRequestPayload,
|
|
14
|
+
comment12,
|
|
15
|
+
comment12Payload,
|
|
16
|
+
deletedCommentPayload,
|
|
17
|
+
deletedCommentResponse,
|
|
18
|
+
} from '~/utils/tests';
|
|
19
|
+
import { ASCApiError } from '~/core/errors';
|
|
20
|
+
|
|
21
|
+
type mockParamAndResponse = {
|
|
22
|
+
query: Amity.QueryComments;
|
|
23
|
+
response: Amity.Comment[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const queryParams: mockParamAndResponse = {
|
|
27
|
+
query: {
|
|
28
|
+
referenceType: 'post',
|
|
29
|
+
referenceId: post11.postId,
|
|
30
|
+
},
|
|
31
|
+
response: textCommentPayload.comments,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const queryImageOnly: mockParamAndResponse = {
|
|
35
|
+
query: {
|
|
36
|
+
...queryParams.query,
|
|
37
|
+
dataTypes: {
|
|
38
|
+
values: ['image'],
|
|
39
|
+
matchType: 'exact',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
response: imageCommentPayload.comments,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const queryImageAny: mockParamAndResponse = {
|
|
46
|
+
query: {
|
|
47
|
+
...queryParams.query,
|
|
48
|
+
dataTypes: {
|
|
49
|
+
values: ['image'],
|
|
50
|
+
matchType: 'any',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
response: textAndImageCommentMixedPayload.comments,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const queryWithParentId: mockParamAndResponse = {
|
|
57
|
+
query: {
|
|
58
|
+
...queryParams.query,
|
|
59
|
+
parentId: comment12.parentId,
|
|
60
|
+
},
|
|
61
|
+
response: comment12Payload.comments,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const deletedComment: mockParamAndResponse = {
|
|
65
|
+
query: {
|
|
66
|
+
...queryParams.query,
|
|
67
|
+
includeDeleted: true,
|
|
68
|
+
},
|
|
69
|
+
response: deletedCommentPayload.comments,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
describe('queryComments', () => {
|
|
73
|
+
beforeAll(connectClient);
|
|
74
|
+
afterAll(disconnectClient);
|
|
75
|
+
|
|
76
|
+
const testCase: [string, object, Amity.QueryComments, Amity.Comment[]][] = [
|
|
77
|
+
[
|
|
78
|
+
// integration_test_id: 0be48975-be6d-4199-bec0-af186af444d3
|
|
79
|
+
'Should return valid comment when user query with valid query',
|
|
80
|
+
textCommentResponse,
|
|
81
|
+
queryParams.query,
|
|
82
|
+
queryParams.response,
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
// integration_test_id: 4550e036-53d0-4f35-b83f-9edc10f1c974
|
|
86
|
+
|
|
87
|
+
'Should return only valid image comment types when user query with dataType exact image',
|
|
88
|
+
imageCommentResponse,
|
|
89
|
+
queryImageOnly.query,
|
|
90
|
+
queryImageOnly.response,
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
// integration_test_id: 03056892-251f-4a85-a9bf-f9978c1912e5
|
|
94
|
+
'Should return only valid deleted comment list when user query with isDeleted=true',
|
|
95
|
+
deletedCommentResponse,
|
|
96
|
+
deletedComment.query,
|
|
97
|
+
deletedComment.response,
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
// integration_test_id: 2f68da78-7738-4371-ae72-b6a4ff043404
|
|
101
|
+
|
|
102
|
+
'Should return only valid mixed types comment list when user query with dataType any image',
|
|
103
|
+
{
|
|
104
|
+
data: {
|
|
105
|
+
...textAndImageCommentMixedPayload,
|
|
106
|
+
paging: {},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
queryImageAny.query,
|
|
110
|
+
queryImageAny.response,
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
// integration_test_id: 8207d436-a800-4224-8fb0-a46c05f7d11e
|
|
114
|
+
'Should return only valid mixed types comment list when user query with parent_id',
|
|
115
|
+
{
|
|
116
|
+
data: {
|
|
117
|
+
...comment12Payload,
|
|
118
|
+
paging: {},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
queryWithParentId.query,
|
|
122
|
+
queryWithParentId.response,
|
|
123
|
+
],
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
test.each(testCase)('%s', async (title, mockResponse, query, expectResult) => {
|
|
127
|
+
client.http.get = jest.fn().mockResolvedValueOnce(mockResponse);
|
|
128
|
+
const result = await queryComments(query);
|
|
129
|
+
expect(result.data).toEqual(expectResult);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const errorCase: [string, number, Amity.QueryComments][] = [
|
|
133
|
+
[
|
|
134
|
+
// integration_test_id: 2719d77f-177a-401f-864f-ef0f0804cc24
|
|
135
|
+
'Should return error 400400 when query with wrong post_id', // title
|
|
136
|
+
Amity.ServerError.ITEM_NOT_FOUND, // errorCode
|
|
137
|
+
textCommentRequestPayload, // payload
|
|
138
|
+
],
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
test.each(errorCase)('%s', async (title, errorCode, payload) => {
|
|
142
|
+
client.http.get = jest
|
|
143
|
+
.fn()
|
|
144
|
+
.mockRejectedValueOnce(new ASCApiError('not found!', errorCode, Amity.ErrorLevel.ERROR));
|
|
145
|
+
await expect(queryComments(payload)).rejects.toThrow();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -9,88 +9,17 @@ import {
|
|
|
9
9
|
imageComment11,
|
|
10
10
|
textImageComment11,
|
|
11
11
|
textMentionComment11,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
imageCommentResponse,
|
|
13
|
+
textCommentResponse,
|
|
14
|
+
textImageCommentResponse,
|
|
15
|
+
textMentionCommentResponse,
|
|
16
|
+
imageCommentRequestPayload,
|
|
17
|
+
textCommentRequestPayload,
|
|
18
|
+
textCommentWithMentionRequestPayload,
|
|
19
|
+
textImageCommentRequestPayload,
|
|
20
20
|
} from '~/utils/tests';
|
|
21
21
|
import { ASCApiError } from '~/core/errors';
|
|
22
22
|
|
|
23
|
-
const updateTextCommentResponse = {
|
|
24
|
-
data: {
|
|
25
|
-
...textCommentPayload,
|
|
26
|
-
files: [],
|
|
27
|
-
commentChildren: [],
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const updateImageCommentResponse = {
|
|
32
|
-
data: {
|
|
33
|
-
...imageCommentPayload,
|
|
34
|
-
files: [],
|
|
35
|
-
commentChildren: [],
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const updateTextMentionCommentResponse = {
|
|
40
|
-
data: {
|
|
41
|
-
...textCommentMentionPayload,
|
|
42
|
-
files: [],
|
|
43
|
-
commentChildren: [],
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const updateTextImageCommentResponse = {
|
|
48
|
-
data: {
|
|
49
|
-
...textImageCommentPayload,
|
|
50
|
-
files: [],
|
|
51
|
-
commentChildren: [],
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const textCommentRequestPayload: Parameters<typeof createComment>[0] = {
|
|
56
|
-
referenceId: post11.postId,
|
|
57
|
-
referenceType: 'post',
|
|
58
|
-
data: {
|
|
59
|
-
text: 'test',
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const textCommentWithMentionRequestPayload: Parameters<typeof createComment>[0] = {
|
|
64
|
-
...textCommentRequestPayload,
|
|
65
|
-
mentionees: [
|
|
66
|
-
{
|
|
67
|
-
type: 'user',
|
|
68
|
-
userIds: [user11._id, user12._id],
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const textImageCommentRequestPayload: Parameters<typeof createComment>[0] = {
|
|
74
|
-
...textCommentRequestPayload,
|
|
75
|
-
attachments: [
|
|
76
|
-
{
|
|
77
|
-
type: 'image',
|
|
78
|
-
fileId: file11.fileId,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const imageCommentRequestPayload: Parameters<typeof createComment>[0] = {
|
|
84
|
-
referenceId: post11.postId,
|
|
85
|
-
referenceType: 'post',
|
|
86
|
-
attachments: [
|
|
87
|
-
{
|
|
88
|
-
type: 'image',
|
|
89
|
-
fileId: file11.fileId,
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
};
|
|
93
|
-
|
|
94
23
|
describe('updateComment', () => {
|
|
95
24
|
beforeAll(connectClient);
|
|
96
25
|
afterAll(disconnectClient);
|
|
@@ -100,7 +29,7 @@ describe('updateComment', () => {
|
|
|
100
29
|
{
|
|
101
30
|
// integration_test_id: 1f0c74da-863e-44eb-acf1-3de57b1a0e79
|
|
102
31
|
title: 'update comment with valid data and return a new data',
|
|
103
|
-
mockRequest:
|
|
32
|
+
mockRequest: textCommentResponse,
|
|
104
33
|
mockFunction: textCommentRequestPayload,
|
|
105
34
|
expectResult: comment11,
|
|
106
35
|
extraCase: [],
|
|
@@ -108,7 +37,7 @@ describe('updateComment', () => {
|
|
|
108
37
|
{
|
|
109
38
|
// integration_test_id: 72550ea2-2943-4708-bc36-dd2b4fcf44b7
|
|
110
39
|
title: 'update text comment with mention and returns the new valid comment',
|
|
111
|
-
mockRequest:
|
|
40
|
+
mockRequest: textMentionCommentResponse,
|
|
112
41
|
mockFunction: textCommentWithMentionRequestPayload,
|
|
113
42
|
expectResult: textMentionComment11,
|
|
114
43
|
extraCase: [],
|
|
@@ -116,7 +45,7 @@ describe('updateComment', () => {
|
|
|
116
45
|
{
|
|
117
46
|
// integration_test_id: 9df2ff6c-81b7-4bdd-bcd2-33d9752735ed
|
|
118
47
|
title: 'update an image + text comment and returns the new valid comment',
|
|
119
|
-
mockRequest:
|
|
48
|
+
mockRequest: textImageCommentResponse,
|
|
120
49
|
mockFunction: textImageCommentRequestPayload,
|
|
121
50
|
expectResult: textImageComment11,
|
|
122
51
|
extraCase: [],
|
|
@@ -124,7 +53,7 @@ describe('updateComment', () => {
|
|
|
124
53
|
{
|
|
125
54
|
// integration_test_id: 75c77684-09f3-442e-8089-6d37e2182a65
|
|
126
55
|
title: 'add image to existing comment and returns the new valid comment',
|
|
127
|
-
mockRequest:
|
|
56
|
+
mockRequest: textImageCommentResponse,
|
|
128
57
|
mockFunction: textImageCommentRequestPayload,
|
|
129
58
|
expectResult: textImageComment11,
|
|
130
59
|
extraCase: [],
|
|
@@ -132,7 +61,7 @@ describe('updateComment', () => {
|
|
|
132
61
|
{
|
|
133
62
|
// integration_test_id: b50d7783-ab5e-4473-be3b-08ffe8b5142a
|
|
134
63
|
title: 'remove image from existing comment and returns the new valid comment',
|
|
135
|
-
mockRequest:
|
|
64
|
+
mockRequest: textCommentResponse,
|
|
136
65
|
mockFunction: textCommentRequestPayload,
|
|
137
66
|
expectResult: comment11,
|
|
138
67
|
extraCase: [{ attachments: [] }],
|
|
@@ -140,7 +69,7 @@ describe('updateComment', () => {
|
|
|
140
69
|
{
|
|
141
70
|
// integration_test_id: f31daa63-7214-400a-a7a1-d9b00d37137e
|
|
142
71
|
title: 'remove text from existing media comment and returns the new valid comment',
|
|
143
|
-
mockRequest:
|
|
72
|
+
mockRequest: imageCommentResponse,
|
|
144
73
|
mockFunction: imageCommentRequestPayload,
|
|
145
74
|
expectResult: imageComment11,
|
|
146
75
|
extraCase: [{ data: { text: '' } }],
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
2
|
import { getResolver } from '~/core/model';
|
|
3
3
|
import { getActiveClient } from '~/client/api';
|
|
4
|
-
import {
|
|
4
|
+
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
5
|
+
|
|
5
6
|
import {
|
|
6
7
|
createQuery,
|
|
7
|
-
runQuery,
|
|
8
|
-
queryOptions,
|
|
9
8
|
filterByPropEquality,
|
|
9
|
+
queryOptions,
|
|
10
|
+
runQuery,
|
|
10
11
|
sortByFirstCreated,
|
|
11
12
|
sortByLastCreated,
|
|
12
13
|
} from '~/core/query';
|
|
@@ -16,14 +17,15 @@ import {
|
|
|
16
17
|
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
17
18
|
} from '~/utils/constants';
|
|
18
19
|
|
|
20
|
+
import { CACHE_SHORTEN_LIFESPAN } from '~/cache/utils';
|
|
19
21
|
import {
|
|
20
22
|
onCommentCreated,
|
|
21
|
-
onCommentUpdated,
|
|
22
23
|
onCommentDeleted,
|
|
23
24
|
onCommentFlagged,
|
|
24
|
-
onCommentUnflagged,
|
|
25
25
|
onCommentReactionAdded,
|
|
26
26
|
onCommentReactionRemoved,
|
|
27
|
+
onCommentUnflagged,
|
|
28
|
+
onCommentUpdated,
|
|
27
29
|
} from '../events';
|
|
28
30
|
import { queryComments } from '../api';
|
|
29
31
|
|
|
@@ -80,7 +82,9 @@ export const liveComments = (
|
|
|
80
82
|
.filter(Boolean)
|
|
81
83
|
.map(({ data }) => data) ?? [];
|
|
82
84
|
|
|
83
|
-
|
|
85
|
+
if (params.includeDeleted === false) {
|
|
86
|
+
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
87
|
+
}
|
|
84
88
|
|
|
85
89
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
86
90
|
|
|
@@ -149,7 +153,7 @@ export const liveComments = (
|
|
|
149
153
|
|
|
150
154
|
responder(data);
|
|
151
155
|
},
|
|
152
|
-
queryOptions(policy),
|
|
156
|
+
queryOptions(policy, CACHE_SHORTEN_LIFESPAN),
|
|
153
157
|
);
|
|
154
158
|
};
|
|
155
159
|
|
|
@@ -168,5 +172,6 @@ export const liveComments = (
|
|
|
168
172
|
return () => {
|
|
169
173
|
log(`liveComments(tmpid: ${timestamp}) > dispose`);
|
|
170
174
|
disposers.forEach(fn => fn());
|
|
175
|
+
dropFromCache(cacheKey);
|
|
171
176
|
};
|
|
172
177
|
};
|
|
@@ -33,7 +33,7 @@ export const queryCommunities = async (
|
|
|
33
33
|
|
|
34
34
|
// safe decapsulation
|
|
35
35
|
const { page, ...params } = query ?? {};
|
|
36
|
-
const { displayName, membership, ...restParams } = params ?? {};
|
|
36
|
+
const { displayName, membership, includeDeleted, ...restParams } = params ?? {};
|
|
37
37
|
|
|
38
38
|
// API-FIX: parameters should be querystring.
|
|
39
39
|
// API-FIX: backend doesnt answer Amity.Response
|
|
@@ -43,6 +43,7 @@ export const queryCommunities = async (
|
|
|
43
43
|
{
|
|
44
44
|
params: {
|
|
45
45
|
...restParams,
|
|
46
|
+
isDeleted: includeDeleted === false ? false : undefined,
|
|
46
47
|
keyword: displayName,
|
|
47
48
|
filter: membership,
|
|
48
49
|
options: {
|
|
@@ -68,6 +68,36 @@ describe('queryCommunities', () => {
|
|
|
68
68
|
|
|
69
69
|
await expect(queryCommunities(queryCriteria)).rejects.toThrow('error');
|
|
70
70
|
});
|
|
71
|
+
|
|
72
|
+
test('it should set isDeleted to undefined if includeDeleted is true', async () => {
|
|
73
|
+
const mockFn = jest.fn();
|
|
74
|
+
client.http.get = mockFn.mockResolvedValue(resolvedGetValue);
|
|
75
|
+
|
|
76
|
+
await queryCommunities({ ...queryCriteriaWithoutPage, includeDeleted: true });
|
|
77
|
+
|
|
78
|
+
expect(mockFn.mock.lastCall).toHaveLength(2);
|
|
79
|
+
expect(mockFn.mock.lastCall[1].params.isDeleted).toBeUndefined();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('it should set isDeleted to false if includeDeleted is false', async () => {
|
|
83
|
+
const mockFn = jest.fn();
|
|
84
|
+
client.http.get = mockFn.mockResolvedValue(resolvedGetValue);
|
|
85
|
+
|
|
86
|
+
await queryCommunities({ ...queryCriteriaWithoutPage, includeDeleted: false });
|
|
87
|
+
|
|
88
|
+
expect(mockFn.mock.lastCall).toHaveLength(2);
|
|
89
|
+
expect(mockFn.mock.lastCall[1].params.isDeleted).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('it should set isDeleted to undefined if includeDeleted is undefined', async () => {
|
|
93
|
+
const mockFn = jest.fn();
|
|
94
|
+
client.http.get = mockFn.mockResolvedValue(resolvedGetValue);
|
|
95
|
+
|
|
96
|
+
await queryCommunities(queryCriteriaWithoutPage);
|
|
97
|
+
|
|
98
|
+
expect(mockFn.mock.lastCall).toHaveLength(2);
|
|
99
|
+
expect(mockFn.mock.lastCall[1].params.isDeleted).toBeUndefined();
|
|
100
|
+
});
|
|
71
101
|
});
|
|
72
102
|
|
|
73
103
|
describe.skip('queryCommunities.locally', () => {
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
2
|
import { getResolver } from '~/core/model';
|
|
3
|
-
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
4
4
|
import { getActiveClient } from '~/client/api';
|
|
5
5
|
import {
|
|
6
6
|
createQuery,
|
|
7
|
-
runQuery,
|
|
8
|
-
queryOptions,
|
|
9
7
|
filterByPropEquality,
|
|
10
|
-
|
|
8
|
+
queryOptions,
|
|
9
|
+
runQuery,
|
|
11
10
|
sortByDisplayName,
|
|
12
11
|
sortByFirstCreated,
|
|
12
|
+
sortByLastCreated,
|
|
13
13
|
} from '~/core/query';
|
|
14
14
|
import {
|
|
15
15
|
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
16
16
|
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
17
17
|
ENABLE_CACHE_MESSAGE,
|
|
18
18
|
} from '~/utils/constants';
|
|
19
|
+
|
|
20
|
+
import { CACHE_SHORTEN_LIFESPAN } from '~/cache/utils';
|
|
19
21
|
import {
|
|
20
22
|
onCommunityCreated,
|
|
21
23
|
onCommunityDeleted,
|
|
22
|
-
onCommunityUpdated,
|
|
23
24
|
onCommunityJoined,
|
|
24
25
|
onCommunityLeft,
|
|
26
|
+
onCommunityUpdated,
|
|
25
27
|
onCommunityUserChanged,
|
|
26
28
|
} from '../events';
|
|
27
29
|
import { queryCommunities } from '../api';
|
|
@@ -73,9 +75,12 @@ export const liveCommunities = (
|
|
|
73
75
|
.filter(Boolean)
|
|
74
76
|
.map(({ data }) => data) ?? [];
|
|
75
77
|
|
|
76
|
-
communities = filterByPropEquality(communities, 'isDeleted', params.isDeleted);
|
|
77
78
|
communities = filterByPropEquality(communities, 'displayName', params.displayName);
|
|
78
79
|
|
|
80
|
+
if (params.includeDeleted === false) {
|
|
81
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
82
|
+
}
|
|
83
|
+
|
|
79
84
|
if (params.categoryId) {
|
|
80
85
|
communities = communities.filter(c => c.categoryIds?.includes(params.categoryId!));
|
|
81
86
|
}
|
|
@@ -166,7 +171,7 @@ export const liveCommunities = (
|
|
|
166
171
|
|
|
167
172
|
responder(data);
|
|
168
173
|
},
|
|
169
|
-
queryOptions(policy),
|
|
174
|
+
queryOptions(policy, CACHE_SHORTEN_LIFESPAN),
|
|
170
175
|
);
|
|
171
176
|
};
|
|
172
177
|
|
|
@@ -184,5 +189,6 @@ export const liveCommunities = (
|
|
|
184
189
|
return () => {
|
|
185
190
|
log(`liveCommunities(tmpid: ${timestamp}) > dispose`);
|
|
186
191
|
disposers.forEach(fn => fn());
|
|
192
|
+
dropFromCache(cacheKey);
|
|
187
193
|
};
|
|
188
194
|
};
|
|
@@ -85,7 +85,7 @@ describe('liveCommunities', () => {
|
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
const filters: [string, Amity.CommunityLiveCollection, Amity.Community[]][] = [
|
|
88
|
-
['deleted', {
|
|
88
|
+
['not deleted', { includeDeleted: false }, [community2]],
|
|
89
89
|
['categoryId', { categoryId: 'test-category-id' }, [community1]],
|
|
90
90
|
['displayName', { displayName: 'community 1' }, [community1]],
|
|
91
91
|
['tagged', { tags: ['test-community-tag'] }, [community1]],
|
|
@@ -200,7 +200,7 @@ describe('liveCommunities', () => {
|
|
|
200
200
|
const callback = jest.fn();
|
|
201
201
|
client.http.get = jest.fn().mockResolvedValue(communityQueryResponse);
|
|
202
202
|
|
|
203
|
-
liveCommunities({
|
|
203
|
+
liveCommunities({ includeDeleted: false }, callback);
|
|
204
204
|
await pause();
|
|
205
205
|
|
|
206
206
|
client.emitter.emit(event, communityPayload);
|
|
@@ -31,6 +31,7 @@ const idResolvers: Resolvers = {
|
|
|
31
31
|
stream: ({ streamId }) => streamId,
|
|
32
32
|
|
|
33
33
|
follow: ({ from, to }) => `${from}#${to}`,
|
|
34
|
+
followInfo: ({ userId }) => userId,
|
|
34
35
|
followCount: ({ userId }) => userId,
|
|
35
36
|
|
|
36
37
|
feed: ({ targetId, feedId }) => `${targetId}#${feedId}`,
|
|
@@ -36,8 +36,9 @@ const CRITERIAS: Criterias = {
|
|
|
36
36
|
reaction: ['reactionId'],
|
|
37
37
|
stream: ['streamId'],
|
|
38
38
|
follow: ['from', 'to'],
|
|
39
|
-
followCount: ['userId', 'followerCount'],
|
|
40
39
|
feed: ['feedId', 'feedType'],
|
|
40
|
+
followInfo: ['userId', 'status'],
|
|
41
|
+
followCount: ['userId', 'followerCount'],
|
|
41
42
|
};
|
|
42
43
|
|
|
43
44
|
/** @hidden */
|