15088: Fixes tests broken by the merge
[arvados-workbench2.git] / src / store / auth / auth-reducer.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { authReducer, AuthState } from "./auth-reducer";
6 import { AuthAction, authActions } from "./auth-action";
7
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";
12
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) => { }
18     };
19
20     beforeAll(() => {
21         localStorage.clear();
22         reducer = authReducer(createServices(mockConfig({}), actions));
23     });
24
25     it('should correctly initialise state', () => {
26         const initialState = undefined;
27         const user = {
28             email: "test@test.com",
29             firstName: "John",
30             lastName: "Doe",
31             uuid: "zzzzz-tpzed-xurymjxw79nv3jz",
32             ownerUuid: "ownerUuid",
33             username: "username",
34             prefs: {},
35             isAdmin: false,
36             isActive: true
37         };
38         const state = reducer(initialState, authActions.INIT({ user, token: "token" }));
39         expect(state).toEqual({
40             apiToken: "token",
41             user,
42             sshKeys: [],
43             sessions: [],
44             homeCluster: "zzzzz",
45             localCluster: "",
46             remoteHosts: {},
47             remoteHostsConfig: {}
48         });
49     });
50
51     it('should save api token', () => {
52         const initialState = undefined;
53
54         const state = reducer(initialState, authActions.SAVE_API_TOKEN("token"));
55         expect(state).toEqual({
56             apiToken: "token",
57             user: undefined,
58             sshKeys: [],
59             sessions: [],
60             homeCluster: "",
61             localCluster: "",
62             remoteHosts: {},
63             remoteHostsConfig: {}
64         });
65     });
66
67     it('should set user details on success fetch', () => {
68         const initialState = undefined;
69
70         const user = {
71             email: "test@test.com",
72             firstName: "John",
73             lastName: "Doe",
74             uuid: "uuid",
75             ownerUuid: "ownerUuid",
76             username: "username",
77             prefs: {},
78             isAdmin: false,
79             isActive: true
80         };
81
82         const state = reducer(initialState, authActions.USER_DETAILS_SUCCESS(user));
83         expect(state).toEqual({
84             apiToken: undefined,
85             sshKeys: [],
86             sessions: [],
87             homeCluster: "",
88             localCluster: "",
89             remoteHosts: {},
90             remoteHostsConfig: {},
91             user: {
92                 email: "test@test.com",
93                 firstName: "John",
94                 lastName: "Doe",
95                 uuid: "uuid",
96                 ownerUuid: "ownerUuid",
97                 username: "username",
98                 prefs: {},
99                 isAdmin: false,
100                 isActive: true
101             }
102         });
103     });
104 });