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
1 parent
a75d08f
commit 15e228d
Showing
8 changed files
with
146 additions
and
0 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
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,18 @@ | ||
/** | ||
* Roles actions. | ||
* @module actions/roles/roles | ||
*/ | ||
|
||
import { LIST_ROLES } from '../../constants/ActionTypes'; | ||
|
||
/** | ||
* List roles. | ||
* @function listRoles | ||
* @returns {Object} List roles action. | ||
*/ | ||
export default function listRoles() { | ||
return { | ||
type: LIST_ROLES, | ||
promise: api => api.get('/@roles'), | ||
}; | ||
} |
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,19 @@ | ||
import listRoles from './roles'; | ||
import { LIST_ROLES } from '../../constants/ActionTypes'; | ||
|
||
describe('Roles action', () => { | ||
describe('listRoles', () => { | ||
it('should create an action to get the breadcrumbs', () => { | ||
const action = listRoles(); | ||
|
||
expect(action.type).toEqual(LIST_ROLES); | ||
|
||
const apiMock = { | ||
get: jest.fn(), | ||
}; | ||
action.promise(apiMock); | ||
|
||
expect(apiMock.get).toBeCalledWith('/@roles'); | ||
}); | ||
}); | ||
}); |
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
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,50 @@ | ||
/** | ||
* Roles reducer. | ||
* @module reducers/roles/roles | ||
*/ | ||
|
||
import { LIST_ROLES } from '../../constants/ActionTypes'; | ||
|
||
const initialState = { | ||
error: null, | ||
roles: [], | ||
loaded: false, | ||
loading: false, | ||
}; | ||
|
||
/** | ||
* Roles reducer. | ||
* @function roles | ||
* @param {Object} state Current state. | ||
* @param {Object} action Action to be handled. | ||
* @returns {Object} New state. | ||
*/ | ||
export default function roles(state = initialState, action = {}) { | ||
switch (action.type) { | ||
case `${LIST_ROLES}_PENDING`: | ||
return { | ||
...state, | ||
error: null, | ||
loaded: false, | ||
loading: true, | ||
}; | ||
case `${LIST_ROLES}_SUCCESS`: | ||
return { | ||
...state, | ||
error: null, | ||
roles: action.result, | ||
loaded: true, | ||
loading: false, | ||
}; | ||
case `${LIST_ROLES}_FAIL`: | ||
return { | ||
...state, | ||
error: action.error, | ||
roles: [], | ||
loaded: false, | ||
loading: false, | ||
}; | ||
default: | ||
return 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,54 @@ | ||
import roles from './roles'; | ||
import { LIST_ROLES } from '../../constants/ActionTypes'; | ||
|
||
describe('Roles reducer', () => { | ||
it('should return the initial state', () => { | ||
expect(roles()).toEqual({ | ||
error: null, | ||
roles: [], | ||
loaded: false, | ||
loading: false, | ||
}); | ||
}); | ||
|
||
it('should handle LIST_ROLES_PENDING', () => { | ||
expect( | ||
roles(undefined, { | ||
type: `${LIST_ROLES}_PENDING`, | ||
}), | ||
).toEqual({ | ||
error: null, | ||
roles: [], | ||
loaded: false, | ||
loading: true, | ||
}); | ||
}); | ||
|
||
it('should handle LIST_ROLES_SUCCESS', () => { | ||
expect( | ||
roles(undefined, { | ||
type: `${LIST_ROLES}_SUCCESS`, | ||
result: 'roles', | ||
}), | ||
).toEqual({ | ||
error: null, | ||
roles: 'roles', | ||
loaded: true, | ||
loading: false, | ||
}); | ||
}); | ||
|
||
it('should handle LIST_ROLES_FAIL', () => { | ||
expect( | ||
roles(undefined, { | ||
type: `${LIST_ROLES}_FAIL`, | ||
error: 'failed', | ||
}), | ||
).toEqual({ | ||
error: 'failed', | ||
roles: [], | ||
loaded: false, | ||
loading: false, | ||
}); | ||
}); | ||
}); |