blob: ae22fd1adfe36fc5982860dde21161f729600d6e [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {Action} from "@ngrx/store";
import {clearUserAction, setUserAction} from "../actions";
import {ESPAUserRoles} from "../model";
import {userReducer} from "./user.reducer";
describe("userReducer", () => {
it("should set the user information to the state", () => {
let initialState;
let action: Action = setUserAction(null);
let state = userReducer(initialState, action);
expect(state).toEqual({firstName: undefined, lastName: undefined, roles: []});
action = setUserAction({
firstName: "firstName",
lastName: "lastName",
roles: [
ESPAUserRoles.DIVISION_MEMBER,
ESPAUserRoles.ROLE_SPA_ACCESS
]
});
state = userReducer(initialState, action);
expect(state).toEqual({
firstName: "firstName",
lastName: "lastName",
roles: [
ESPAUserRoles.DIVISION_MEMBER,
ESPAUserRoles.ROLE_SPA_ACCESS
]
});
action = clearUserAction();
state = userReducer(initialState, action);
expect(state).toEqual(undefined);
initialState = {
firstName: "firstName",
lastName: "lastName",
roles: [
ESPAUserRoles.DIVISION_MEMBER,
ESPAUserRoles.ROLE_SPA_ACCESS
]
};
action = clearUserAction();
state = userReducer(initialState, action);
expect(state).toEqual(undefined);
});
});