1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import authReducer from "./auth-reducer";
6 import actions from "./auth-action";
12 } from "../../services/auth-service/auth-service";
14 require('jest-localstorage-mock');
16 describe('auth-reducer', () => {
21 it('should return default state on initialisation', () => {
22 const initialState = undefined;
23 const state = authReducer(initialState, actions.INIT());
24 expect(state).toEqual({
30 it('should read user and api token from local storage on init if they are there', () => {
31 const initialState = undefined;
33 localStorage.setItem(API_TOKEN_KEY, "token");
34 localStorage.setItem(USER_EMAIL_KEY, "test@test.com");
35 localStorage.setItem(USER_FIRST_NAME_KEY, "John");
36 localStorage.setItem(USER_LAST_NAME_KEY, "Doe");
38 const state = authReducer(initialState, actions.INIT());
39 expect(state).toEqual({
42 email: "test@test.com",
49 it('should store token in local storage', () => {
50 const initialState = undefined;
52 const state = authReducer(initialState, actions.SAVE_API_TOKEN("token"));
53 expect(state).toEqual({
58 expect(localStorage.getItem(API_TOKEN_KEY)).toBe("token");
61 it('should set user details on success fetch', () => {
62 const initialState = undefined;
65 email: "test@test.com",
71 const state = authReducer(initialState, actions.USER_DETAILS_SUCCESS(userDetails));
72 expect(state).toEqual({
75 email: "test@test.com",
81 expect(localStorage.getItem(API_TOKEN_KEY)).toBe("token");