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