Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

[GH-12004] Add tests for openDirectChannelToUserId action #4179

Merged
merged 5 commits into from
Nov 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions actions/channel_actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ const initialState = {
total_msg_count: 10,
team_id: 'team_id',
},
current_user_id__existingId: {
id: 'current_user_id__existingId',
name: 'current_user_id__existingId',
display_name: 'Default',
delete_at: 0,
type: '0',
total_msg_count: 0,
team_id: 'team_id',
}
},
channelsInTeam: {
'team-id': ['current_channel_id'],
Expand Down Expand Up @@ -87,6 +96,8 @@ const initialState = {
},
};

const realDateNow = Date.now;

jest.mock('mattermost-redux/actions/channels', () => ({
fetchMyChannelsAndMembers: (...args) => ({type: 'MOCK_FETCH_CHANNELS_AND_MEMBERS', args}),
searchChannels: () => {
Expand All @@ -102,6 +113,7 @@ jest.mock('mattermost-redux/actions/channels', () => ({
};
},
addChannelMember: (...args) => ({type: 'MOCK_ADD_CHANNEL_MEMBER', args}),
createDirectChannel: (...args) => ({type: 'MOCK_CREATE_DIRECT_CHANNEL', args}),
createGroupChannel: (...args) => ({type: 'MOCK_CREATE_GROUP_CHANNEL', args}),
}));

Expand Down Expand Up @@ -160,6 +172,109 @@ describe('Actions.Channel', () => {
expect(testStore.getActions()).toEqual(expectedActions);
});

test('openDirectChannelToUserId Not Existing', async () => {
const testStore = await mockStore(initialState);

const expectedActions = [{
type: 'MOCK_CREATE_DIRECT_CHANNEL',
args: ['current_user_id', 'testid'],
}];

const fakeData = {
userId: 'testid',
};

await testStore.dispatch(Actions.openDirectChannelToUserId(fakeData.userId));
expect(testStore.getActions()).toEqual(expectedActions);
});

test('openDirectChannelToUserId Existing', async () => {
Date.now = () => new Date(0).getMilliseconds();
const testStore = await mockStore(initialState);
const expectedActions = [
{
meta: {
batch: true,
},
payload: [
{
data: [
{
category: 'direct_channel_show',
name: 'existingId',
value: 'true',
},
],
type: 'RECEIVED_PREFERENCES',
},
{
data: [
{
category: 'channel_open_time',
name: 'current_user_id__existingId',
value: '0',
},
],
type: 'RECEIVED_PREFERENCES',
},
],
type: 'BATCHING_REDUCER.BATCH',
},
{
data: [
{
category: 'direct_channel_show',
name: 'existingId',
user_id: 'current_user_id',
value: 'true',
},
{
category: 'channel_open_time',
name: 'current_user_id__existingId',
user_id: 'current_user_id',
value: '0',
},
],
meta: {
offline: {
commit: {
type: 'RECEIVED_PREFERENCES',
},
effect: null,
rollback: {
data: [
{
category: 'direct_channel_show',
name: 'existingId',
user_id: 'current_user_id',
value: 'true',
},
{
category: 'channel_open_time',
name: 'current_user_id__existingId',
user_id: 'current_user_id',
value: '0',
},
],
type: 'DELETED_PREFERENCES',
},
},
},
type: 'RECEIVED_PREFERENCES',
},
];
const fakeData = {
userId: 'existingId',
};

await testStore.dispatch(Actions.openDirectChannelToUserId(fakeData.userId));

const doneActions = testStore.getActions();
doneActions[1].meta.offline.effect = null;
expect(doneActions).toEqual(expectedActions);
Date.now = realDateNow;
});

test('openGroupChannelToUserIds', async () => {
const testStore = await mockStore(initialState);

Expand Down