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

Commit

Permalink
feat(actions-links): use promise-middleware, fix tests
Browse files Browse the repository at this point in the history
feat(actions-links): use promise-middleware, fix tests
  • Loading branch information
Metnew committed Feb 18, 2018
1 parent 64c2bb5 commit 66e70f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
27 changes: 6 additions & 21 deletions src/common/actions/links/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
// @flow
import {awral} from 'actions/utils'
import {getLinksAPI} from 'api/LinksSvc'
import type {LinkItem} from 'types'
// Define action types
export const GET_LINKS_SUCCESS = 'GET_LINKS_SUCCESS'
export const GET_LINKS_FAIL = 'GET_LINKS_FAIL'
export const GET_LINKS_FULFILLED = 'GET_LINKS_FULFILLED'
export const GET_LINKS_REJECTED = 'GET_LINKS_REJECTED'
export const GET_LINKS_PENDING = 'GET_LINKS_PENDING'

export type GET_LINKS_SUCCESS_TYPE = {
type: 'GET_LINKS_SUCCESS',
payload: Array<LinkItem>
}

export type GET_LINKS_FAIL_TYPE = {
type: 'GET_LINKS_FAIL',
payload: {
errors?: void | Object
}
}

export type GET_LINKS_PENDING_TYPE = {
type: 'GET_LINKS_PENDING'
}

export const GET_LINKS = awral(getLinksAPI)('GET_LINKS')
export const GET_LINKS = () => ({
type: 'GET_LINKS',
payload: getLinksAPI()
})
16 changes: 8 additions & 8 deletions src/common/actions/links/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import thunk from 'redux-thunk'
import nock from 'nock'
import {
GET_LINKS,
GET_LINKS_SUCCESS,
GET_LINKS_FULFILLED,
GET_LINKS_PENDING,
GET_LINKS_FAIL
GET_LINKS_REJECTED
} from 'actions/links'

const middlewares = [thunk]
Expand All @@ -18,7 +18,7 @@ describe('Links actions', () => {
type: GET_LINKS_PENDING
}

it('creates GET_LINKS_SUCCESS when GET_LINKS was successful', done => {
it('creates GET_LINKS_FULFILLED when GET_LINKS was successful', done => {
const store = mockStore({})
const payload = [
{
Expand All @@ -27,15 +27,15 @@ describe('Links actions', () => {
}
]

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

return store.dispatch(GET_LINKS()).then(res => {
const actions = store.getActions()
const success = {
meta: null,
type: GET_LINKS_SUCCESS,
type: GET_LINKS_FULFILLED,
payload
}
const expectedActions = [pending, success]
Expand All @@ -45,9 +45,9 @@ describe('Links actions', () => {
})
})

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

Expand All @@ -56,7 +56,7 @@ describe('Links actions', () => {
const actions = store.getActions()
const fail = {
meta: null,
type: GET_LINKS_FAIL,
type: GET_LINKS_REJECTED,
error: true,
payload
}
Expand Down

0 comments on commit 66e70f4

Please sign in to comment.