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

Commit

Permalink
fix(actions-links): don't handle REJECTED action, update tests
Browse files Browse the repository at this point in the history
fix(actions-links): don't handle REJECTED action, update tests
  • Loading branch information
Metnew committed Feb 19, 2018
1 parent ecb9750 commit 5a7d262
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 41 deletions.
3 changes: 2 additions & 1 deletion src/common/actions/links/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import {getLinksAPI} from 'api/LinksSvc'
// Define action types
export const GET_LINKS_FULFILLED = 'GET_LINKS_FULFILLED'
export const GET_LINKS_REJECTED = 'GET_LINKS_REJECTED'
// GET_LINKS_REJECTED isn't handled in the boilerplate.
// export const GET_LINKS_REJECTED = 'GET_LINKS_REJECTED'
export const GET_LINKS_PENDING = 'GET_LINKS_PENDING'

export const GET_LINKS = () => ({
Expand Down
58 changes: 18 additions & 40 deletions src/common/actions/links/index.test.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,44 @@
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import promiseMiddleware from 'redux-promise-middleware'
import nock from 'nock'
import {
GET_LINKS,
GET_LINKS_FULFILLED,
GET_LINKS_PENDING,
GET_LINKS_REJECTED
GET_LINKS_PENDING
} from 'actions/links'

const middlewares = [thunk]
const middlewares = [thunk, promiseMiddleware()]
const mockStore = configureMockStore(middlewares)

describe('Links actions', () => {
describe('GET_LINKS', () => {
const pending = {
meta: null,
type: GET_LINKS_PENDING
}

it('creates GET_LINKS_FULFILLED when GET_LINKS was successful', done => {
it('creates GET_LINKS_FULFILLED when GET_LINKS was successful', async done => {
const store = mockStore({})
const payload = [
{
link: 'string',
header: 'string'
}
]

nock(/.*/)
.get('/links')
.reply(200, payload)

return store.dispatch(GET_LINKS()).then(res => {
const actions = store.getActions()
const success = {
meta: null,
type: GET_LINKS_FULFILLED,
payload
}
const expectedActions = [pending, success]

expect(actions).toEqual(expectedActions)
done()
})
})
const data = {
link: 'string',
header: 'string'
}

it('creates GET_LINKS_REJECTED when GET_LINKS was unsuccessful', async done => {
const payload = {errors: {}}
nock(/.*/)
.get('/links')
.reply(400, payload)
.get('/api/links')
.reply(200, data)

const store = mockStore({})
await store.dispatch(GET_LINKS())
const actions = store.getActions()
const fail = {
meta: null,
type: GET_LINKS_REJECTED,
error: true,
payload
const success = {
type: GET_LINKS_FULFILLED,
payload: {
ok: true,
status: 200,
data
}
}
const expectedActions = [pending, fail]
const expectedActions = [pending, success]

expect(actions).toEqual(expectedActions)
done()
Expand Down

0 comments on commit 5a7d262

Please sign in to comment.