Skip to content

Commit

Permalink
Add type attribute (#156)
Browse files Browse the repository at this point in the history
* Add special type property

* Bump minor
  • Loading branch information
chawes13 authored Jun 29, 2023
1 parent d672733 commit 46f9c79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion src/create-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ...
* })
Expand All @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions test/create-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 46f9c79

Please sign in to comment.