1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { authReducer, AuthState } from "./auth-reducer";
6 import { AuthAction, authActions } from "./auth-action";
8 import 'jest-localstorage-mock';
9 import { createServices } from "../../services/services";
11 describe('auth-reducer', () => {
12 let reducer: (state: AuthState | undefined, action: AuthAction) => any;
16 reducer = authReducer(createServices({ apiHost: "/arvados/v1", keepWebHost: "" }));
19 it('should correctly initialise state', () => {
20 const initialState = undefined;
22 email: "test@test.com",
26 ownerUuid: "ownerUuid"
28 const state = reducer(initialState, authActions.INIT({ user, token: "token" }));
29 expect(state).toEqual({
35 it('should save api token', () => {
36 const initialState = undefined;
38 const state = reducer(initialState, authActions.SAVE_API_TOKEN("token"));
39 expect(state).toEqual({
45 it('should set user details on success fetch', () => {
46 const initialState = undefined;
49 email: "test@test.com",
53 ownerUuid: "ownerUuid"
56 const state = reducer(initialState, authActions.USER_DETAILS_SUCCESS(user));
57 expect(state).toEqual({
60 email: "test@test.com",
64 ownerUuid: "ownerUuid",