-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename user-service to user-management
- Loading branch information
Showing
6 changed files
with
108 additions
and
124 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
102 changes: 102 additions & 0 deletions
102
.../templates/react/src/test/javascript/spec/app/shared/reducers/user-management.spec.ts.ejs
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,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)); | ||
}); | ||
}); | ||
}); |
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,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)); | ||
}); | ||
}); | ||
}); | ||
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