From: Daniel Kos Date: Wed, 6 Jun 2018 17:46:40 +0000 (+0200) Subject: Add login/logout tests X-Git-Tag: 1.0.0~1^2~1 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/5320327aa99710bb1cd1ce090fcb8e2b1d6de0da Add login/logout tests Feature #13563 Arvados-DCO-1.1-Signed-off-by: Daniel Kos : --- diff --git a/src/store/auth/auth-reducer.test.ts b/src/store/auth/auth-reducer.test.ts index 3d60c4f4..9290f57d 100644 --- a/src/store/auth/auth-reducer.test.ts +++ b/src/store/auth/auth-reducer.test.ts @@ -10,6 +10,7 @@ import { USER_FIRST_NAME_KEY, USER_LAST_NAME_KEY } from "../../services/auth-service/auth-service"; +import { API_HOST } from "../../common/server-api"; require('jest-localstorage-mock'); @@ -80,4 +81,38 @@ describe('auth-reducer', () => { expect(localStorage.getItem(API_TOKEN_KEY)).toBe("token"); }); + + it('should fire external url to login', () => { + const initialState = undefined; + + const location = { + href: 'http://localhost:3000', + protocol: 'http:', + host: 'localhost:3000' + }; + + global['window'] = { location }; + + authReducer(initialState, actions.LOGIN()); + expect(window.location.href).toBe( + `${API_HOST}/login?return_to=${location.protocol}//${location.host}/token` + ); + }); + + it('should fire external url to logout', () => { + const initialState = undefined; + + const location = { + href: 'http://localhost:3000', + protocol: 'http:', + host: 'localhost:3000' + }; + + global['window'] = { location }; + + authReducer(initialState, actions.LOGOUT()); + expect(window.location.href).toBe( + `${API_HOST}/logout?return_to=${location.protocol}//${location.host}` + ); + }); }); diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts index 730312f7..c5a48564 100644 --- a/src/store/auth/auth-reducer.ts +++ b/src/store/auth/auth-reducer.ts @@ -22,7 +22,7 @@ const authReducer = (state: AuthState = {}, action: AuthAction) => { INIT: () => { const user = authService.getUser(); const token = authService.getApiToken(); - return { user, apiToken: token }; + return {user, apiToken: token}; }, LOGIN: () => { authService.login();