From 66e70f4fb5564f957f6e4942950d38d6c096e9bb Mon Sep 17 00:00:00 2001 From: Vladimir Metnev Date: Sun, 18 Feb 2018 15:51:51 +0200 Subject: [PATCH] feat(actions-links): use promise-middleware, fix tests feat(actions-links): use promise-middleware, fix tests --- src/common/actions/links/index.js | 27 ++++++-------------------- src/common/actions/links/index.test.js | 16 +++++++-------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/common/actions/links/index.js b/src/common/actions/links/index.js index 119f5b54..ded25fa3 100644 --- a/src/common/actions/links/index.js +++ b/src/common/actions/links/index.js @@ -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 -} - -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() +}) diff --git a/src/common/actions/links/index.test.js b/src/common/actions/links/index.test.js index d1e47f89..ae90b420 100644 --- a/src/common/actions/links/index.test.js +++ b/src/common/actions/links/index.test.js @@ -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] @@ -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 = [ { @@ -27,7 +27,7 @@ describe('Links actions', () => { } ] - nock(process.env.BASE_API) + nock(/.*/) .get('/links') .reply(200, payload) @@ -35,7 +35,7 @@ describe('Links actions', () => { const actions = store.getActions() const success = { meta: null, - type: GET_LINKS_SUCCESS, + type: GET_LINKS_FULFILLED, payload } const expectedActions = [pending, success] @@ -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) @@ -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 }