mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
fixed reducer for FETCH_USER_SUCCESS
This commit is contained in:
@@ -374,25 +374,18 @@ export default function reducer(state: any = {}, action: any = {}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
case FETCH_USER_SUCCESS:
|
case FETCH_USER_SUCCESS:
|
||||||
const ubn = extractUsersByNames(
|
return reduceUsersByNames(state, action.payload.name, {
|
||||||
[action.payload],
|
loading: false,
|
||||||
[action.payload.name],
|
error: null,
|
||||||
state.usersByNames
|
entry: action.payload
|
||||||
);
|
});
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
users: {
|
|
||||||
error: null,
|
|
||||||
entries: [action.payload.name],
|
|
||||||
loading: false
|
|
||||||
},
|
|
||||||
usersByNames: ubn
|
|
||||||
};
|
|
||||||
case FETCH_USER_FAILURE:
|
case FETCH_USER_FAILURE:
|
||||||
return reduceUsersByNames(state, action.payload.username, {
|
return reduceUsersByNames(state, action.payload.username, {
|
||||||
loading: true,
|
loading: true,
|
||||||
error: action.payload.error
|
error: action.payload.error
|
||||||
});
|
});
|
||||||
|
|
||||||
// Delete single user cases
|
// Delete single user cases
|
||||||
case DELETE_USER:
|
case DELETE_USER:
|
||||||
return reduceUsersByNames(state, action.payload.name, {
|
return reduceUsersByNames(state, action.payload.name, {
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ import {
|
|||||||
deleteUserSuccess,
|
deleteUserSuccess,
|
||||||
fetchUsersPending,
|
fetchUsersPending,
|
||||||
fetchUserPending,
|
fetchUserPending,
|
||||||
fetchUserFailure
|
fetchUserFailure,
|
||||||
|
fetchUserSuccess
|
||||||
} from "./users";
|
} from "./users";
|
||||||
|
|
||||||
import reducer from "./users";
|
import reducer from "./users";
|
||||||
@@ -443,11 +444,44 @@ describe("users reducer", () => {
|
|||||||
expect(newState.usersByNames["zaphod"].loading).toBeTruthy();
|
expect(newState.usersByNames["zaphod"].loading).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not affect users state", () => {
|
||||||
|
const newState = reducer(
|
||||||
|
{
|
||||||
|
users: {
|
||||||
|
entries: ["ford"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fetchUserPending("zaphod")
|
||||||
|
);
|
||||||
|
expect(newState.usersByNames["zaphod"].loading).toBeTruthy();
|
||||||
|
expect(newState.users.entries).toEqual(["ford"]);
|
||||||
|
});
|
||||||
|
|
||||||
it("should update state according to FETCH_USER_FAILURE action", () => {
|
it("should update state according to FETCH_USER_FAILURE action", () => {
|
||||||
const newState = reducer(
|
const newState = reducer(
|
||||||
{},
|
{},
|
||||||
fetchUserFailure(userFord.name, new Error("kaputt!"))
|
fetchUserFailure(userFord.name, new Error("kaputt!"))
|
||||||
);
|
);
|
||||||
expect(newState.usersByNames["ford"].error).toBeTruthy;
|
expect(newState.usersByNames["ford"].error).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should update state according to FETCH_USER_SUCCESS action", () => {
|
||||||
|
const newState = reducer({}, fetchUserSuccess(userFord));
|
||||||
|
expect(newState.usersByNames["ford"].loading).toBeFalsy();
|
||||||
|
expect(newState.usersByNames["ford"].entry).toBe(userFord);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should affect users state nor the state of other users", () => {
|
||||||
|
const newState = reducer(
|
||||||
|
{
|
||||||
|
users: {
|
||||||
|
entries: ["zaphod"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fetchUserSuccess(userFord)
|
||||||
|
);
|
||||||
|
expect(newState.usersByNames["ford"].loading).toBeFalsy();
|
||||||
|
expect(newState.usersByNames["ford"].entry).toBe(userFord);
|
||||||
|
expect(newState.users.entries).toEqual(["zaphod"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user