forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_actions.test.js
116 lines (99 loc) · 5.34 KB
/
integration_actions.test.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import {getProfilesByIds} from 'mattermost-redux/actions/users';
import * as Actions from 'actions/integration_actions.jsx';
jest.mock('mattermost-redux/actions/users', () => ({
getProfilesByIds: jest.fn(() => {
return {type: ''};
}),
}));
const mockStore = configureStore([thunk]);
describe('actions/integration_actions', () => {
const initialState = {
entities: {
teams: {
currentTeamId: 'team_id1',
teams: {
team_id1: {
id: 'team_id1',
name: 'team1',
},
},
},
users: {
currentUserId: 'current_user_id',
profiles: {current_user_id: {id: 'current_user_id', username: 'current_user'}, user_id3: {id: 'user_id3', username: 'user3'}, user_id4: {id: 'user_id4', username: 'user4'}},
},
},
};
describe('loadProfilesForIncomingHooks', () => {
test('load profiles for hooks including user we already have', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForIncomingHooks([{user_id: 'current_user_id'}, {user_id: 'user_id2'}]));
expect(getProfilesByIds).toHaveBeenCalledWith(expect.arrayContainingExactly(['user_id2']));
});
test('load profiles for hooks including only users we don\'t have', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForIncomingHooks([{user_id: 'user_id1'}, {user_id: 'user_id2'}]));
expect(getProfilesByIds).toHaveBeenCalledWith(expect.arrayContainingExactly(['user_id1', 'user_id2']));
});
test('load profiles for empty hooks', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForIncomingHooks([]));
expect(getProfilesByIds).not.toHaveBeenCalled();
});
});
describe('loadProfilesForOutgoingHooks', () => {
test('load profiles for hooks including user we already have', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForOutgoingHooks([{creator_id: 'current_user_id'}, {creator_id: 'user_id2'}]));
expect(getProfilesByIds).toHaveBeenCalledWith(expect.arrayContainingExactly(['user_id2']));
});
test('load profiles for hooks including only users we don\'t have', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForOutgoingHooks([{creator_id: 'user_id1'}, {creator_id: 'user_id2'}]));
expect(getProfilesByIds).toHaveBeenCalledWith(expect.arrayContainingExactly(['user_id1', 'user_id2']));
});
test('load profiles for empty hooks', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForOutgoingHooks([]));
expect(getProfilesByIds).not.toHaveBeenCalled();
});
});
describe('loadProfilesForCommands', () => {
test('load profiles for commands including user we already have', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForCommands([{creator_id: 'current_user_id'}, {creator_id: 'user_id2'}]));
expect(getProfilesByIds).toHaveBeenCalledWith(expect.arrayContainingExactly(['user_id2']));
});
test('load profiles for commands including only users we don\'t have', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForCommands([{creator_id: 'user_id1'}, {creator_id: 'user_id2'}]));
expect(getProfilesByIds).toHaveBeenCalledWith(expect.arrayContainingExactly(['user_id1', 'user_id2']));
});
test('load profiles for empty commands', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForCommands([]));
expect(getProfilesByIds).not.toHaveBeenCalled();
});
});
describe('loadProfilesForOAuthApps', () => {
test('load profiles for apps including user we already have', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForOAuthApps([{creator_id: 'current_user_id'}, {creator_id: 'user_id2'}]));
expect(getProfilesByIds).toHaveBeenCalledWith(expect.arrayContainingExactly(['user_id2']));
});
test('load profiles for apps including only users we don\'t have', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForOAuthApps([{creator_id: 'user_id1'}, {creator_id: 'user_id2'}]));
expect(getProfilesByIds).toHaveBeenCalledWith(expect.arrayContainingExactly(['user_id1', 'user_id2']));
});
test('load profiles for empty apps', () => {
const testStore = mockStore(initialState);
testStore.dispatch(Actions.loadProfilesForOAuthApps([]));
expect(getProfilesByIds).not.toHaveBeenCalled();
});
});
});