@amityco/ts-sdk 0.0.1-beta.38 → 0.0.1-beta.39
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 +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +2 -2
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +1 -2
- package/dist/@types/domains/feed.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/user.d.ts +8 -0
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/channel/observers/liveChannels.d.ts.map +1 -1
- package/dist/client/api/connectClient.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.map +1 -1
- package/dist/core/query/filtering.d.ts +10 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/core/query/paging.d.ts +2 -2
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/query/tests/paging.test.d.ts +2 -0
- package/dist/core/query/tests/paging.test.d.ts.map +1 -0
- package/dist/index.cjs.js +180 -71
- package/dist/index.esm.js +178 -71
- package/dist/index.umd.js +4 -4
- package/dist/message/api/queryMessages.d.ts +2 -2
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/post/observers/livePosts.d.ts +2 -2
- package/dist/post/observers/livePosts.d.ts.map +1 -1
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/dist/report/api/tests/createReport.test.d.ts +2 -0
- package/dist/report/api/tests/createReport.test.d.ts.map +1 -0
- package/dist/report/api/tests/deleteReport.test.d.ts +2 -0
- package/dist/report/api/tests/deleteReport.test.d.ts.map +1 -0
- package/dist/user/api/queryUsers.d.ts +1 -6
- package/dist/user/api/queryUsers.d.ts.map +1 -1
- package/dist/user/observers/index.d.ts +1 -0
- package/dist/user/observers/index.d.ts.map +1 -1
- package/dist/user/observers/liveUsers.d.ts +18 -0
- package/dist/user/observers/liveUsers.d.ts.map +1 -0
- package/dist/user/observers/tests/liveUsers.test.d.ts +2 -0
- package/dist/user/observers/tests/liveUsers.test.d.ts.map +1 -0
- package/dist/utils/liveObject.d.ts +1 -1
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/feed.d.ts +21 -0
- package/dist/utils/tests/dummy/feed.d.ts.map +1 -0
- 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 +9 -0
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/dist/utils/tests/dummy/user.d.ts +63 -0
- package/dist/utils/tests/dummy/user.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/model.ts +4 -0
- package/src/@types/domains/channel.ts +2 -2
- package/src/@types/domains/feed.ts +1 -3
- package/src/@types/domains/message.ts +4 -1
- package/src/@types/domains/post.ts +1 -1
- package/src/@types/domains/user.ts +14 -0
- package/src/cache/api/tests/ingestInCache.test.ts +2 -0
- package/src/channel/observers/liveChannels.ts +29 -24
- package/src/client/api/connectClient.ts +0 -2
- package/src/core/model/idResolvers.ts +2 -0
- package/src/core/model/identifyModel.ts +1 -0
- package/src/core/model/index.ts +2 -0
- package/src/core/query/filtering.ts +33 -3
- package/src/core/query/paging.ts +5 -4
- package/src/core/query/tests/paging.test.ts +66 -0
- package/src/message/api/queryMessages.ts +7 -7
- package/src/message/api/tests/queryMessages.test.ts +6 -6
- package/src/message/tests/observers/liveMessages.test.ts +4 -4
- package/src/post/observers/livePosts.ts +14 -22
- package/src/post/observers/tests/livePosts.test.ts +65 -8
- package/src/report/api/createReport.ts +1 -6
- package/src/report/api/deleteReport.ts +2 -6
- package/src/report/api/tests/createReport.test.ts +93 -0
- package/src/report/api/tests/deleteReport.test.ts +93 -0
- package/src/user/api/queryUsers.ts +1 -6
- package/src/user/observers/index.ts +1 -0
- package/src/user/observers/liveUsers.ts +162 -0
- package/src/user/observers/tests/liveUsers.test.ts +202 -0
- package/src/utils/tests/dummy/channel.ts +1 -0
- package/src/utils/tests/dummy/feed.ts +13 -0
- package/src/utils/tests/dummy/index.ts +2 -0
- package/src/utils/tests/dummy/post.ts +6 -2
- package/src/utils/tests/dummy/user.ts +36 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { toPage, isSkip, isAfterBefore } from '../paging';
|
|
2
|
+
|
|
3
|
+
describe('paging', () => {
|
|
4
|
+
const skipToken = 'eyJza2lwIjoiMTAiLCJsaW1pdCI6IjEwIn0=';
|
|
5
|
+
const afterToken = 'eyJhZnRlciI6InRlc3QtdG9rZW4iLCJsaW1pdCI6Mn0=';
|
|
6
|
+
const beforeToken =
|
|
7
|
+
'eyJiZWZvcmUiOiI2M2Y0NzFjZmI2MTQzOTExZjFkMWUwNmYiLCJsaW1pdCI6Miwic2VnbWVudCI6Nn0=';
|
|
8
|
+
|
|
9
|
+
describe('toPage', () => {
|
|
10
|
+
test('it should return expected response for skip paging token', () => {
|
|
11
|
+
const expected = { after: '10', limit: '10' };
|
|
12
|
+
|
|
13
|
+
expect(toPage(skipToken)).toStrictEqual(expected);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('it should return appropriate response for "before" paging token', () => {
|
|
17
|
+
const expected = {
|
|
18
|
+
before: '63f471cfb6143911f1d1e06f',
|
|
19
|
+
limit: undefined,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
expect(toPage(beforeToken)).toStrictEqual(expected);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('it should return appropriate response for "after" paging token', () => {
|
|
26
|
+
const expected = {
|
|
27
|
+
after: 'test-token',
|
|
28
|
+
limit: undefined,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
expect(toPage(afterToken)).toStrictEqual(expected);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('isSkip', () => {
|
|
36
|
+
test('it should return true if skip prop in object', () => {
|
|
37
|
+
expect(isSkip({ skip: 10 })).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('it should return true if skip prop not in object', () => {
|
|
41
|
+
expect(isSkip({ limit: 10 })).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('isAfterBefore', () => {
|
|
46
|
+
test('it should return true if after prop in object', () => {
|
|
47
|
+
expect(isAfterBefore({ after: '' })).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('it should return true if before prop in object', () => {
|
|
51
|
+
expect(isAfterBefore({ before: '' })).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('it should return true if first prop in object', () => {
|
|
55
|
+
expect(isAfterBefore({ first: '' })).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('it should return true if last prop in object', () => {
|
|
59
|
+
expect(isAfterBefore({ last: '' })).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('it should return false if skip prop in object', () => {
|
|
63
|
+
expect(isAfterBefore({ skip: '' })).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { fireEvent } from '~/core/events';
|
|
4
|
-
import {
|
|
4
|
+
import { toPageRaw } from '~/core/query';
|
|
5
5
|
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
6
6
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
7
7
|
import { getResolver } from '~/core/model';
|
|
@@ -23,7 +23,7 @@ import { convertQueryParams, convertResponseFromRaw } from '../utils';
|
|
|
23
23
|
*/
|
|
24
24
|
export const queryMessages = async (
|
|
25
25
|
query: Amity.QueryMessages,
|
|
26
|
-
): Promise<Amity.Cached<Amity.Paged<Amity.Message
|
|
26
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.Message, Amity.Page<string>>>> => {
|
|
27
27
|
const client = getActiveClient();
|
|
28
28
|
client.log('message/queryMessages', query);
|
|
29
29
|
|
|
@@ -53,8 +53,8 @@ export const queryMessages = async (
|
|
|
53
53
|
|
|
54
54
|
fireEvent('local.message.fetched', { messages });
|
|
55
55
|
|
|
56
|
-
const nextPage =
|
|
57
|
-
const prevPage =
|
|
56
|
+
const nextPage = toPageRaw(paging.next);
|
|
57
|
+
const prevPage = toPageRaw(paging.previous);
|
|
58
58
|
|
|
59
59
|
return { data: messages, cachedAt, prevPage, nextPage };
|
|
60
60
|
};
|
|
@@ -74,7 +74,7 @@ export const queryMessages = async (
|
|
|
74
74
|
*/
|
|
75
75
|
queryMessages.locally = (
|
|
76
76
|
query: Parameters<typeof queryMessages>[0],
|
|
77
|
-
): Amity.Cached<Amity.Paged<Amity.Message
|
|
77
|
+
): Amity.Cached<Amity.Paged<Amity.Message, Amity.Page<string>>> | undefined => {
|
|
78
78
|
const client = getActiveClient();
|
|
79
79
|
client.log('message/queryMessages.locally', query);
|
|
80
80
|
|
|
@@ -94,8 +94,8 @@ queryMessages.locally = (
|
|
|
94
94
|
.filter(Boolean)
|
|
95
95
|
.map(({ data }) => data);
|
|
96
96
|
|
|
97
|
-
const prevPage =
|
|
98
|
-
const nextPage =
|
|
97
|
+
const prevPage = toPageRaw(data?.paging.previous);
|
|
98
|
+
const nextPage = toPageRaw(data?.paging.next);
|
|
99
99
|
|
|
100
100
|
return messages.length === data?.messages?.length
|
|
101
101
|
? { data: messages, cachedAt, prevPage, nextPage }
|
|
@@ -14,9 +14,9 @@ const messageIds = messagesToQuery.map(x => x.messageId);
|
|
|
14
14
|
const queryCriteriaWithoutPage = { subChannelId: messagesToQuery[0].subChannelId };
|
|
15
15
|
const queryCriteria = { ...queryCriteriaWithoutPage, page: { limit: 10 } };
|
|
16
16
|
const paging = {
|
|
17
|
-
|
|
18
|
-
next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
17
|
+
next: 'eyJsaW1pdCI6MiwiYmVmb3JlIjo2MzQ3MTYxNDM5MTExMTAwMDAwMH0',
|
|
19
18
|
};
|
|
19
|
+
const nextPage = { before: 63471614391111000000, limit: 2 };
|
|
20
20
|
|
|
21
21
|
const getResolvedMessageValue = () => ({
|
|
22
22
|
data: {
|
|
@@ -34,8 +34,8 @@ describe('queryMessages', () => {
|
|
|
34
34
|
await expect(queryMessages(queryCriteria)).resolves.toEqual(
|
|
35
35
|
expect.objectContaining({
|
|
36
36
|
data: messagesToQuery,
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
nextPage,
|
|
38
|
+
prevPage: undefined,
|
|
39
39
|
}),
|
|
40
40
|
);
|
|
41
41
|
});
|
|
@@ -91,8 +91,8 @@ describe('queryMessages.locally', () => {
|
|
|
91
91
|
expect(queryMessages.locally(queryCriteria)).toEqual(
|
|
92
92
|
expect.objectContaining({
|
|
93
93
|
data: messagesToQuery,
|
|
94
|
-
prevPage:
|
|
95
|
-
nextPage
|
|
94
|
+
prevPage: undefined,
|
|
95
|
+
nextPage,
|
|
96
96
|
}),
|
|
97
97
|
);
|
|
98
98
|
});
|
|
@@ -182,8 +182,8 @@ describe('liveMessages', () => {
|
|
|
182
182
|
data: {
|
|
183
183
|
messages: returnValue,
|
|
184
184
|
paging: {
|
|
185
|
-
previous: '
|
|
186
|
-
next: '
|
|
185
|
+
previous: 'eyJsaW1pdCI6MiwiYmVmb3JlIjo2MzQ3MTYxNDM5MTExMTAwMDAwMH0',
|
|
186
|
+
next: 'eyJsaW1pdCI6MiwiYmVmb3JlIjo2MzQ3MTYxNDM5MTExMTAwMDAwMH0',
|
|
187
187
|
},
|
|
188
188
|
},
|
|
189
189
|
})
|
|
@@ -191,8 +191,8 @@ describe('liveMessages', () => {
|
|
|
191
191
|
data: {
|
|
192
192
|
messages: returnValue2,
|
|
193
193
|
paging: {
|
|
194
|
-
previous: '
|
|
195
|
-
next: '
|
|
194
|
+
previous: 'eyJsaW1pdCI6MiwiYmVmb3JlIjo2MzQ3MTYxNDM5MTExMTAwMDAwMH0',
|
|
195
|
+
next: 'eyJsaW1pdCI6MiwiYmVmb3JlIjo2MzQ3MTYxNDM5MTExMTAwMDAwMH0',
|
|
196
196
|
},
|
|
197
197
|
},
|
|
198
198
|
});
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
runQuery,
|
|
8
8
|
queryOptions,
|
|
9
9
|
filterByPropEquality,
|
|
10
|
+
filterByFeedType,
|
|
10
11
|
sortByFirstCreated,
|
|
11
12
|
sortByLastCreated,
|
|
12
13
|
} from '~/core/query';
|
|
@@ -43,8 +44,8 @@ import { queryPosts } from '../api';
|
|
|
43
44
|
*
|
|
44
45
|
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
45
46
|
*
|
|
46
|
-
* @param targetType the type of the target
|
|
47
|
-
* @param targetId the ID of the target
|
|
47
|
+
* @param param.targetType the type of the target
|
|
48
|
+
* @param param.targetId the ID of the target
|
|
48
49
|
* @param callback the function to call when new data are available
|
|
49
50
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
50
51
|
*
|
|
@@ -86,13 +87,16 @@ export const livePosts = (
|
|
|
86
87
|
posts = filterByPropEquality(posts, 'isDeleted', params.isDeleted);
|
|
87
88
|
|
|
88
89
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
89
|
-
|
|
90
90
|
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
91
91
|
|
|
92
92
|
if (params.tags) {
|
|
93
93
|
posts = posts.filter(p => p.tags?.some(t => params.tags?.includes(t)));
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
if (params.targetType === 'community' && params.feedType) {
|
|
97
|
+
posts = filterByFeedType(posts, params.feedType);
|
|
98
|
+
}
|
|
99
|
+
|
|
96
100
|
callback({
|
|
97
101
|
onNextPage: onFetch,
|
|
98
102
|
data: posts,
|
|
@@ -108,27 +112,15 @@ export const livePosts = (
|
|
|
108
112
|
if (params.targetId !== post.targetId || params.targetType !== post.targetType || !collection)
|
|
109
113
|
return;
|
|
110
114
|
|
|
111
|
-
if (['onCreate', 'onApproved'].includes(action)) {
|
|
112
|
-
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
113
|
-
} else if (['onDelete', 'onDeclined'].includes(action)) {
|
|
114
|
-
collection.data = collection.data.filter(p => p !== post.postId);
|
|
115
|
-
|
|
116
|
-
/*
|
|
117
|
-
* if isDeleted is true, collection should add deleted items to the
|
|
118
|
-
* begining of the collection
|
|
119
|
-
*/
|
|
120
|
-
if (params.isDeleted) collection.data.unshift(post.postId);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
115
|
/*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* The responder should pull the feed from cache once available and should
|
|
127
|
-
* match the collection to feedType param
|
|
128
|
-
* https://ekoapp.atlassian.net/browse/ASC-9382
|
|
116
|
+
* This is not ideal, but currently this is the only way to update the
|
|
117
|
+
* collection on post declined
|
|
129
118
|
*/
|
|
130
|
-
if (
|
|
131
|
-
collection.data = collection.data.filter(
|
|
119
|
+
if (action === 'onDeclined') {
|
|
120
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
121
|
+
} else {
|
|
122
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
123
|
+
}
|
|
132
124
|
|
|
133
125
|
pushToCache(cacheKey, collection);
|
|
134
126
|
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
connectClient,
|
|
7
7
|
disconnectClient,
|
|
8
8
|
post11,
|
|
9
|
+
post14,
|
|
9
10
|
postQueryResponse,
|
|
10
11
|
postQueryResponsePage2,
|
|
11
12
|
} from '~/utils/tests';
|
|
@@ -133,23 +134,30 @@ describe('livePosts', () => {
|
|
|
133
134
|
expect(callback).toHaveBeenNthCalledWith(4, expect.objectContaining(snapshot));
|
|
134
135
|
});
|
|
135
136
|
|
|
136
|
-
const events: [string, keyof Amity.Events, Amity.Post][] = [
|
|
137
|
+
const events: [string, keyof Amity.Events, Amity.Post, Amity.PostLiveCollection][] = [
|
|
137
138
|
[
|
|
138
139
|
'it should add new post to collection onCreate',
|
|
139
140
|
'post.created',
|
|
140
141
|
{ ...post11, postId: 'new-post-id' },
|
|
142
|
+
params,
|
|
141
143
|
],
|
|
142
|
-
['it should edit post in collection onUpdate', 'post.updated', post11],
|
|
144
|
+
['it should edit post in collection onUpdate', 'post.updated', post11, params],
|
|
143
145
|
[
|
|
144
146
|
'it should update post in collection onApproved',
|
|
145
147
|
'post.approved',
|
|
146
148
|
{ ...post11, postId: 'approved-post-id' },
|
|
149
|
+
params,
|
|
147
150
|
],
|
|
148
|
-
[
|
|
149
|
-
|
|
151
|
+
[
|
|
152
|
+
'it should remove post in collection onDelete',
|
|
153
|
+
'post.deleted',
|
|
154
|
+
{ ...post11, isDeleted: true },
|
|
155
|
+
{ ...params, isDeleted: false },
|
|
156
|
+
],
|
|
157
|
+
['it should remove post in collection onDeclined', 'post.declined', post11, params],
|
|
150
158
|
];
|
|
151
159
|
|
|
152
|
-
test.each(events)('%s', async (test, event, post) => {
|
|
160
|
+
test.each(events)('%s', async (test, event, post, params) => {
|
|
153
161
|
const snapshot = getSnapshot();
|
|
154
162
|
|
|
155
163
|
const callback = jest.fn();
|
|
@@ -165,7 +173,7 @@ describe('livePosts', () => {
|
|
|
165
173
|
});
|
|
166
174
|
|
|
167
175
|
const payload = postQueryResponse.data;
|
|
168
|
-
const deletePayload = payload.posts.filter(
|
|
176
|
+
const deletePayload = payload.posts.filter(p => p.postId !== post.postId);
|
|
169
177
|
|
|
170
178
|
snapshot.loading = false;
|
|
171
179
|
// get data based on event
|
|
@@ -277,11 +285,51 @@ describe('livePosts', () => {
|
|
|
277
285
|
});
|
|
278
286
|
|
|
279
287
|
test('it should remove approved post when feedtype reviewing', async () => {
|
|
280
|
-
const
|
|
288
|
+
const feedId = 'publishedFeed';
|
|
289
|
+
const approvedPost = { ...post14, feedId };
|
|
290
|
+
|
|
291
|
+
const callback = jest.fn();
|
|
292
|
+
client.http.get = jest.fn().mockResolvedValue(postQueryResponsePage2);
|
|
293
|
+
|
|
294
|
+
livePosts({ ...params, targetType: 'community', feedType: 'reviewing' }, callback);
|
|
295
|
+
|
|
296
|
+
await pause();
|
|
297
|
+
const payload = postQueryResponsePage2.data.posts;
|
|
298
|
+
const snapshot = getSnapshot();
|
|
299
|
+
|
|
300
|
+
snapshot.data = payload;
|
|
301
|
+
snapshot.loading = false;
|
|
302
|
+
|
|
303
|
+
expect(callback).toHaveBeenNthCalledWith(2, expect.objectContaining(snapshot));
|
|
304
|
+
|
|
305
|
+
client.emitter.emit('post.approved', {
|
|
306
|
+
posts: [approvedPost],
|
|
307
|
+
feeds: [
|
|
308
|
+
{
|
|
309
|
+
...postQueryResponsePage2.data.feeds[0],
|
|
310
|
+
targetType: 'community',
|
|
311
|
+
feedId,
|
|
312
|
+
feedType: 'published',
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
snapshot.data = payload.filter(({ postId }) => postId !== approvedPost.postId);
|
|
318
|
+
|
|
319
|
+
expect(callback).toHaveBeenNthCalledWith(3, expect.objectContaining(snapshot));
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test('it should remove reviewing post when feedtype published', async () => {
|
|
323
|
+
const feedId = 'publishedFeed';
|
|
324
|
+
const approvedPost = { ...post14, feedId };
|
|
325
|
+
|
|
326
|
+
const approvedFeed = { ...postQueryResponsePage2.data.feeds[0], feedType: 'published' };
|
|
327
|
+
postQueryResponsePage2.data.feeds = [approvedFeed];
|
|
328
|
+
|
|
281
329
|
const callback = jest.fn();
|
|
282
330
|
client.http.get = jest.fn().mockResolvedValue(postQueryResponsePage2);
|
|
283
331
|
|
|
284
|
-
livePosts({ ...params, feedType: '
|
|
332
|
+
livePosts({ ...params, targetType: 'community', feedType: 'published' }, callback);
|
|
285
333
|
|
|
286
334
|
await pause();
|
|
287
335
|
const payload = postQueryResponsePage2.data.posts;
|
|
@@ -294,9 +342,18 @@ describe('livePosts', () => {
|
|
|
294
342
|
|
|
295
343
|
client.emitter.emit('post.approved', {
|
|
296
344
|
posts: [approvedPost],
|
|
345
|
+
feeds: [
|
|
346
|
+
{
|
|
347
|
+
...postQueryResponsePage2.data.feeds[0],
|
|
348
|
+
targetType: 'community',
|
|
349
|
+
feedId,
|
|
350
|
+
feedType: 'reviewing',
|
|
351
|
+
},
|
|
352
|
+
],
|
|
297
353
|
});
|
|
298
354
|
|
|
299
355
|
snapshot.data = payload.filter(({ postId }) => postId !== approvedPost.postId);
|
|
356
|
+
|
|
300
357
|
expect(callback).toHaveBeenNthCalledWith(3, expect.objectContaining(snapshot));
|
|
301
358
|
});
|
|
302
359
|
});
|
|
@@ -49,12 +49,7 @@ export const createReport = async (
|
|
|
49
49
|
referenceType === 'message' ? prepareMessagePayload(data as Amity.RawMessagePayload) : data,
|
|
50
50
|
);
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
fireEvent('message.flagged', data as Amity.RawMessagePayload);
|
|
54
|
-
} else {
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
fireEvent(`${referenceType}.flagged`, data);
|
|
57
|
-
}
|
|
52
|
+
fireEvent(`${referenceType}.flagged`, data);
|
|
58
53
|
|
|
59
54
|
return !!data;
|
|
60
55
|
};
|
|
@@ -49,12 +49,8 @@ export const deleteReport = async (
|
|
|
49
49
|
referenceType === 'message' ? prepareMessagePayload(data as Amity.RawMessagePayload) : data,
|
|
50
50
|
);
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} else {
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
fireEvent(`${referenceType}.unflagged`, data);
|
|
57
|
-
}
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
fireEvent(`${referenceType}.unflagged`, data);
|
|
58
54
|
|
|
59
55
|
return !!data;
|
|
60
56
|
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
flaggedUser,
|
|
7
|
+
flaggedUserQueryResponse,
|
|
8
|
+
} from '~/utils/tests';
|
|
9
|
+
import { ASCApiError } from '~/core/errors';
|
|
10
|
+
|
|
11
|
+
import { onUserFlagged } from '~/user/events';
|
|
12
|
+
|
|
13
|
+
import { createReport } from '..';
|
|
14
|
+
import REFERENCE_TYPES from '../../constants/referenceTypes';
|
|
15
|
+
|
|
16
|
+
describe('createReport', () => {
|
|
17
|
+
beforeAll(connectClient);
|
|
18
|
+
afterAll(disconnectClient);
|
|
19
|
+
|
|
20
|
+
// integration_test_id: ca4a760f-4342-4a99-9f3c-6c17cd205ca6
|
|
21
|
+
test('it should flag user with userId', async () => {
|
|
22
|
+
const expected = true;
|
|
23
|
+
client.http.post = jest.fn().mockResolvedValue(flaggedUserQueryResponse);
|
|
24
|
+
|
|
25
|
+
const received = await createReport('user', flaggedUser.userId);
|
|
26
|
+
|
|
27
|
+
expect(received).toBe(expected);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// integration_test_id: e8d0f02c-3558-488f-bdae-e70835d8cefb
|
|
31
|
+
test('it should throw error with 400400 when sending invalid userId', async () => {
|
|
32
|
+
client.http.post = jest
|
|
33
|
+
.fn()
|
|
34
|
+
.mockRejectedValueOnce(
|
|
35
|
+
new ASCApiError('unauthorized', Amity.ServerError.ITEM_NOT_FOUND, Amity.ErrorLevel.ERROR),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
await expect(createReport('user', flaggedUser.userId)).rejects.toThrow('400400');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('it should fire event for user', async () => {
|
|
42
|
+
let dispose;
|
|
43
|
+
const expected = flaggedUser;
|
|
44
|
+
|
|
45
|
+
client.http.post = jest.fn().mockResolvedValue(flaggedUserQueryResponse);
|
|
46
|
+
|
|
47
|
+
const callbackPromise = new Promise(resolve => {
|
|
48
|
+
dispose = onUserFlagged(resolve);
|
|
49
|
+
}).finally(dispose);
|
|
50
|
+
|
|
51
|
+
const recieved = await createReport('user', flaggedUser.userId);
|
|
52
|
+
|
|
53
|
+
expect(recieved).toBe(true);
|
|
54
|
+
await expect(callbackPromise).resolves.toEqual(expect.objectContaining(expected));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test.todo('it should fire event for flagging message');
|
|
58
|
+
test.todo('it should fire event for flagging post');
|
|
59
|
+
|
|
60
|
+
const tests: [keyof typeof REFERENCE_TYPES, string, string][] = [
|
|
61
|
+
['user', 'userId', `/api/v4/me/flags/${encodeURIComponent('userId')}`],
|
|
62
|
+
['post', 'postId', `/api/v3/posts/${encodeURIComponent('postId')}/flag`],
|
|
63
|
+
['message', 'messageId', `/api/v5/messages/${encodeURIComponent('messageId')}/flags`],
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
test.each(tests)(
|
|
67
|
+
'it should call the appropriate api for %s',
|
|
68
|
+
async (referenceType, referenceId, expected) => {
|
|
69
|
+
const apimock = jest.fn();
|
|
70
|
+
|
|
71
|
+
client.http.post = apimock.mockResolvedValue({ data: {} });
|
|
72
|
+
|
|
73
|
+
await createReport(referenceType, referenceId);
|
|
74
|
+
|
|
75
|
+
const received = apimock.mock.lastCall[0];
|
|
76
|
+
|
|
77
|
+
expect(received).toBe(expected);
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
test('it should add data to cache', async () => {
|
|
82
|
+
enableCache();
|
|
83
|
+
const expected = flaggedUser;
|
|
84
|
+
client.http.post = jest.fn().mockResolvedValue(flaggedUserQueryResponse);
|
|
85
|
+
|
|
86
|
+
await createReport('user', flaggedUser.userId);
|
|
87
|
+
const recieved = pullFromCache(['user', 'get', flaggedUser.userId]);
|
|
88
|
+
|
|
89
|
+
expect(recieved?.data).toBe(expected);
|
|
90
|
+
|
|
91
|
+
disableCache();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
flaggedUser as unflaggedUser,
|
|
7
|
+
flaggedUserQueryResponse as unflaggedUserQueryResponse,
|
|
8
|
+
} from '~/utils/tests';
|
|
9
|
+
import { ASCApiError } from '~/core/errors';
|
|
10
|
+
|
|
11
|
+
import { onUserUnflagged } from '~/user/events';
|
|
12
|
+
|
|
13
|
+
import { deleteReport } from '..';
|
|
14
|
+
import REFERENCE_TYPES from '../../constants/referenceTypes';
|
|
15
|
+
|
|
16
|
+
describe('deleteReport', () => {
|
|
17
|
+
beforeAll(connectClient);
|
|
18
|
+
afterAll(disconnectClient);
|
|
19
|
+
|
|
20
|
+
// integration_test_id: fddf1d63-98e2-4296-ab3a-4e2b55044f89
|
|
21
|
+
test('it should unflag user with userId', async () => {
|
|
22
|
+
const expected = true;
|
|
23
|
+
client.http.delete = jest.fn().mockResolvedValue(unflaggedUserQueryResponse);
|
|
24
|
+
|
|
25
|
+
const received = await deleteReport('user', unflaggedUser.userId);
|
|
26
|
+
|
|
27
|
+
expect(received).toBe(expected);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// integration_test_id: a95a0784-56ce-4b17-ac1b-0f1c50a361ef
|
|
31
|
+
test('it should throw error with 400400 when sending invalid userId', async () => {
|
|
32
|
+
client.http.delete = jest
|
|
33
|
+
.fn()
|
|
34
|
+
.mockRejectedValueOnce(
|
|
35
|
+
new ASCApiError('unauthorized', Amity.ServerError.ITEM_NOT_FOUND, Amity.ErrorLevel.ERROR),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
await expect(deleteReport('user', unflaggedUser.userId)).rejects.toThrow('400400');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('it should fire event for user', async () => {
|
|
42
|
+
let dispose;
|
|
43
|
+
const expected = unflaggedUser;
|
|
44
|
+
|
|
45
|
+
client.http.delete = jest.fn().mockResolvedValue(unflaggedUserQueryResponse);
|
|
46
|
+
|
|
47
|
+
const callbackPromise = new Promise(resolve => {
|
|
48
|
+
dispose = onUserUnflagged(resolve);
|
|
49
|
+
}).finally(dispose);
|
|
50
|
+
|
|
51
|
+
const recieved = await deleteReport('user', unflaggedUser.userId);
|
|
52
|
+
|
|
53
|
+
expect(recieved).toBe(true);
|
|
54
|
+
await expect(callbackPromise).resolves.toEqual(expect.objectContaining(expected));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test.todo('it should fire event for unflagging message');
|
|
58
|
+
test.todo('it should fire event for unflagging delete');
|
|
59
|
+
|
|
60
|
+
const tests: [keyof typeof REFERENCE_TYPES, string, string][] = [
|
|
61
|
+
['user', 'userId', `/api/v4/me/flags/${encodeURIComponent('userId')}`],
|
|
62
|
+
['post', 'postId', `/api/v3/posts/${encodeURIComponent('postId')}/unflag`],
|
|
63
|
+
['message', 'messageId', `/api/v5/messages/${encodeURIComponent('messageId')}/flags`],
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
test.each(tests)(
|
|
67
|
+
'it should call the appropriate api for %s',
|
|
68
|
+
async (referenceType, referenceId, expected) => {
|
|
69
|
+
const apimock = jest.fn();
|
|
70
|
+
|
|
71
|
+
client.http.delete = apimock.mockResolvedValue({ data: {} });
|
|
72
|
+
|
|
73
|
+
await deleteReport(referenceType, referenceId);
|
|
74
|
+
|
|
75
|
+
const received = apimock.mock.lastCall[0];
|
|
76
|
+
|
|
77
|
+
expect(received).toBe(expected);
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
test('it should add data to cache', async () => {
|
|
82
|
+
enableCache();
|
|
83
|
+
const expected = unflaggedUser;
|
|
84
|
+
client.http.delete = jest.fn().mockResolvedValue(unflaggedUserQueryResponse);
|
|
85
|
+
|
|
86
|
+
await deleteReport('user', unflaggedUser.userId);
|
|
87
|
+
const recieved = pullFromCache(['user', 'get', unflaggedUser.userId]);
|
|
88
|
+
|
|
89
|
+
expect(recieved?.data).toBe(expected);
|
|
90
|
+
|
|
91
|
+
disableCache();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -23,12 +23,7 @@ import { fireEvent } from '~/core/events';
|
|
|
23
23
|
* @async
|
|
24
24
|
*/
|
|
25
25
|
export const queryUsers = async (
|
|
26
|
-
query: {
|
|
27
|
-
displayName?: Amity.User['displayName'];
|
|
28
|
-
filter?: 'all' | 'flagged';
|
|
29
|
-
sortBy?: 'displayName' | 'firstCreated' | 'lastCreated';
|
|
30
|
-
page?: Amity.Page;
|
|
31
|
-
} = {},
|
|
26
|
+
query: Amity.QueryUsers = {},
|
|
32
27
|
): Promise<Amity.Cached<Amity.Paged<Amity.User>>> => {
|
|
33
28
|
const client = getActiveClient();
|
|
34
29
|
client.log('user/queryUsers', query);
|