-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
127 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
trivialRedux = {defaultStates} = require '../../src/index' | ||
|
||
api = trivialRedux( | ||
todos: | ||
entry: 'http://www.somesite.somedomain/todos' | ||
type: 'action' | ||
) | ||
|
||
{reducers, types} = api | ||
|
||
describe 'action reducer', -> | ||
test 'execute pending', -> | ||
state = Object.assign({}, defaultStates.action) | ||
state = reducers.todos(state, type: types.todos.execute.load) | ||
|
||
expect(state.pending).toBe true | ||
|
||
test 'execute success', -> | ||
data = { | ||
someData: 'Something', | ||
another: [] | ||
} | ||
state = Object.assign({}, defaultStates.action) | ||
state = reducers.todos(state, type: types.todos.execute.success, payload: data) | ||
|
||
expect(state.data).toEqual data | ||
expect(state.pending).toBe false | ||
expect(typeof state.lastExecutedAt).toBe 'number' | ||
|
||
test 'execute failure', -> | ||
error = 'error' | ||
state = Object.assign({}, defaultStates.action) | ||
state = reducers.todos(state, type: types.todos.execute.failure, payload: error) | ||
|
||
expect(state.pending).toBe false | ||
expect(state.data).toBe error | ||
|
||
test 'some action', -> | ||
data = { | ||
someData: 'Something', | ||
another: [] | ||
} | ||
state = Object.assign({}, defaultStates.action, data: data) | ||
|
||
expect(reducers.todos(state, type: 'SOME_ACTION_TYPE')).toEqual state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
trivialRedux = require '../../src/index' | ||
actionTypesFor = require '../../src/action_types' | ||
actionTypeFor = require '../../src/action_type' | ||
|
||
api = trivialRedux( | ||
todos: | ||
entry:'http://www.somesite.somedomain/todos' | ||
type: 'action' | ||
) | ||
|
||
describe 'Fetch actions', -> | ||
test 'execute action', -> | ||
action = {meta: {fetch}, types} = api.requests.todos.execute(test: 1) | ||
|
||
expect(types).toEqual actionTypesFor('execute', 'todos') | ||
expect(fetch.url).toBe 'http://www.somesite.somedomain/todos.json' | ||
expect(fetch.params).toBeUndefined() | ||
expect(fetch.data).toEqual(test: 1) | ||
expect(Object.keys(fetch).length).toBe 3 | ||
expect(action.isRequest).toBe true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
trivialRedux = require '../src/index' | ||
actionTypesFor = require '../src/action_types' | ||
actionTypeFor = require '../src/action_type' | ||
|
||
api = trivialRedux( | ||
todos: | ||
entry:'http://www.somesite.somedomain/todos' | ||
type: 'rest' | ||
stateless: true | ||
) | ||
|
||
describe 'Stateless endpoint', -> | ||
|
||
test 'api contains only requests', -> | ||
expect(api.requests.todos).toBeDefined() | ||
expect(api.actions.todos).toBeUndefined() | ||
expect(api.reducers.todo).toBeUndefined() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
actionTypesFor = require '../action_types' | ||
actionTypeFor = require '../action_type' | ||
urlFormat = require '../utils/url_format' | ||
|
||
module.exports = (entity_name, endpoint, settings) -> | ||
format = urlFormat(settings) | ||
|
||
execute: (data, options = {}) -> | ||
types: actionTypesFor('execute', entity_name) | ||
meta: | ||
fetch: Object.assign({}, { | ||
url: format(endpoint) | ||
method: 'POST' | ||
data | ||
}, options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = | ||
fetch: require './fetch' | ||
rest: require './rest' | ||
setter: require './setter' | ||
setter: require './setter' | ||
action: require './action' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
actionTypesFor = require '../action_types' | ||
actionTypeFor = require '../action_type' | ||
defaultState = require '../states/fetch' | ||
|
||
createActionReducerFor = (entity_name, initialState) -> | ||
(state = initialState, action) -> | ||
switch action.type | ||
when @types.execute.load | ||
Object.assign({}, state, pending: true) | ||
when @types.execute.success | ||
lastExecutedAt: new Date().getTime(), data: action.payload, pending: false | ||
when @types.execute.failure | ||
Object.assign({}, state, data: action.payload, pending: false) | ||
when @types.reset | ||
Object.assign({}, state, initialState) | ||
else | ||
state | ||
|
||
createActionReducerFor.defaultState = defaultState | ||
|
||
module.exports = createActionReducerFor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = | ||
fetch: require './fetch' | ||
rest: require './rest' | ||
setter: require './setter' | ||
setter: require './setter' | ||
action: require './action' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters