-
Notifications
You must be signed in to change notification settings - Fork 960
Expand file tree
/
Copy pathcommunityChatJoinError.test.ts
More file actions
83 lines (70 loc) · 2.25 KB
/
Copy pathcommunityChatJoinError.test.ts
File metadata and controls
83 lines (70 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import {afterEach, describe, expect, it, vi} from 'vitest';
const mocks = vi.hoisted(() => ({
toastNew: vi.fn()
}));
vi.mock('@components/toast', () => ({
toastNew: mocks.toastNew
}));
import handleCommunityChatJoinError
from '@components/communities/handleCommunityChatJoinError';
function createOptions(errorType: string, isBroadcast = false) {
const getChatFull = vi.fn().mockResolvedValue(undefined);
const options = {
error: {type: errorType} as ApiError,
isBroadcast,
communityId: 10 as ChatId,
managers: {
appProfileManager: {getChatFull}
} as any
};
return {getChatFull, options};
}
afterEach(() => {
vi.clearAllMocks();
});
describe('handleCommunityChatJoinError', () => {
it.each([
[false, 'Community.GroupRequestSent'],
[true, 'Community.ChannelRequestSent']
])('handles a sent join request for broadcast=%s', (
isBroadcast,
langPackKey
) => {
const {getChatFull, options} = createOptions(
'INVITE_REQUEST_SENT',
isBroadcast
);
expect(handleCommunityChatJoinError(options)).toBe(true);
expect(mocks.toastNew).toHaveBeenCalledWith({langPackKey});
expect(getChatFull).not.toHaveBeenCalled();
});
it.each(['USERS_TOO_MUCH', 'GROUP_FULL'])(
'handles %s as a full group',
(errorType) => {
const {options} = createOptions(errorType);
expect(handleCommunityChatJoinError(options)).toBe(true);
expect(mocks.toastNew).toHaveBeenCalledWith({
langPackKey: 'Community.GroupFull'
});
}
);
it.each([
'CHANNEL_PRIVATE',
'CHANNEL_PUBLIC_GROUP_NA',
'USER_BANNED_IN_CHANNEL',
'ACCESS_DENIED'
])('handles %s as an inaccessible peer', (errorType) => {
const {getChatFull, options} = createOptions(errorType, true);
expect(handleCommunityChatJoinError(options)).toBe(true);
expect(mocks.toastNew).toHaveBeenCalledWith({
langPackKey: 'Community.ChannelNotAccessible'
});
expect(getChatFull).toHaveBeenCalledWith(10, true);
});
it('leaves an unknown error to the caller', () => {
const {getChatFull, options} = createOptions('UNKNOWN');
expect(handleCommunityChatJoinError(options)).toBe(false);
expect(mocks.toastNew).not.toHaveBeenCalled();
expect(getChatFull).not.toHaveBeenCalled();
});
});