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";
10 import { mockConfig } from 'common/config';
11 import { ApiActions } from "services/api/api-actions";
13 describe('auth-reducer', () => {
14 let reducer: (state: AuthState | undefined, action: AuthAction) => any;
15 const actions: ApiActions = {
16 progressFn: (id: string, working: boolean) => { },
17 errorFn: (id: string, message: string) => { }
22 reducer = authReducer(createServices(mockConfig({}), actions));
25 it('should correctly initialise state', () => {
26 const initialState = undefined;
28 email: "test@test.com",
31 uuid: "zzzzz-tpzed-xurymjxw79nv3jz",
32 ownerUuid: "ownerUuid",
40 const state = reducer(initialState, authActions.INIT_USER({ user, token: "token" }));
41 expect(state).toEqual({
43 config: mockConfig({}),
55 it('should set user details on success fetch', () => {
56 const initialState = undefined;
59 email: "test@test.com",
63 ownerUuid: "ownerUuid",
72 const state = reducer(initialState, authActions.USER_DETAILS_SUCCESS(user));
73 expect(state).toEqual({
75 apiTokenExpiration: undefined,
76 apiTokenLocation: undefined,
77 config: mockConfig({}),
80 extraApiToken: undefined,
81 extraApiTokenExpiration: undefined,
86 remoteHostsConfig: {},
88 email: "test@test.com",
92 ownerUuid: "ownerUuid",