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, initAuth } from "./auth-action";
14 } from "~/services/auth-service/auth-service";
16 import 'jest-localstorage-mock';
17 import { createServices } from "~/services/services";
18 import { configureStore, RootStore } from "../store";
19 import createBrowserHistory from "history/createBrowserHistory";
21 describe('auth-actions', () => {
22 let reducer: (state: AuthState | undefined, action: AuthAction) => any;
26 store = configureStore(createBrowserHistory(), createServices({ apiHost: "/arvados/v1", keepWebHost: "" }));
28 reducer = authReducer(createServices({ apiHost: "/arvados/v1", keepWebHost: "" }));
31 it('should initialise state with user and api token from local storage', () => {
33 localStorage.setItem(API_TOKEN_KEY, "token");
34 localStorage.setItem(USER_EMAIL_KEY, "test@test.com");
35 localStorage.setItem(USER_FIRST_NAME_KEY, "John");
36 localStorage.setItem(USER_LAST_NAME_KEY, "Doe");
37 localStorage.setItem(USER_UUID_KEY, "uuid");
38 localStorage.setItem(USER_OWNER_UUID_KEY, "ownerUuid");
40 store.dispatch(initAuth());
42 expect(store.getState().auth).toEqual({
45 email: "test@test.com",
49 ownerUuid: "ownerUuid"
54 // TODO: Add remaining action tests
56 it('should fire external url to login', () => {
57 const initialState = undefined;
58 window.location.assign = jest.fn();
59 reducer(initialState, authActions.LOGIN());
60 expect(window.location.assign).toBeCalledWith(
61 `/login?return_to=${window.location.protocol}//${window.location.host}/token`
65 it('should fire external url to logout', () => {
66 const initialState = undefined;
67 window.location.assign = jest.fn();
68 reducer(initialState, authActions.LOGOUT());
69 expect(window.location.assign).toBeCalledWith(
70 `/logout?return_to=${location.protocol}//${location.host}`