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

Commit

Permalink
fix(links-reducer): fix tests, don't handle REJECTED action
Browse files Browse the repository at this point in the history
fix(links-reducer): fix tests, don't handle REJECTED action
  • Loading branch information
Metnew committed Feb 19, 2018
1 parent 745dffd commit ecb9750
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 33 deletions.
13 changes: 2 additions & 11 deletions src/common/reducers/links/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// @flow
import {
GET_LINKS_FULFILLED,
GET_LINKS_REJECTED,
GET_LINKS_PENDING
} from 'actions/links'

export type State = {
entities: any[],
errors: Object,
fetchStatus: 'none' | 'loaded' | 'loading' | 'error'
fetchStatus: 'none' | 'loaded' | 'loading'
}

export const initialState: State = {
Expand All @@ -27,21 +26,13 @@ export function links (state: State = initialState, action): State {
}
}
case GET_LINKS_FULFILLED: {
const entities = action.payload
const entities = action.payload.data
return {
...state,
entities,
fetchStatus: 'loaded'
}
}
case GET_LINKS_REJECTED: {
const errors = action.payload
return {
...state,
errors,
fetchStatus: 'error'
}
}
default:
return state
}
Expand Down
29 changes: 7 additions & 22 deletions src/common/reducers/links/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {links as reducer, initialState} from 'reducers/links'
import {
GET_LINKS_FULFILLED,
GET_LINKS_REJECTED,
GET_LINKS_PENDING
} from 'actions/links'

Expand All @@ -10,33 +9,19 @@ describe('LINKS REDUCER', () => {
expect(reducer(undefined, {x: 'string'})).toEqual(initialState)
})

it('should handle GET_LINKS_SUCCESS', () => {
const payload = [{item: 'payload'}]

it('should handle GET_LINKS_FULFILLED', () => {
const success = {
type: GET_LINKS_FULFILLED,
payload
}
expect(reducer(initialState, success)).toEqual({
...initialState,
entities: payload,
fetchStatus: 'loaded'
})
})

it('should handle GET_LINKS_FAIL', () => {
const fail = {
type: GET_LINKS_REJECTED,
payload: {
hmm: 'thatsanerror'
data: [{item: 'payload'}],
ok: false,
status: 400
}
}
expect(reducer(initialState, fail)).toEqual({
expect(reducer(initialState, success)).toEqual({
...initialState,
errors: {
hmm: 'thatsanerror'
},
fetchStatus: 'error'
entities: [{item: 'payload'}],
fetchStatus: 'loaded'
})
})

Expand Down

0 comments on commit ecb9750

Please sign in to comment.