import commentReducer from 'CommentSection/reducer'; import * as ActionTypes from 'CommentSection/constants'; import { action } from 'typesafe-actions'; describe('regMonReducer', () => { it('should initialize the initial state', () => { const createdAction = action( ActionTypes.FETCH_COMMENTS_FAILURE, ); const state = commentReducer(undefined, createdAction); expect(state.comments).toEqual([]); expect(state.users).toEqual([]); }); it('should save comments in state', () => { const createdAt = (new Date()).toString(); const testData = { message: 'test', author: 'testAuth', authorId: 'testId', createdDate: createdAt, isOwner: false, }; const createdAction = action( ActionTypes.FETCH_COMMENTS_SUCCESS, { comments: [{ ...testData, id: '1', }, { ...testData, id: '2', }], }, ); const state = commentReducer(undefined, createdAction); const comment = state.comments[0]; const input = testData; expect(comment.author).toEqual(input.author); expect(comment.createdDate).toEqual(createdAt); expect(comment.message).toEqual(input.message); }); it('should save users in state', () => { const testData = { username: 'test', firstName: 'testFirst', lastName: 'testLast', }; const createdActionUser = action( ActionTypes.FETCH_USERS_SUCCESS, { users: [{ ...testData, id: '1', }, { ...testData, id: '2', }], }, ); const state = commentReducer(undefined, createdActionUser); const user = state.users[0]; const input = testData; expect(user.username).toEqual(input.username); expect(user.firstName).toEqual(input.firstName); expect(user.lastName).toEqual(input.lastName); }); });