small fixes in users module

This commit is contained in:
Sebastian Sdorra
2018-07-30 11:17:47 +02:00
parent f9f93b338e
commit 2511e99409
2 changed files with 8 additions and 10 deletions

View File

@@ -111,7 +111,7 @@ export function fetchUser(name: string) {
export function fetchUserPending(name: string): Action { export function fetchUserPending(name: string): Action {
return { return {
type: FETCH_USER_PENDING, type: FETCH_USER_PENDING,
payload: { name } payload: name
}; };
} }
@@ -122,11 +122,11 @@ export function fetchUserSuccess(user: any): Action {
}; };
} }
export function fetchUserFailure(username: string, error: Error): Action { export function fetchUserFailure(name: string, error: Error): Action {
return { return {
type: FETCH_USER_FAILURE, type: FETCH_USER_FAILURE,
payload: { payload: {
username, name,
error error
} }
}; };
@@ -148,7 +148,6 @@ export function createUser(user: User, callback?: () => void) {
.catch(err => .catch(err =>
dispatch( dispatch(
createUserFailure( createUserFailure(
user,
new Error(`failed to add user ${user.name}: ${err.message}`) new Error(`failed to add user ${user.name}: ${err.message}`)
) )
) )
@@ -169,11 +168,10 @@ export function createUserSuccess(): Action {
}; };
} }
export function createUserFailure(user: User, err: Error): Action { export function createUserFailure(error: Error): Action {
return { return {
type: CREATE_USER_FAILURE, type: CREATE_USER_FAILURE,
payload: err, payload: error
user
}; };
} }
@@ -392,7 +390,7 @@ function byNamesReducer(state: any = {}, action: any = {}) {
// Fetch single user actions // Fetch single user actions
case FETCH_USER_PENDING: case FETCH_USER_PENDING:
return reducerByName(state, action.payload.name, { return reducerByName(state, action.payload, {
loading: true, loading: true,
error: null error: null
}); });
@@ -403,7 +401,7 @@ function byNamesReducer(state: any = {}, action: any = {}) {
entry: action.payload entry: action.payload
}); });
case FETCH_USER_FAILURE: case FETCH_USER_FAILURE:
return reducerByName(state, action.payload.username, { return reducerByName(state, action.payload.name, {
loading: false, loading: false,
error: action.payload.error error: action.payload.error
}); });

View File

@@ -517,7 +517,7 @@ describe("users reducer", () => {
it("should set the loading to false and the error if user could not be created", () => { it("should set the loading to false and the error if user could not be created", () => {
const newState = reducer( const newState = reducer(
{ create: { loading: true, error: null } }, { create: { loading: true, error: null } },
createUserFailure(userFord, new Error("kaputt kaputt")) createUserFailure(new Error("kaputt kaputt"))
); );
expect(newState.create.loading).toBeFalsy(); expect(newState.create.loading).toBeFalsy();
expect(newState.create.error).toEqual(new Error("kaputt kaputt")); expect(newState.create.error).toEqual(new Error("kaputt kaputt"));