Skip to content

Commit 6c09fce

Browse files
author
Rodrigo Lins
committed
fix: TTA-180 fixing tests
1 parent 0d6d4ab commit 6c09fce

File tree

9 files changed

+34
-13
lines changed

9 files changed

+34
-13
lines changed

src/app/modules/login/login.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ <h3>Please log in</h3>
1111
<button (click)="login() " class="btn btn-primary">login</button>
1212
</div>
1313
<div *ngIf="!isProduction">
14-
<button class="btn btn-primary"><a href="{{loginAuth()}}">Login</a></button>
14+
<a href="{{loginAuth()}}"><button class="btn btn-primary">Login</button></a>
1515
</div>
1616
</div>

src/app/modules/login/login.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class LoginComponent implements OnInit {
2323
isProduction = environment.production === EnvironmentType.TT_PROD_LEGACY;
2424
cliendId = CLIENT_URL;
2525
authUrl = environment.authUrl;
26+
authAppName = environment.authAppName;
2627
auth2: any;
2728

2829

@@ -67,7 +68,7 @@ export class LoginComponent implements OnInit {
6768
}
6869

6970
loginAuth(): string {
70-
return `${this.authUrl}/authn/login/timeTracker`;
71+
return `${this.authUrl}/authn/login/${this.authAppName}`;
7172
}
7273

7374
}

src/app/modules/login/services/login.service.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { HttpClient } from '@angular/common/http';
22
import { HttpClientTestingModule } from '@angular/common/http/testing';
3+
import { RouterTestingModule } from '@angular/router/testing';
34
import { TestBed } from '@angular/core/testing';
5+
import { Router } from '@angular/router';
46
import { JwtHelperService } from '@auth0/angular-jwt';
57
import { SocialAuthService } from 'angularx-social-login';
68
import { CookieService } from 'ngx-cookie-service';
@@ -12,6 +14,7 @@ describe('LoginService', () => {
1214
let service: LoginService;
1315
let cookieService: CookieService;
1416
let socialAuthService: SocialAuthService;
17+
let router: Router;
1518
let account;
1619
const socialAuthServiceStub = jasmine.createSpyObj('SocialAuthService', ['signOut', 'signIn']);
1720
const httpClientSpy = jasmine.createSpyObj('HttpClient', ['post', 'get']);
@@ -23,16 +26,17 @@ describe('LoginService', () => {
2326

2427
beforeEach(() => {
2528
TestBed.configureTestingModule({
26-
imports: [HttpClientTestingModule],
29+
imports: [HttpClientTestingModule, RouterTestingModule.withRoutes([])],
2730
providers: [
2831
{ providers: CookieService, useValue: cookieStoreStub },
2932
{ provide: SocialAuthService, useValue: socialAuthServiceStub },
30-
{ provide: HttpClient, useValue: httpClientSpy }
33+
{ provide: HttpClient, useValue: httpClientSpy },
3134
],
3235
});
3336
service = TestBed.inject(LoginService);
3437
cookieService = TestBed.inject(CookieService);
3538
socialAuthService = TestBed.inject(SocialAuthService);
39+
router = TestBed.inject(Router);
3640
account = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImFiYyIsIm5hbWUiOiJhYmMiLCJlbWFpbCI6ImFiYyIsImdyb3VwcyI6WyJhYmMiXX0.UNxyDT8XzXJhI1F3LySBU7TJlpENPUPHj8my7Obw2ZM';
3741
let store = {};
3842
const mockLocalStorage = {
@@ -121,7 +125,9 @@ describe('LoginService', () => {
121125
});
122126

123127
it('should logout with social angularx-social-login', () => {
128+
service.router = router;
124129
spyOn(cookieService, 'deleteAll').and.returnValue();
130+
spyOn(service, 'invalidateSessionCookie').and.returnValue(of(true));
125131

126132
service.logout();
127133

src/app/modules/login/services/login.service.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { HttpClient } from '@angular/common/http';
2-
import { Injectable, NgZone } from '@angular/core';
2+
import { Injectable } from '@angular/core';
33
import { CookieService } from 'ngx-cookie-service';
44
import { EnvironmentType, UserEnum } from 'src/environments/enum';
55
import { environment } from 'src/environments/environment';
66
import { JwtHelperService } from '@auth0/angular-jwt';
77
import { map } from 'rxjs/operators';
8-
import { Observable, of } from 'rxjs';
8+
import { of } from 'rxjs';
99
import { Router } from '@angular/router';
1010

1111
@Injectable({
@@ -17,7 +17,6 @@ export class LoginService {
1717
isLegacyProd: boolean = environment.production === EnvironmentType.TT_PROD_LEGACY;
1818
localStorageKey = this.isLegacyProd ? 'user2' : 'user';
1919
router: Router;
20-
ngZone: NgZone;
2120

2221
constructor(
2322
private http?: HttpClient,
@@ -29,7 +28,14 @@ export class LoginService {
2928

3029
logout() {
3130
localStorage.clear();
32-
this.http.post(`${this.baseUrl}/logout`, null, { withCredentials: true }).subscribe();
31+
this.cookieService.deleteAll();
32+
this.invalidateSessionCookie().subscribe(() => {
33+
this.router.navigate(['login']);
34+
});
35+
}
36+
37+
invalidateSessionCookie() {
38+
return this.http.post(`${this.baseUrl}/logout`, null, { withCredentials: true });
3339
}
3440

3541
isLogin() {

src/app/modules/shared/components/sidebar/sidebar.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<h3 class="font-poppins text-base ml-4 pl-3 -mt-6 text-left" >{{ item.text }}</h3>
1818
</a>
1919
<div class="bg-whiteTW pt-2 absolute bottom-4 dark:bg-grayTW-dark flex justify-center items-center">
20-
<a class="flex pl-4 text-blackTW hover:text-grayTW dark:text-whiteTW" href="#">
20+
<button class="logout flex pl-4 text-blackTW hover:text-grayTW dark:text-whiteTW" (click)="logout()">
2121
<em class="fas fa-sign-out-alt"></em>
22-
<span class="font-poppins pl-3 font-medium dark:text-whiteTW" (click)="logout()">Sign out</span>
23-
</a>
22+
<span class="font-poppins pl-3 font-medium dark:text-whiteTW">Sign out</span>
23+
</button>
2424
<app-dark-mode class="ml-4"></app-dark-mode>
2525
</div>
2626
</div>

src/app/modules/shared/components/sidebar/sidebar.component.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ body {
44
overflow-x: hidden;
55
}
66

7+
button.logout:active {
8+
outline: none;
9+
}
10+
711
#sidebar-wrapper {
812
min-height: 100vh;
913
margin-left: -15rem;
@@ -76,4 +80,4 @@ body {
7680
height: -webkit-calc(100vh - 1vh);
7781
height: -o-calc(100vh - 1vh);
7882
height: calc(100vh - 1vh);
79-
}
83+
}

src/app/modules/shared/components/sidebar/sidebar.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, OnDestroy, OnInit } from '@angular/core';
22
import { ItemSidebar } from './models/item-sidebar.model';
33
import { NavigationStart, Router } from '@angular/router';
4-
import { Observable, Subscription } from 'rxjs';
4+
import { Observable, Subscription, timer } from 'rxjs';
55
import { filter, map } from 'rxjs/operators';
66
import { UserInfoService } from 'src/app/modules/user/services/user-info.service';
77
import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service';
@@ -42,6 +42,7 @@ export class SidebarComponent implements OnInit, OnDestroy {
4242

4343
ngOnDestroy(): void {
4444
this.sidebarItems$.unsubscribe();
45+
this.logout();
4546
}
4647

4748
toggleSideBar() {

src/environments/environment.prod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export const environment = {
44
production: EnvironmentType.TT_PROD,
55
timeTrackerApiUrl: process.env["API_URL"],
66
stackexchangeApiUrl: 'https://api.stackexchange.com',
7+
authUrl: 'https://api.auth.ioet.com',
8+
authAppName: 'timeTracker',
79
};
810

911
export const AUTHORITY = process.env["AUTHORITY"];

src/environments/environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const environment = {
99
timeTrackerApiUrl: process.env['API_URL'],
1010
stackexchangeApiUrl: 'https://api.stackexchange.com',
1111
authUrl: 'https://uat-backend.auth.ioet.com',
12+
authAppName: 'timeTracker',
1213
};
1314

1415
export const AUTHORITY = process.env['AUTHORITY'];

0 commit comments

Comments
 (0)