@@ -111,4 +111,40 @@ describe('Login', () => {
111111 expect ( auth . isAuthed ( ) ) . toBe ( false ) ;
112112 } ) ;
113113 } ) ;
114+
115+ describe ( 'visiting /login with an existing session' , ( ) => {
116+ it ( 'should redirect an already-authenticated user to /reports and keep the session' , ( ) => {
117+ // Arrange
118+ var { $location, $scope, auth } = createContext ( ) ;
119+ auth . loginByToken ( 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0ODQ2MzAzMTgsImV4cCI6MTQ4NzIyMjMxOCwiaWF0IjoxNDg0NjMwMzE4LCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjM0NzUxIiwic3ViIjoxMDAzLCJ1bmlxdWVfbmFtZSI6ImFtb3NjaGluaUBtYWtpbmdzZW5zZS5jb20iLCJyZWxheV9hY2NvdW50cyI6WyJhbW9zY2hpbmktbWFraW5nc2Vuc2UiXSwicmVsYXlfdG9rZW5fdmVyc2lvbiI6IjEuMC4wLWJldGE1In0.dQh20ukVSCP0rNXMWBh2DlPQXbP0uTaYzadRDNPXECI9lvCsgDKNXc2bToXAUQDeXw90kbHliVF-kCueW4gQLPBtMJOcHQFv6LfgspsG2jue2iMwoBC1q6UB_4xFlGoyhkRjldnQUV0oqBTzhFdXuTvQz53kRPiqILCHkd4FLl4KliBgdaDRwWz-HIjJwinMpnv_7V38CNvHlHo-q2XU0MnE3CsGXmWGoAgzN7rbeQPgI9azHXpbaUPh9n_4zjCydOSBC5tx7MtEAx3ivfFYImBPp2T2vUM-F5AwRh7hl_lMUvyQLal0S_spoT0XMGy8YhnjxXLoZeVRisWbxBmucQ' ) ;
120+ expect ( auth . isAuthed ( ) ) . toBe ( true ) ;
121+ expect ( auth . isTemporarilyAuthed ( ) ) . toBe ( false ) ;
122+
123+ // Act
124+ $location . path ( '/login' ) ;
125+ $scope . $apply ( ) ;
126+
127+ // Assert
128+ expect ( $location . path ( ) ) . toBe ( '/reports' ) ;
129+ expect ( auth . isAuthed ( ) ) . toBe ( true ) ;
130+ expect ( auth . getUserName ( ) ) . toBe ( 'amoschini@makingsense.com' ) ;
131+ } ) ;
132+
133+ it ( 'should clear the temporal session and stay on /login when the user is only temporally authed' , ( ) => {
134+ // Arrange
135+ var { $location, $scope, auth } = createContext ( ) ;
136+ auth . loginByToken ( 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYmYiOjE0ODQ2MjAxMjEsImV4cCI6MTUyODIwNDQzNCwiaWF0IjoxNDg0NjIwMTIxLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjM0NzUxIiwidW5pcXVlX25hbWUiOiJhbW9zY2hpbmkrMUBtYWtpbmdzZW5zZS5jb20iLCJyZWxheV9vbl9wYXNzd29yZF9yZXNldCI6dHJ1ZSwicmVsYXlfdGVtcG9yYWxfdG9rZW4iOnRydWV9.gecKe6J6zQL7mHceq42fgjdpTUcVeQEBtSNp0mbI6Ig' ) ;
137+ expect ( auth . isAuthed ( ) ) . toBe ( true ) ;
138+ expect ( auth . isTemporarilyAuthed ( ) ) . toBe ( true ) ;
139+
140+ // Act
141+ $location . path ( '/login' ) ;
142+ $scope . $apply ( ) ;
143+
144+ // Assert
145+ expect ( $location . path ( ) ) . toBe ( '/login' ) ;
146+ expect ( auth . isAuthed ( ) ) . toBe ( false ) ;
147+ expect ( auth . isTemporarilyAuthed ( ) ) . toBe ( false ) ;
148+ } ) ;
149+ } ) ;
114150} ) ;
0 commit comments