Skip to content

Commit

Permalink
rename user-service to user-management
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdns committed Apr 20, 2018
1 parent 833bcae commit db6b6a3
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 124 deletions.
4 changes: 2 additions & 2 deletions generators/client/files-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const files = {
condition: generator => generator.authenticationType === 'oauth2',
path: REACT_DIR,
templates: [
'shared/reducers/user-service.ts'
'shared/reducers/user-management.ts'
]
}
],
Expand Down Expand Up @@ -399,7 +399,7 @@ const files = {
condition: generator => generator.skipUserManagement,
path: TEST_SRC_DIR,
templates: [
'spec/app/shared/reducers/user-service.spec.ts'
'spec/app/shared/reducers/user-management.spec.ts'
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import locale from './locale';
<%_ } _%>
import authentication from './authentication';
<%_ if (skipUserManagement) { _%>
import userService from './user-service';
import userManagement from './user-management';
<%_ } _%>

import administration from 'app/modules/administration/administration.reducer';
Expand All @@ -49,11 +49,7 @@ export default combineReducers({
locale,
<%_ } _%>
administration,
<%_ if (!skipUserManagement) { _%>
userManagement,
<%_ } else { _%>
userService,
<%_ } _%>
<%_ if (authenticationType !== 'oauth2') { _%>
register,
activate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
limitations under the License.
-%>
import axios from 'axios';
import { ICrudGetAction, ICrudGetAllAction, ICrudPutAction, ICrudDeleteAction } from 'react-jhipster';
import { ICrudGetAllAction } from 'react-jhipster';

import { REQUEST, SUCCESS, FAILURE } from 'app/shared/reducers/action-type.util';
import { IUser } from 'app/shared/model/user.model';
Expand All @@ -28,7 +28,6 @@ export const ACTION_TYPES = {
};

const initialState = {
loading: false,
errorMessage: null,
users: [],
};
Expand All @@ -39,18 +38,15 @@ export default (state = initialState, action) => {
case REQUEST(ACTION_TYPES.FETCH_USERS):
return {
...state,
loading: true
};
case FAILURE(ACTION_TYPES.FETCH_USERS):
return {
...state,
loading: false,
errorMessage: action.payload
};
case SUCCESS(ACTION_TYPES.FETCH_USERS):
return {
...state,
loading: false,
users: action.payload.data,
};
case ACTION_TYPES.RESET:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<%#
Copyright 2013-2018 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { expect } from 'chai';
import configureStore from 'redux-mock-store';
import promiseMiddleware from 'redux-promise-middleware';
import axios from 'axios';
import thunk from 'redux-thunk';
import * as sinon from 'sinon';

import { REQUEST, SUCCESS, FAILURE } from 'app/shared/reducers/action-type.util';
import userManagement, {
ACTION_TYPES,
getUsers,
} from 'app/shared/reducers/user-management';

describe('User management reducer tests', () => {
const initialState = {
users: [],
errorMessage: null
};

describe('Common', () => {
it('should return the initial state', () => {
expect(userManagement(undefined, {})).to.eql({ ...initialState });
});
});

describe('Requests', () => {
});

describe('Failures', () => {
it('should set state to failed and put an error message in errorMessage', () => {
expect(userManagement(undefined, { type: FAILURE(ACTION_TYPES.FETCH_USERS), payload: 'something happened' })).to.eql
(
{ ...initialState, errorMessage: 'something happened' }
)
});
});

describe('Success', () => {
it('should update state according to a successful fetch users request', () => {
const payload = { data: 'some handsome users' };
const toTest = userManagement(undefined, { type: SUCCESS(ACTION_TYPES.FETCH_USERS), payload });
expect(toTest).to.contain({
users: payload.data
});
});
});

describe('Actions', () => {
let store;

const resolvedObject = { value: 'whatever' };
beforeEach(() => {
const mockStore = configureStore([thunk, promiseMiddleware()]);
store = mockStore({});
axios.get = sinon.stub().returns(Promise.resolve(resolvedObject));
});

it('dispatches FETCH_USERS_PENDING and FETCH_USERS_FULFILLED actions', async () => {
const expectedActions = [
{
type: REQUEST(ACTION_TYPES.FETCH_USERS)
},
{
type: SUCCESS(ACTION_TYPES.FETCH_USERS),
payload: resolvedObject
}
];
await store.dispatch(getUsers()).then(() => expect(store.getActions()).to.eql(expectedActions));
});

it('dispatches FETCH_USERS_PENDING and FETCH_USERS_FULFILLED actions with pagination options', async () => {
const expectedActions = [
{
type: REQUEST(ACTION_TYPES.FETCH_USERS)
},
{
type: SUCCESS(ACTION_TYPES.FETCH_USERS),
payload: resolvedObject
}
];
await store.dispatch(getUsers(1, 20, 'id,desc')).then(() => expect(store.getActions()).to.eql(expectedActions));
});
});
});
Original file line number Diff line number Diff line change
@@ -1,110 +0,0 @@
<%#
Copyright 2013-2018 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { expect } from 'chai';
import configureStore from 'redux-mock-store';
import promiseMiddleware from 'redux-promise-middleware';
import axios from 'axios';
import thunk from 'redux-thunk';
import * as sinon from 'sinon';

import { REQUEST, SUCCESS, FAILURE } from 'app/shared/reducers/action-type.util';
import userService, {
ACTION_TYPES,
getUsers,
} from 'app/shared/reducers/user-service';

describe('User service reducer tests', () => {
const initialState = {
loading: false,
users: [],
errorMessage: null
};

describe('Common', () => {
it('should return the initial state', () => {
expect(userService(undefined, {})).to.eql({ ...initialState });
});
});

describe('Requests', () => {
it('should set state to loading', () => {
expect(userService(undefined, { type: REQUEST(ACTION_TYPES.FETCH_USERS) })).to.eql
(
{ ...initialState, loading: true }
)
});
});

describe('Failures', () => {
it('should set state to failed and put an error message in errorMessage', () => {
expect(userService(undefined, { type: FAILURE(ACTION_TYPES.FETCH_USERS), payload: 'something happened' })).to.eql
(
{ ...initialState, loading: false, errorMessage: 'something happened' }
)
});
});

describe('Success', () => {
it('should update state according to a successful fetch users request', () => {
const payload = { data: 'some handsome users' };
const toTest = userService(undefined, { type: SUCCESS(ACTION_TYPES.FETCH_USERS), payload });
expect(toTest).to.contain({
loading: false,
users: payload.data,
});
});
});

describe('Actions', () => {
let store;

const resolvedObject = { value: 'whatever' };
beforeEach(() => {
const mockStore = configureStore([thunk, promiseMiddleware()]);
store = mockStore({});
axios.get = sinon.stub().returns(Promise.resolve(resolvedObject));
});

it('dispatches FETCH_USERS_PENDING and FETCH_USERS_FULFILLED actions', async () => {
const expectedActions = [
{
type: REQUEST(ACTION_TYPES.FETCH_USERS)
},
{
type: SUCCESS(ACTION_TYPES.FETCH_USERS),
payload: resolvedObject
}
];
await store.dispatch(getUsers()).then(() => expect(store.getActions()).to.eql(expectedActions));
});

it('dispatches FETCH_USERS_PENDING and FETCH_USERS_FULFILLED actions with pagination options', async () => {
const expectedActions = [
{
type: REQUEST(ACTION_TYPES.FETCH_USERS)
},
{
type: SUCCESS(ACTION_TYPES.FETCH_USERS),
payload: resolvedObject
}
];
await store.dispatch(getUsers(1, 20, 'id,desc')).then(() => expect(store.getActions()).to.eql(expectedActions));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ Object.keys(differentRelationships).forEach(key => {
action: `get${upperFirstCamelCase(uniqueRel.otherEntityNamePlural)}`,
instance: `${uniqueRel.otherEntityNamePlural}`,
entity: uniqueRel.otherEntityAngularName,
reducer: uniqueRel.otherEntityAngularName === 'User' ? (authenticationType !== 'oauth2' ? 'userManagement' : 'userService') : uniqueRel.otherEntityName
reducer: uniqueRel.otherEntityAngularName === 'User' ? 'userManagement' : uniqueRel.otherEntityName
});
if (uniqueRel.otherEntityAngularName === 'User') {
_%>
import { I<%= uniqueRel.otherEntityAngularName %> } from 'app/shared/model/user.model';
<%_ if (authenticationType === 'oauth2') { _%>
import { getUsers } from 'app/shared/reducers/user-service';
import { getUsers } from 'app/shared/reducers/user-management';
<%_ } else { _%>
import { getUsers } from 'app/modules/administration/user-management/user-management.reducer';
<%_ } _%>
Expand Down

0 comments on commit db6b6a3

Please sign in to comment.