Skip to content

Instantly share code, notes, and snippets.

@terrysahaidak
Created January 21, 2016 09:45
Show Gist options
  • Save terrysahaidak/3a31b320586adab034f2 to your computer and use it in GitHub Desktop.
Save terrysahaidak/3a31b320586adab034f2 to your computer and use it in GitHub Desktop.
Test failed
messages module
messages reducer
√ should handle ROOM_MESSAGES_SUCCESS
1) should handle ROOM_MESSAGES_BEFORE_SUCCESS
1 passing (495ms)
1 failing
1) messages module messages reducer should handle ROOM_MESSAGES_BEFORE_SUCCESS:
Error: Expected { entities:
{ message1: {
id: 'message1', text: 'Hi @suprememoocow !'
},
message2: {
id: 'message2', text: 'Hi @suprememoocow !'
}
}, error: false, errors: [], isFetching: false,
messagesByRoom: {
room1: [ 'message2' ] }
} to equal { entities:
{ message1: {
id: 'message1', text: 'Hi @suprememoocow !'
},
message2: {
id: 'message2', text: 'Hi @suprememoocow !'
} }, error: false, errors: [], isFetching: false,
messagesByRoom: { room1: [ 'message1', 'message2' ] } }
+ expected - actual
"errors": []
"isFetching": false
"messagesByRoom": {
"room1": [
+ "message1"
"message2"
]
}
}
export default function messages(state = {
isFetching: false,
error: false,
messagesByRoom: {},
entities: {},
errors: []
}, action) {
switch (action.type) {
case ROOM_MESSAGES_BEFORE_SUCCESS:
{
const {lastMessageId, response, roomId} = action.payload
const normalized = normalize(response)
const roomIds = state.messagesByRoom[[roomId]]
return {
...state,
isFetching: false,
error: false,
messagesByRoom: {
...state.messagesByRoom,
[roomId]: _.merge(roomIds, normalized.ids)
},
entities: _.merge(state.entities, normalized.entities)
}
}
default:
return state
}
}
import expect from 'expect'
import _ from 'lodash'
import * as messages from '../../app/modules/messages'
describe('messages module', () => {
describe('messages reducer', () => {
const initialState = {
isFetching: false,
error: false,
messagesByRoom: {},
entities: {},
errors: []
}
const stateBefore = _.merge(initialState, {
messagesByRoom: {
'room1': ["message1"]
},
entities: {
"message1": {
"id": "message1",
"text": "Hi @suprememoocow !",
}
}
})
const roomId = 'room1'
const testData = [{
"id": "message1",
"text": "Hi @suprememoocow !",
}]
const testData2 = [{
"id": "message2",
"text": "Hi @suprememoocow !",
}]
const lastMessageId = 'message1'
it('should handle ROOM_MESSAGES_BEFORE_SUCCESS', () => {
expect(
messages.default(stateBefore, {
type: messages.ROOM_MESSAGES_BEFORE_SUCCESS,
payload: {response: testData2, roomId, lastMessageId}
})
).toEqual(_.merge(initialState, {
messagesByRoom: {
'room1': ["message1", "message2"]
},
entities: {
"message1": {
"id": "message1",
"text": "Hi @suprememoocow !",
},
"message2": {
"id": "message2",
"text": "Hi @suprememoocow !",
}
}
}))
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment