16073: Add input collection mounts to process io panel and split pdh links into 2
[arvados-workbench2.git] / src / store / auth / auth-middleware.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import 'jest-localstorage-mock';
6 import Axios, { AxiosInstance } from "axios";
7 import { createBrowserHistory } from "history";
8
9 import { authMiddleware } from "./auth-middleware";
10 import { RootStore, configureStore } from "../store";
11 import { ServiceRepository, createServices } from "services/services";
12 import { ApiActions } from "services/api/api-actions";
13 import { mockConfig } from "common/config";
14 import { authActions } from "./auth-action";
15 import { API_TOKEN_KEY } from 'services/auth-service/auth-service';
16
17 describe("AuthMiddleware", () => {
18     let store: RootStore;
19     let services: ServiceRepository;
20     let axiosInst: AxiosInstance;
21     const config: any = {};
22     const actions: ApiActions = {
23         progressFn: (id: string, working: boolean) => { },
24         errorFn: (id: string, message: string) => { }
25     };
26
27     beforeEach(() => {
28         axiosInst = Axios.create({ headers: {} });
29         services = createServices(mockConfig({}), actions, axiosInst);
30         store = configureStore(createBrowserHistory(), services, config);
31         localStorage.clear();
32     });
33
34     it("handles LOGOUT action", () => {
35         localStorage.setItem(API_TOKEN_KEY, 'someToken');
36         window.location.assign = jest.fn();
37         const next = jest.fn();
38         const middleware = authMiddleware(services)(store)(next);
39         middleware(authActions.LOGOUT({deleteLinkData: false}));
40         expect(window.location.assign).toBeCalledWith(
41             `/logout?api_token=someToken&return_to=${location.protocol}//${location.host}`
42         );
43         expect(localStorage.getItem(API_TOKEN_KEY)).toBeFalsy();
44     });
45 });