Commit d08abef1 authored by Elias Nahum's avatar Elias Nahum Committed by Carlos Tadeu Panato Junior

Fix unit tests (#2214)

parent f7816c73
......@@ -40,12 +40,14 @@ jest.mock('utils/user_agent', () => ({
isIosClassic: jest.fn().mockReturnValueOnce(true).mockReturnValue(false),
}));
const POST_CREATED_TIME = Date.now();
const RECEIVED_POSTS = {
channelId: 'current_channel_id',
data: {order: [], posts: {new_post_id: {channel_id: 'current_channel_id', id: 'new_post_id', message: 'new message', type: ''}}},
data: {order: [], posts: {new_post_id: {channel_id: 'current_channel_id', id: 'new_post_id', message: 'new message', type: '', user_id: 'some_user_id', create_at: POST_CREATED_TIME}}},
type: 'RECEIVED_POSTS',
};
const INCREASED_POST_VISIBILITY = {amount: 1, data: 'current_channel_id', type: 'INCREASE_POST_VISIBILITY'};
const STOP_TYPING = {type: 'stop_typing', data: {id: 'current_channel_idundefined', now: POST_CREATED_TIME, userId: 'some_user_id'}};
function getReceivedPosts(post) {
const receivedPosts = {...RECEIVED_POSTS};
......@@ -165,11 +167,18 @@ describe('Actions.Posts', () => {
test('handleNewPost', async () => {
const testStore = await mockStore(initialState);
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL};
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL, user_id: 'some_user_id', create_at: POST_CREATED_TIME};
const msg = {data: {team_id: 'team_id', mentions: ['current_user_id']}};
await testStore.dispatch(Actions.handleNewPost(newPost, msg));
expect(testStore.getActions()).toEqual([INCREASED_POST_VISIBILITY, getReceivedPosts(newPost)]);
expect(testStore.getActions()).toEqual([
INCREASED_POST_VISIBILITY,
{
meta: {batch: true},
payload: [getReceivedPosts(newPost), STOP_TYPING],
type: 'BATCHING_REDUCER.BATCH',
},
]);
});
test('setEditingPost', async () => {
......
......@@ -68,7 +68,7 @@ export function lastPostActions(post, websocketMessageProps) {
data: {
id: post.channel_id + post.root_id,
userId: post.user_id,
now: Date.now(),
now: post.create_at,
},
}];
......
......@@ -30,12 +30,14 @@ const MARK_CHANNEL_AS_VIEWED = {
args: ['current_channel_id'],
type: 'MOCK_MARK_CHANNEL_AS_VIEWED',
};
const POST_CREATED_TIME = Date.now();
const RECEIVED_POSTS = {
channelId: 'current_channel_id',
data: {order: [], posts: {new_post_id: {channel_id: 'current_channel_id', id: 'new_post_id', message: 'new message', type: ''}}},
data: {order: [], posts: {new_post_id: {channel_id: 'current_channel_id', id: 'new_post_id', message: 'new message', type: '', user_id: 'some_user_id', create_at: POST_CREATED_TIME}}},
type: 'RECEIVED_POSTS',
};
const INCREASED_POST_VISIBILITY = {amount: 1, data: 'current_channel_id', type: 'INCREASE_POST_VISIBILITY'};
const STOP_TYPING = {type: 'stop_typing', data: {id: 'current_channel_idundefined', now: POST_CREATED_TIME, userId: 'some_user_id'}};
function getReceivedPosts(post) {
const receivedPosts = {...RECEIVED_POSTS};
......@@ -98,20 +100,34 @@ describe('actions/post_utils', () => {
test('completePostReceive', async () => {
const testStore = await mockStore(initialState);
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL};
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL, user_id: 'some_user_id', create_at: POST_CREATED_TIME};
const websocketProps = {team_id: 'team_id', mentions: ['current_user_id']};
await testStore.dispatch(PostActionsUtils.completePostReceive(newPost, websocketProps));
expect(testStore.getActions()).toEqual([INCREASED_POST_VISIBILITY, getReceivedPosts(newPost)]);
expect(testStore.getActions()).toEqual([
INCREASED_POST_VISIBILITY,
{
meta: {batch: true},
payload: [getReceivedPosts(newPost), STOP_TYPING],
type: 'BATCHING_REDUCER.BATCH',
},
]);
});
test('lastPostActions', async () => {
const testStore = await mockStore(initialState);
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL};
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL, user_id: 'some_user_id', create_at: POST_CREATED_TIME};
const websocketProps = {team_id: 'team_id', mentions: ['current_user_id']};
await testStore.dispatch(PostActionsUtils.lastPostActions(newPost, websocketProps));
expect(testStore.getActions()).toEqual([INCREASED_POST_VISIBILITY, getReceivedPosts(newPost)]);
expect(testStore.getActions()).toEqual([
INCREASED_POST_VISIBILITY,
{
meta: {batch: true},
payload: [getReceivedPosts(newPost), STOP_TYPING],
type: 'BATCHING_REDUCER.BATCH',
},
]);
});
test('setChannelReadAndView', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment