@amityco/ts-sdk 6.3.1 → 6.3.2-de32ca2.0
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/domains/user.d.ts +1 -0
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/index.cjs.js +28 -2
- package/dist/index.esm.js +28 -2
- package/dist/index.umd.js +1 -1
- package/dist/userRepository/observers/index.d.ts +1 -0
- package/dist/userRepository/observers/index.d.ts.map +1 -1
- package/dist/userRepository/observers/searchUserByDisplayName.d.ts +19 -0
- package/dist/userRepository/observers/searchUserByDisplayName.d.ts.map +1 -0
- package/dist/userRepository/observers/tests/searchUserByDisplayName.test.d.ts +2 -0
- package/dist/userRepository/observers/tests/searchUserByDisplayName.test.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/domains/user.ts +2 -0
- package/src/userRepository/observers/getUsers.ts +1 -1
- package/src/userRepository/observers/index.ts +1 -0
- package/src/userRepository/observers/searchUserByDisplayName.ts +30 -0
- package/src/userRepository/observers/tests/searchUserByDisplayName.test.ts +113 -0
|
@@ -2,4 +2,5 @@ export { getUser } from './getUser';
|
|
|
2
2
|
export { getUsers } from './getUsers';
|
|
3
3
|
export { observeUser } from './observeUser';
|
|
4
4
|
export { getBlockedUsers } from './getBlockedUsers';
|
|
5
|
+
export { searchUserByDisplayName } from './searchUserByDisplayName';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/userRepository/observers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/userRepository/observers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
4
|
+
*
|
|
5
|
+
* let users = []
|
|
6
|
+
* const unsub = UserRepository.searchUserByDisplayName({}, response => merge(users, response.data))
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Observe all mutations on a list of {@link Amity.User}s
|
|
10
|
+
*
|
|
11
|
+
* @param params for searching users
|
|
12
|
+
* @param callback the function to call when new data are available
|
|
13
|
+
* @param config the configuration for the live collection
|
|
14
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the users
|
|
15
|
+
*
|
|
16
|
+
* @category Category Live Collection
|
|
17
|
+
*/
|
|
18
|
+
export declare const searchUserByDisplayName: (params: Amity.UserSearchLiveCollection, callback: Amity.LiveCollectionCallback<Amity.User>, config?: Amity.LiveCollectionConfig) => () => void;
|
|
19
|
+
//# sourceMappingURL=searchUserByDisplayName.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchUserByDisplayName.d.ts","sourceRoot":"","sources":["../../../src/userRepository/observers/searchUserByDisplayName.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,uBAAuB,WAC1B,MAAM,wBAAwB,YAC5B,MAAM,sBAAsB,CAAC,MAAM,IAAI,CAAC,WACzC,MAAM,oBAAoB,eAGpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchUserByDisplayName.test.d.ts","sourceRoot":"","sources":["../../../../src/userRepository/observers/tests/searchUserByDisplayName.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -34,6 +34,8 @@ declare global {
|
|
|
34
34
|
|
|
35
35
|
type UserLiveCollection = Amity.LiveCollectionParams<Omit<QueryUsers, 'page'>>;
|
|
36
36
|
|
|
37
|
+
type UserSearchLiveCollection = Amity.LiveCollectionParams<Omit<QueryUsers, 'sortBy'>>;
|
|
38
|
+
|
|
37
39
|
type UserLiveCollectionCache = Amity.LiveCollectionCache<
|
|
38
40
|
Amity.User['userId'],
|
|
39
41
|
Pick<QueryUsers, 'page'>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getUsers } from './getUsers';
|
|
2
|
+
|
|
3
|
+
/* begin_public_function
|
|
4
|
+
id: user.search
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
9
|
+
*
|
|
10
|
+
* let users = []
|
|
11
|
+
* const unsub = UserRepository.searchUserByDisplayName({}, response => merge(users, response.data))
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Observe all mutations on a list of {@link Amity.User}s
|
|
15
|
+
*
|
|
16
|
+
* @param params for searching users
|
|
17
|
+
* @param callback the function to call when new data are available
|
|
18
|
+
* @param config the configuration for the live collection
|
|
19
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the users
|
|
20
|
+
*
|
|
21
|
+
* @category Category Live Collection
|
|
22
|
+
*/
|
|
23
|
+
export const searchUserByDisplayName = (
|
|
24
|
+
params: Amity.UserSearchLiveCollection,
|
|
25
|
+
callback: Amity.LiveCollectionCallback<Amity.User>,
|
|
26
|
+
config?: Amity.LiveCollectionConfig,
|
|
27
|
+
) => {
|
|
28
|
+
return getUsers({ ...params, filter: 'all' }, callback, config);
|
|
29
|
+
};
|
|
30
|
+
/* end_public_function */
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { disableCache, enableCache } from '~/cache/api';
|
|
2
|
+
import {
|
|
3
|
+
client,
|
|
4
|
+
connectClient,
|
|
5
|
+
disconnectClient,
|
|
6
|
+
pause,
|
|
7
|
+
user21,
|
|
8
|
+
userQueryResponse,
|
|
9
|
+
userQueryResponsePage2,
|
|
10
|
+
} from '~/utils/tests';
|
|
11
|
+
|
|
12
|
+
import { searchUserByDisplayName } from '../searchUserByDisplayName';
|
|
13
|
+
|
|
14
|
+
const getSnapshot = (params?: Record<string, any>) => {
|
|
15
|
+
return {
|
|
16
|
+
data: [] as Amity.User[],
|
|
17
|
+
loading: true,
|
|
18
|
+
error: undefined as any,
|
|
19
|
+
...params,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const { paging, ...payload } = userQueryResponse.data;
|
|
24
|
+
const { paging: paging2, ...payload2 } = userQueryResponsePage2.data;
|
|
25
|
+
|
|
26
|
+
describe('searchUserByDisplayName', () => {
|
|
27
|
+
beforeAll(connectClient);
|
|
28
|
+
afterAll(disconnectClient);
|
|
29
|
+
|
|
30
|
+
beforeEach(enableCache);
|
|
31
|
+
|
|
32
|
+
afterEach(disableCache);
|
|
33
|
+
|
|
34
|
+
const params = { displayName: user21.displayName } as Amity.UserLiveCollection;
|
|
35
|
+
|
|
36
|
+
// integration_test_id: c7cb9776-5c72-4abe-9b3c-572d74d534fe
|
|
37
|
+
test('it should return users collection', async () => {
|
|
38
|
+
const callback = jest.fn();
|
|
39
|
+
client.http.get = jest.fn().mockResolvedValue(userQueryResponse);
|
|
40
|
+
|
|
41
|
+
searchUserByDisplayName(params, callback);
|
|
42
|
+
await pause();
|
|
43
|
+
|
|
44
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
45
|
+
expect(callback).toHaveBeenNthCalledWith(1, expect.objectContaining(getSnapshot()));
|
|
46
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
47
|
+
2,
|
|
48
|
+
expect.objectContaining(
|
|
49
|
+
getSnapshot({
|
|
50
|
+
data: payload.users,
|
|
51
|
+
loading: false,
|
|
52
|
+
}),
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('it should return data from cache', async () => {
|
|
58
|
+
const callback = jest.fn();
|
|
59
|
+
client.http.get = jest.fn().mockResolvedValue(userQueryResponse);
|
|
60
|
+
|
|
61
|
+
searchUserByDisplayName(params, () => undefined);
|
|
62
|
+
await pause();
|
|
63
|
+
searchUserByDisplayName(params, callback);
|
|
64
|
+
await pause();
|
|
65
|
+
|
|
66
|
+
// The second `searchUserByDisplayName` call fetches data from the cache,
|
|
67
|
+
// so there is no loading state and the callback only fires once.
|
|
68
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
69
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
70
|
+
1,
|
|
71
|
+
expect.objectContaining(
|
|
72
|
+
getSnapshot({
|
|
73
|
+
data: payload.users,
|
|
74
|
+
loading: false,
|
|
75
|
+
}),
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('it should return method to fetch next page', async () => {
|
|
81
|
+
const callback = jest.fn();
|
|
82
|
+
client.http.get = jest
|
|
83
|
+
.fn()
|
|
84
|
+
.mockResolvedValue(userQueryResponse)
|
|
85
|
+
.mockResolvedValueOnce(userQueryResponsePage2);
|
|
86
|
+
|
|
87
|
+
searchUserByDisplayName(params, callback);
|
|
88
|
+
await pause();
|
|
89
|
+
|
|
90
|
+
expect(callback).toHaveBeenCalled();
|
|
91
|
+
expect(callback.mock.lastCall).toHaveLength(1);
|
|
92
|
+
|
|
93
|
+
const { onNextPage, hasNextPage } = callback.mock.lastCall[0];
|
|
94
|
+
|
|
95
|
+
expect(hasNextPage).toBe(true);
|
|
96
|
+
expect(onNextPage).toBeTruthy();
|
|
97
|
+
|
|
98
|
+
onNextPage();
|
|
99
|
+
await pause();
|
|
100
|
+
|
|
101
|
+
// 4 -> because 1 local & server call each per call (2)
|
|
102
|
+
expect(callback).toHaveBeenCalledTimes(4);
|
|
103
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
104
|
+
4,
|
|
105
|
+
expect.objectContaining(
|
|
106
|
+
getSnapshot({
|
|
107
|
+
loading: false,
|
|
108
|
+
data: [...payload2.users, ...payload.users],
|
|
109
|
+
}),
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
});
|