Add login/logout tests
authorDaniel Kos <daniel.kos@contractors.roche.com>
Wed, 6 Jun 2018 17:46:40 +0000 (19:46 +0200)
committerDaniel Kos <daniel.kos@contractors.roche.com>
Wed, 6 Jun 2018 17:46:40 +0000 (19:46 +0200)
Feature #13563

Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos@contractors.roche.com>:

src/store/auth/auth-reducer.test.ts
src/store/auth/auth-reducer.ts

index 3d60c4f400fb1c0fb6ee8f10e4e11a1327d00eb3..9290f57d6bcf281851e4d11cd48662d8dabc4389 100644 (file)
@@ -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}`
+        );
+    });
 });
index 730312f7ce1ce88e71422638fe6a437c8fec4bf3..c5a485648f40e49029aead8bbfc23222eb7718d2 100644 (file)
@@ -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();