diff --git a/package.json b/package.json index b67c950..d7f37e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@launchpadlab/lp-redux-api", - "version": "6.2.4", + "version": "6.3.0", "description": "redux middleware and api library", "main": "lib/index.js", "scripts": { diff --git a/src/create-request.js b/src/create-request.js index da6b34a..02a6fb5 100644 --- a/src/create-request.js +++ b/src/create-request.js @@ -22,7 +22,7 @@ import { isObject, isFunction } from 'lodash' * // -> will make request to /users/5 * * // Just like in redux-actions, this action can be referenced in a reducer by name: - * + * * handleActions({ * [apiActions.fetchUser]: (state, action) => ... * }) @@ -49,6 +49,7 @@ function createRequestWithMethod (type, definition, method) { } } actionCreator.toString = () => LP_API_ACTION_NAMESPACE + type + actionCreator.type = LP_API_ACTION_NAMESPACE + type return actionCreator } diff --git a/test/create-request.test.js b/test/create-request.test.js index 3987fdd..64e3d64 100644 --- a/test/create-request.test.js +++ b/test/create-request.test.js @@ -7,6 +7,7 @@ import { createPatchRequest, createDeleteRequest, } from '../src/' +import { LP_API_ACTION_NAMESPACE } from '../src/actions' import { REQUEST_TYPE } from './fixtures' test('createRequest requires a type argument', () => { @@ -36,6 +37,16 @@ test('createRequest rejects other types of request definitions', () => { expect(() => createRequest(REQUEST_TYPE, 'wtf')).toThrow() }) +test('createRequest has the namespaced action type as its string representation', () => { + const actionCreator = createRequest(REQUEST_TYPE, {}) + expect(actionCreator.toString()).toEqual(LP_API_ACTION_NAMESPACE+REQUEST_TYPE) +}) + +test('createRequest has the namespaced action type set to the special `type` property', () => { + const actionCreator = createRequest(REQUEST_TYPE, {}) + expect(actionCreator.type).toEqual(LP_API_ACTION_NAMESPACE+REQUEST_TYPE) +}) + // Convenience functions test('createGetRequest creates a request with method GET', () => {