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';
12 describe('auth-reducer', () => {
13 let reducer: (state: AuthState | undefined, action: AuthAction) => any;
17 reducer = authReducer(createServices(mockConfig({})));
20 it('should correctly initialise state', () => {
21 const initialState = undefined;
23 email: "test@test.com",
27 ownerUuid: "ownerUuid"
29 const state = reducer(initialState, authActions.INIT({ user, token: "token" }));
30 expect(state).toEqual({
36 it('should save api token', () => {
37 const initialState = undefined;
39 const state = reducer(initialState, authActions.SAVE_API_TOKEN("token"));
40 expect(state).toEqual({
46 it('should set user details on success fetch', () => {
47 const initialState = undefined;
50 email: "test@test.com",
54 ownerUuid: "ownerUuid"
57 const state = reducer(initialState, authActions.USER_DETAILS_SUCCESS(user));
58 expect(state).toEqual({
61 email: "test@test.com",
65 ownerUuid: "ownerUuid",