Add typescript paths to top level folders
[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
11 describe('auth-reducer', () => {
12     let reducer: (state: AuthState | undefined, action: AuthAction) => any;
13
14     beforeAll(() => {
15         localStorage.clear();
16         reducer = authReducer(createServices("/arvados/v1"));
17     });
18
19     it('should correctly initialise state', () => {
20         const initialState = undefined;
21         const user = {
22             email: "test@test.com",
23             firstName: "John",
24             lastName: "Doe",
25             uuid: "uuid",
26             ownerUuid: "ownerUuid"
27         };
28         const state = reducer(initialState, authActions.INIT({user, token: "token"}));
29         expect(state).toEqual({
30             apiToken: "token",
31             user
32         });
33     });
34
35     it('should save api token', () => {
36         const initialState = undefined;
37
38         const state = reducer(initialState, authActions.SAVE_API_TOKEN("token"));
39         expect(state).toEqual({
40             apiToken: "token",
41             user: undefined
42         });
43     });
44
45     it('should set user details on success fetch', () => {
46         const initialState = undefined;
47
48         const user = {
49             email: "test@test.com",
50             firstName: "John",
51             lastName: "Doe",
52             uuid: "uuid",
53             ownerUuid: "ownerUuid"
54         };
55
56         const state = reducer(initialState, authActions.USER_DETAILS_SUCCESS(user));
57         expect(state).toEqual({
58             apiToken: undefined,
59             user: {
60                 email: "test@test.com",
61                 firstName: "John",
62                 lastName: "Doe",
63                 uuid: "uuid",
64                 ownerUuid: "ownerUuid",
65             }
66         });
67     });
68 });