@amityco/ts-sdk 0.0.1-beta.29 → 0.0.1-beta.30
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/channel.d.ts +11 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts +1 -8
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/observers/index.d.ts +1 -0
- package/dist/channel/observers/index.d.ts.map +1 -1
- package/dist/channel/observers/liveChannelMembers.d.ts +20 -0
- package/dist/channel/observers/liveChannelMembers.d.ts.map +1 -0
- package/dist/channel/observers/tests/liveChannelMembers.test.d.ts +2 -0
- package/dist/channel/observers/tests/liveChannelMembers.test.d.ts.map +1 -0
- package/dist/client/api/getToken.d.ts +1 -3
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +1 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/index.cjs.js +105 -2
- package/dist/index.esm.js +104 -3
- package/dist/index.umd.js +4 -4
- package/dist/utils/tests/dummy/channel.d.ts +29 -3
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/utils.d.ts +1 -0
- package/dist/utils/tests/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/@types/domains/channel.ts +19 -0
- package/src/channel/api/queryChannelMembers.ts +3 -8
- package/src/channel/observers/index.ts +1 -0
- package/src/channel/observers/liveChannelMembers.ts +159 -0
- package/src/channel/observers/tests/liveChannelMembers.test.ts +165 -0
- package/src/channel/observers/tests/liveChannels.test.ts +17 -9
- package/src/client/api/isConnected.ts +1 -1
- package/src/core/query/filtering.ts +6 -0
- package/src/core/query/query.ts +2 -3
- package/src/core/tests/query/query.test.ts +93 -11
- package/src/utils/tests/dummy/channel.ts +57 -17
- package/src/utils/tests/utils.ts +10 -0
|
@@ -1,19 +1,101 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isFetcher,
|
|
3
|
+
isMutator,
|
|
4
|
+
isOffline,
|
|
5
|
+
isCachable,
|
|
6
|
+
isLocal,
|
|
7
|
+
isFresh,
|
|
8
|
+
queryOptions,
|
|
9
|
+
} from '~/core/query';
|
|
2
10
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
11
|
+
describe('Core/Query', () => {
|
|
12
|
+
type isFetcherMockType = jest.Mock<any, any> & {
|
|
13
|
+
locally?: jest.Mock<any, any>;
|
|
14
|
+
};
|
|
6
15
|
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
type isMutatorMockType = jest.Mock<any, any> & {
|
|
17
|
+
optimistically?: jest.Mock<any, any>;
|
|
18
|
+
};
|
|
9
19
|
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
describe('isFetcher', () => {
|
|
21
|
+
const isFetcherMock: isFetcherMockType = jest.fn();
|
|
22
|
+
|
|
23
|
+
test('should return false if func is not a fetcher', () => {
|
|
24
|
+
expect(isFetcher(isFetcherMock)).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('should return true if func is a fetcher', () => {
|
|
28
|
+
isFetcherMock.locally = jest.fn();
|
|
29
|
+
|
|
30
|
+
expect(isFetcher(isFetcherMock)).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('isMutator', () => {
|
|
35
|
+
const isMutatorMock: isMutatorMockType = jest.fn();
|
|
36
|
+
|
|
37
|
+
test('should return false if func is not a mutator', () => {
|
|
38
|
+
expect(isMutator(isMutatorMock)).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should return true if func is a mutator', () => {
|
|
42
|
+
isMutatorMock.optimistically = jest.fn();
|
|
43
|
+
|
|
44
|
+
expect(isMutator(isMutatorMock)).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('isOffline', () => {
|
|
49
|
+
const isMutatorMock: isMutatorMockType = jest.fn();
|
|
50
|
+
|
|
51
|
+
test('should return false if func is not a mutator or fetcher', () => {
|
|
52
|
+
expect(isOffline(isMutatorMock)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('should return true if func is a mutator', () => {
|
|
56
|
+
isMutatorMock.optimistically = jest.fn();
|
|
57
|
+
|
|
58
|
+
expect(isMutator(isMutatorMock)).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('isCachable', () => {
|
|
63
|
+
test('should return false if object is not cachable', () => {
|
|
64
|
+
expect(isCachable({})).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('should return true if object is cachable', () => {
|
|
68
|
+
expect(isCachable({ cachedAt: -1 })).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('isLocal', () => {
|
|
73
|
+
test('should return false if object is not local', () => {
|
|
74
|
+
expect(isLocal({ cachedAt: 0 })).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('should return true if object is local', () => {
|
|
78
|
+
expect(isLocal({ cachedAt: -1 })).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('isFresh', () => {
|
|
83
|
+
test('should return false if object is not fresh', () => {
|
|
84
|
+
expect(isFresh({ cachedAt: -1 })).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('should return true if object is fresh', () => {
|
|
88
|
+
expect(isFresh({ cachedAt: Date.now() })).toBe(true);
|
|
89
|
+
});
|
|
12
90
|
});
|
|
13
91
|
|
|
14
|
-
|
|
15
|
-
|
|
92
|
+
describe('queryOptions', () => {
|
|
93
|
+
test('should return lifespan 0 if server only', () => {
|
|
94
|
+
expect(queryOptions('server_only').lifeSpan).toBe(0);
|
|
95
|
+
});
|
|
16
96
|
|
|
17
|
-
|
|
97
|
+
test('should return lifespan Infinity if cache only', () => {
|
|
98
|
+
expect(queryOptions('cache_only').lifeSpan).toBe(Infinity);
|
|
99
|
+
});
|
|
18
100
|
});
|
|
19
101
|
});
|
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import { date, rolesAndPermissions, user11 } from '.';
|
|
1
|
+
import { date, rolesAndPermissions, user11, user12, user13 } from '.';
|
|
2
|
+
|
|
3
|
+
const mockPage = {
|
|
4
|
+
paging: {
|
|
5
|
+
previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
6
|
+
next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
7
|
+
},
|
|
8
|
+
};
|
|
2
9
|
|
|
3
10
|
export const channelRaw1: Amity.ChannelRaw = {
|
|
11
|
+
tags: ['tag2'],
|
|
4
12
|
messageCount: 1,
|
|
5
13
|
createdAt: date,
|
|
14
|
+
isDeleted: false,
|
|
6
15
|
type: 'community',
|
|
7
16
|
channelId: 'channelId11',
|
|
8
17
|
};
|
|
9
18
|
|
|
10
19
|
export const channelRaw2: Amity.ChannelRaw = {
|
|
20
|
+
tags: ['tag1'],
|
|
11
21
|
messageCount: 3,
|
|
12
22
|
createdAt: date,
|
|
13
|
-
|
|
23
|
+
isDeleted: true,
|
|
24
|
+
type: 'conversation',
|
|
14
25
|
channelId: 'channelId12',
|
|
15
26
|
};
|
|
16
27
|
|
|
@@ -26,17 +37,12 @@ export const channel11: Amity.Channel = {
|
|
|
26
37
|
hasMention: false,
|
|
27
38
|
unreadCount: 0,
|
|
28
39
|
type: 'community',
|
|
29
|
-
isDeleted: false,
|
|
30
|
-
tags: ['tag2'],
|
|
31
40
|
};
|
|
32
41
|
|
|
33
42
|
export const channel12: Amity.Channel = {
|
|
34
43
|
...channelRaw2,
|
|
35
|
-
hasMention:
|
|
36
|
-
unreadCount:
|
|
37
|
-
type: 'conversation',
|
|
38
|
-
isDeleted: true,
|
|
39
|
-
tags: ['tag1'],
|
|
44
|
+
hasMention: true,
|
|
45
|
+
unreadCount: 2,
|
|
40
46
|
};
|
|
41
47
|
|
|
42
48
|
export const channel21: Amity.Channel = {
|
|
@@ -69,16 +75,33 @@ export const channelUser2: Amity.Membership<'channel'> = {
|
|
|
69
75
|
channelId: channel12.channelId,
|
|
70
76
|
};
|
|
71
77
|
|
|
78
|
+
export const channelUser3: Amity.Membership<'channel'> = {
|
|
79
|
+
isMuted: false,
|
|
80
|
+
createdAt: date,
|
|
81
|
+
muteTimeout: '',
|
|
82
|
+
isBanned: false,
|
|
83
|
+
readToSegment: 1,
|
|
84
|
+
lastActivity: date,
|
|
85
|
+
userId: user12.userId,
|
|
86
|
+
...rolesAndPermissions,
|
|
87
|
+
membership: 'none',
|
|
88
|
+
roles: ['test-role'],
|
|
89
|
+
lastMentionedSegment: 0,
|
|
90
|
+
channelId: channel11.channelId,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const channelUser4: Amity.Membership<'channel'> = {
|
|
94
|
+
...channelUser3,
|
|
95
|
+
userId: user13.userId,
|
|
96
|
+
};
|
|
97
|
+
|
|
72
98
|
export const channelQueryResponse = {
|
|
73
99
|
data: {
|
|
74
100
|
channels: [channel11, channel12],
|
|
75
101
|
channelUsers: [],
|
|
76
102
|
files: [],
|
|
77
103
|
users: [],
|
|
78
|
-
|
|
79
|
-
previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
80
|
-
next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
81
|
-
},
|
|
104
|
+
...mockPage,
|
|
82
105
|
},
|
|
83
106
|
};
|
|
84
107
|
|
|
@@ -88,9 +111,26 @@ export const channelQueryResponsePage2 = {
|
|
|
88
111
|
channelUsers: [],
|
|
89
112
|
files: [],
|
|
90
113
|
users: [],
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
114
|
+
...mockPage,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const channelUserQueryResponse = {
|
|
119
|
+
data: {
|
|
120
|
+
channels: [channel11],
|
|
121
|
+
channelUsers: [channelUser1, channelUser3],
|
|
122
|
+
users: [],
|
|
123
|
+
files: [],
|
|
124
|
+
...mockPage,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const channelUserQueryResponsePage2 = {
|
|
129
|
+
data: {
|
|
130
|
+
channels: [channel11],
|
|
131
|
+
channelUsers: [channelUser4],
|
|
132
|
+
users: [],
|
|
133
|
+
files: [],
|
|
134
|
+
...mockPage,
|
|
95
135
|
},
|
|
96
136
|
};
|
package/src/utils/tests/utils.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { encode } from 'js-base64';
|
|
2
2
|
|
|
3
3
|
export const encodeJson = (value: Record<string, any>) => encode(JSON.stringify(value));
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Used instead of asserting an async request is completed, when the async
|
|
7
|
+
* request is not the API being tested. This util makes tests readable by moving
|
|
8
|
+
* all assertions to the end of the test
|
|
9
|
+
*/
|
|
10
|
+
export const pause = (ms = 50) =>
|
|
11
|
+
new Promise(resolve => {
|
|
12
|
+
setTimeout(resolve, ms);
|
|
13
|
+
});
|