Merge branch '15256-removing-files-during-upload'
[arvados-workbench2.git] / src / store / auth / auth-reducer.test.ts
index aaedd40d0b847455d0852efbce0a031cfd14067d..756feeeb6b835d7c3c845c88752a0aa6726dd6db 100644 (file)
@@ -6,14 +6,20 @@ import { authReducer, AuthState } from "./auth-reducer";
 import { AuthAction, authActions } from "./auth-action";
 
 import 'jest-localstorage-mock';
-import { createServices } from "../../services/services";
+import { createServices } from "~/services/services";
+import { mockConfig } from '~/common/config';
+import { ApiActions } from "~/services/api/api-actions";
 
 describe('auth-reducer', () => {
     let reducer: (state: AuthState | undefined, action: AuthAction) => any;
+    const actions: ApiActions = {
+        progressFn: (id: string, working: boolean) => { },
+        errorFn: (id: string, message: string) => { }
+    };
 
     beforeAll(() => {
         localStorage.clear();
-        reducer = authReducer(createServices({ apiHost: "/arvados/v1", keepWebHost: "" }));
+        reducer = authReducer(createServices(mockConfig({}), actions));
     });
 
     it('should correctly initialise state', () => {
@@ -22,23 +28,25 @@ describe('auth-reducer', () => {
             email: "test@test.com",
             firstName: "John",
             lastName: "Doe",
-            uuid: "uuid",
-            ownerUuid: "ownerUuid"
+            uuid: "zzzzz-tpzed-xurymjxw79nv3jz",
+            ownerUuid: "ownerUuid",
+            username: "username",
+            prefs: {},
+            isAdmin: false,
+            isActive: true
         };
-        const state = reducer(initialState, authActions.INIT({ user, token: "token" }));
-        expect(state).toEqual({
-            apiToken: "token",
-            user
-        });
-    });
-
-    it('should save api token', () => {
-        const initialState = undefined;
-
-        const state = reducer(initialState, authActions.SAVE_API_TOKEN("token"));
+        const state = reducer(initialState, authActions.INIT_USER({ user, token: "token" }));
         expect(state).toEqual({
             apiToken: "token",
-            user: undefined
+            config: mockConfig({}),
+            user,
+            sshKeys: [],
+            sessions: [],
+            homeCluster: "zzzzz",
+            localCluster: "",
+            loginCluster: "",
+            remoteHosts: {},
+            remoteHostsConfig: {}
         });
     });
 
@@ -50,18 +58,34 @@ describe('auth-reducer', () => {
             firstName: "John",
             lastName: "Doe",
             uuid: "uuid",
-            ownerUuid: "ownerUuid"
+            ownerUuid: "ownerUuid",
+            username: "username",
+            prefs: {},
+            isAdmin: false,
+            isActive: true
         };
 
         const state = reducer(initialState, authActions.USER_DETAILS_SUCCESS(user));
         expect(state).toEqual({
             apiToken: undefined,
+            config: mockConfig({}),
+            sshKeys: [],
+            sessions: [],
+            homeCluster: "uuid",
+            localCluster: "",
+            loginCluster: "",
+            remoteHosts: {},
+            remoteHostsConfig: {},
             user: {
                 email: "test@test.com",
                 firstName: "John",
                 lastName: "Doe",
                 uuid: "uuid",
                 ownerUuid: "ownerUuid",
+                username: "username",
+                prefs: {},
+                isAdmin: false,
+                isActive: true
             }
         });
     });