From 661a9aaed653cd8b08e27294de3711cf0363ce28 Mon Sep 17 00:00:00 2001 From: Jimmy Jaramillo Date: Thu, 25 Aug 2022 08:46:50 -0500 Subject: [PATCH 1/5] TTA-142: Alphabetically sort list of users on reports (#925) Co-authored-by: Jimmy Jaramillo --- .../time-entries-table.component.spec.ts | 6 +++--- .../time-entries-table/time-entries-table.component.ts | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts index 6e84b0fc8..01f49ae06 100644 --- a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts +++ b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts @@ -212,10 +212,10 @@ describe('Reports Page', () => { it('the sume of hours of entries selected is equal to {hours:0, minutes:0, seconds:0}', () => { let checked = true; - let {hours, minutes, seconds}:TotalHours = component.sumHoursEntriesSelected(timeEntryList[0], checked); + let {hours, minutes, seconds}: TotalHours = component.sumHoursEntriesSelected(timeEntryList[0], checked); checked = false; - ({hours, minutes,seconds} = component.sumHoursEntriesSelected(timeEntryList[0], checked)); - expect({hours, minutes, seconds}).toEqual({hours:0, minutes:0, seconds:0}); + ({hours, minutes, seconds} = component.sumHoursEntriesSelected(timeEntryList[0], checked)); + expect({hours, minutes, seconds}).toEqual({hours: 0, minutes: 0, seconds: 0}); }); it('should export data with the correct format', () => { diff --git a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts index 7709e94a7..419958560 100644 --- a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts +++ b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts @@ -69,7 +69,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn }, ], columnDefs: [{ type: 'date', targets: 2}, {orderable: false, targets: [0]}], - order: [[1,'asc'],[2,'desc'],[4,'desc']] + order: [[1, 'asc'], [2, 'desc'], [4, 'desc']] }; dtTrigger: Subject = new Subject(); @ViewChild(DataTableDirective, { static: false }) @@ -79,7 +79,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn rerenderTableSubscription: Subscription; resultSum: TotalHours; resultSumEntriesSelected: TotalHours; - resultSumEntriesSelected$:Observable; + resultSumEntriesSelected$: Observable; totalHoursSubscription: Subscription; dateTimeOffset: ParseDateTimeOffset; @@ -96,7 +96,9 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn this.actionsSubject$ .pipe(filter((action: any) => action.type === UserActionTypes.LOAD_USERS_SUCCESS)) .subscribe((action) => { - this.users = action.payload; + const sortUsers = [...action.payload]; + sortUsers.sort((a, b) => a.name.localeCompare(b.name)); + this.users = sortUsers; }); } From e08c0250eff5506eada615d513fb77b2ee7d59c5 Mon Sep 17 00:00:00 2001 From: Rodolfo <105673045+rodolfoIOET@users.noreply.github.com> Date: Fri, 26 Aug 2022 15:28:16 -0500 Subject: [PATCH 2/5] TTA-145-refactor-login-ui-v-2 (#927) * refactor: TTA-145 Refactor login ui v2 * TTA-145 removing not needed import script * TTA-145 removing not needed tests Co-authored-by: Jimmy Jaramillo --- src/app/app.module.ts | 18 +---- src/app/modules/login/login.component.html | 17 +++- src/app/modules/login/login.component.spec.ts | 23 ------ src/app/modules/login/login.component.ts | 78 +++++++++++++------ .../login/services/login.service.spec.ts | 6 -- .../modules/login/services/login.service.ts | 7 -- 6 files changed, 70 insertions(+), 79 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d0c44bfbf..391675003 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -49,7 +49,7 @@ import { ProjectEffects } from './modules/customer-management/components/project import { TechnologyEffects } from './modules/shared/store/technology.effects'; import { ProjectTypeEffects } from './modules/customer-management/components/projects-type/store/project-type.effects'; import { reducers } from './reducers'; -import { CLIENT_URL, environment } from '../environments/environment'; +import { environment } from '../environments/environment'; import { EnvironmentType } from '../environments/enum'; import { CustomerComponent } from './modules/customer-management/pages/customer.component'; // tslint:disable-next-line: max-line-length @@ -91,8 +91,6 @@ import { CalendarComponent } from './modules/time-entries/components/calendar/ca import { DropdownComponent } from './modules/shared/components/dropdown/dropdown.component'; import { NgSelectModule } from '@ng-select/ng-select'; import { DarkModeComponent } from './modules/shared/components/dark-mode/dark-mode.component'; -import { SocialLoginModule, SocialAuthServiceConfig } from 'angularx-social-login'; -import { GoogleLoginProvider } from 'angularx-social-login'; import { SearchUserComponent } from './modules/shared/components/search-user/search-user.component'; import { TimeRangeCustomComponent } from './modules/reports/components/time-range-custom/time-range-custom.component'; import { TimeRangeHeaderComponent } from './modules/reports/components/time-range-custom/time-range-header/time-range-header.component'; @@ -201,7 +199,6 @@ const maskConfig: Partial = { useFactory: adapterFactory, }), NgSelectModule, - SocialLoginModule ], providers: [ { @@ -211,18 +208,7 @@ const maskConfig: Partial = { }, DatePipe, CookieService, - { - provide: 'SocialAuthServiceConfig', - useValue: { - autoLogin: false, - providers: [ - { - id: GoogleLoginProvider.PROVIDER_ID, - provider: new GoogleLoginProvider(CLIENT_URL) - } - ] - } as SocialAuthServiceConfig, - } + {provide: Window, useValue: window} ], bootstrap: [AppComponent], }) diff --git a/src/app/modules/login/login.component.html b/src/app/modules/login/login.component.html index 745fce8a8..9ad2d90d3 100644 --- a/src/app/modules/login/login.component.html +++ b/src/app/modules/login/login.component.html @@ -7,8 +7,19 @@

Please log in

- diff --git a/src/app/modules/login/login.component.spec.ts b/src/app/modules/login/login.component.spec.ts index 03a439a68..717bde7a1 100644 --- a/src/app/modules/login/login.component.spec.ts +++ b/src/app/modules/login/login.component.spec.ts @@ -100,22 +100,6 @@ describe('LoginComponent', () => { expect(featureToggleCookiesService.setCookies).toHaveBeenCalled(); })); - it('should sign up or login with google if is not logged-in into the app Locally', inject([Router], (router: Router) => { - spyOn(loginService, 'isLogin').and.returnValue(of(false)); - spyOn(loginService, 'setLocalStorage').and.returnValue(); - spyOn(loginService, 'getUser').and.returnValue(of({token: ''})); - spyOn(loginService, 'setCookies').and.returnValue(); - spyOn(loginService, 'signIn').and.returnValue(); - spyOn(featureToggleCookiesService, 'setCookies').and.returnValue(featureToggleCookiesService.setCookies()); - - component.ngOnInit(); - component.loginWithGoogle(); - - expect(loginService.signIn).toHaveBeenCalled(); - expect(loginService.setCookies).toHaveBeenCalled(); - expect(featureToggleCookiesService.setCookies).toHaveBeenCalled(); - })); - it('should not sign-up or login with google if is already logged-in into the app on Production', inject([Router], (router: Router) => { spyOn(azureAdB2CService, 'isLogin').and.returnValue(true); spyOn(router, 'navigate').and.stub(); @@ -124,11 +108,4 @@ describe('LoginComponent', () => { expect(router.navigate).toHaveBeenCalledWith(['']); })); - it('should not sign-up or login with google if is already logged-in into the app Locally', inject([Router], (router: Router) => { - spyOn(loginService, 'isLogin').and.returnValue(of(true)); - spyOn(router, 'navigate').and.stub(); - component.loginWithGoogle(); - expect(loginService.isLogin).toHaveBeenCalled(); - expect(router.navigate).toHaveBeenCalledWith(['']); - })); }); diff --git a/src/app/modules/login/login.component.ts b/src/app/modules/login/login.component.ts index 0c6493947..1e26d139a 100644 --- a/src/app/modules/login/login.component.ts +++ b/src/app/modules/login/login.component.ts @@ -1,46 +1,85 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, NgZone } from '@angular/core'; import { AzureAdB2CService } from './services/azure.ad.b2c.service'; import { Router } from '@angular/router'; import { FeatureToggleCookiesService } from '../shared/feature-toggles/feature-toggle-cookies/feature-toggle-cookies.service'; -import { SocialAuthService, SocialUser } from 'angularx-social-login'; -import { environment } from 'src/environments/environment'; +import { environment, CLIENT_URL } from 'src/environments/environment'; import { EnvironmentType } from 'src/environments/enum'; import { LoginService } from './services/login.service'; import { UserService } from '../user/services/user.service'; +declare global { + interface Window { + handleCredentialResponse: (response: any) => void; + } +} + @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.scss'], }) export class LoginComponent implements OnInit { - socialUser: SocialUser; isProduction = environment.production === EnvironmentType.TT_PROD_LEGACY; + cliendId = CLIENT_URL; + auth2: any; + constructor( private azureAdB2CService: AzureAdB2CService, private router: Router, private featureToggleCookiesService: FeatureToggleCookiesService, - private socialAuthService: SocialAuthService, private loginService?: LoginService, - private userService?: UserService + private userService?: UserService, + private ngZone?: NgZone ) {} + + googleAuthSDK() { + + (window)['googleSDKLoaded'] = () => { + (window)['gapi'].load('auth2', () => { + this.auth2 = (window)['gapi'].auth2.init({ + client_id: this.cliendId, + plugin_name:'login', + cookiepolicy: 'single_host_origin', + scope: 'profile email' + }); + }); + } + (function (d, s, id) { + var js, gjs = d.getElementsByTagName(s)[1]; + if (d.getElementById(id)) { return; } + js = d.createElement(s); js.id = id; + js.src = "https://accounts.google.com/gsi/client"; + gjs.parentNode.insertBefore(js, gjs); + }(document, 'script', 'async defer')); + } + ngOnInit() { - this.socialAuthService.authState.subscribe((user) => { - if (user != null) { - this.featureToggleCookiesService.setCookies(); - this.loginService.setLocalStorage('idToken', user.idToken); - this.loginService.getUser(user.idToken).subscribe((response) => { + + this.googleAuthSDK(); + if(this.isProduction && this.azureAdB2CService.isLogin()){ + this.router.navigate(['']); + } else { + this.loginService.isLogin().subscribe(isLogin => { + if (isLogin) { + this.router.navigate(['']); + } + }); + } + window.handleCredentialResponse = (response) => { + const {credential = ''} = response; + this.featureToggleCookiesService.setCookies(); + this.loginService.setLocalStorage('idToken', credential); + this.loginService.getUser(credential).subscribe((response) => { this.loginService.setCookies(); const tokenObject = JSON.stringify(response); const tokenJson = JSON.parse(tokenObject); this.loginService.setLocalStorage('user', tokenJson.token); - this.router.navigate(['']); - }); - } - }); + this.ngZone.run(() => this.router.navigate([''])); + }); + } } login(): void { @@ -62,13 +101,4 @@ export class LoginComponent implements OnInit { } } - loginWithGoogle() { - this.loginService.isLogin().subscribe(isLogin => { - if (isLogin) { - this.router.navigate(['']); - } else { - this.loginService.signIn(); - } - }); - } } diff --git a/src/app/modules/login/services/login.service.spec.ts b/src/app/modules/login/services/login.service.spec.ts index fa558e35e..6530662b0 100644 --- a/src/app/modules/login/services/login.service.spec.ts +++ b/src/app/modules/login/services/login.service.spec.ts @@ -114,17 +114,11 @@ describe('LoginService', () => { }); }); - it('should login with social angularx-social-login', () => { - service.signIn(); - expect(socialAuthService.signIn).toHaveBeenCalled(); - }); - it('should logout with social angularx-social-login', () => { spyOn(cookieService, 'deleteAll').and.returnValue(); service.logout(); - expect(socialAuthService.signOut).toHaveBeenCalled(); expect(localStorage.clear).toHaveBeenCalled(); expect(cookieService.deleteAll).toHaveBeenCalled(); }); diff --git a/src/app/modules/login/services/login.service.ts b/src/app/modules/login/services/login.service.ts index 212aa4b88..8a0869829 100644 --- a/src/app/modules/login/services/login.service.ts +++ b/src/app/modules/login/services/login.service.ts @@ -1,6 +1,5 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { GoogleLoginProvider, SocialAuthService } from 'angularx-social-login'; import { CookieService } from 'ngx-cookie-service'; import { EnvironmentType, UserEnum } from 'src/environments/enum'; import { environment } from 'src/environments/environment'; @@ -20,18 +19,12 @@ export class LoginService { constructor( private http?: HttpClient, private cookieService?: CookieService, - private socialAuthService?: SocialAuthService ) { this.baseUrl = `${environment.timeTrackerApiUrl}/users`; this.helper = new JwtHelperService(); } - signIn() { - this.socialAuthService.signIn(GoogleLoginProvider.PROVIDER_ID); - } - logout() { - this.socialAuthService.signOut(); this.cookieService.deleteAll(); localStorage.clear(); } From fa976cb3357377e42a574c7377f1aa720c619383 Mon Sep 17 00:00:00 2001 From: Jimmy Jaramillo Date: Tue, 30 Aug 2022 09:07:32 -0500 Subject: [PATCH 3/5] fix: TTA-147 fixing column format 'time in' in the reports page (#929) Co-authored-by: Jimmy Jaramillo --- .../time-entries-table.component.spec.ts | 16 +--------------- .../time-entries-table.component.ts | 4 +--- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts index 01f49ae06..30c2d7882 100644 --- a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts +++ b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts @@ -17,10 +17,8 @@ describe('Reports Page', () => { let fixture: ComponentFixture; let store: MockStore; let getReportDataSourceSelectorMock; - let durationTime: number; let row: number; let node: number; - let decimalValidator: RegExp; const timeEntry: Entry = { id: '123', start_date: new Date(), @@ -102,10 +100,8 @@ describe('Reports Page', () => { ); beforeEach(() => { - durationTime = new Date().setHours(5, 30); row = 0; node = 0; - decimalValidator = /^\d+\.\d{0,2}$/; }); it('component should be created', async () => { @@ -155,16 +151,6 @@ describe('Reports Page', () => { }); }); - it('The data should be displayed as a multiple of hour when column is equal to 4', () => { - const column = 4; - expect(component.bodyExportOptions(durationTime, row, column, node)).toMatch(decimalValidator); - }); - - it('The data should not be displayed as a multiple of hour when column is different of 4', () => { - const column = 5; - expect(component.bodyExportOptions(durationTime, row, column, node)).toBe(durationTime.toString()); - }); - it('The link Ticket must not contain the ticket URL enclosed with < > when export a file csv, excel or PDF', () => { const entry = 'https://TT-392-uri'; const column = 0; @@ -247,7 +233,7 @@ describe('Reports Page', () => { '19', 'user@ioet.com', '07/01/2022', - '9.00', + '09:00', '09:00', '18:00', 'Project_Name', diff --git a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts index 419958560..7f7135bbd 100644 --- a/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts +++ b/src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts @@ -144,9 +144,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn } bodyExportOptions(data, row, column, node) { - const dataFormated = data.toString().replace(/<((.|\n){0,200}?)>/gi, ''); - const durationColumnIndex = 4; - return column === durationColumnIndex ? moment.duration(dataFormated).asHours().toFixed(2) : dataFormated; + return data.toString().replace(/<((.|\n){0,200}?)>/gi, '') || ''; } From 6486c510e91d63e5824c3b3afda87fe4080ee9ea Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 30 Aug 2022 14:09:59 +0000 Subject: [PATCH 4/5] chore(release): 1.75.16 [skip ci]nn --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index bd368b686..38f2f2867 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "time-tracker", - "version": "1.75.1", + "version": "1.75.16", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5e8c5d645..81ef73c68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "time-tracker", - "version": "1.75.1", + "version": "1.75.16", "scripts": { "preinstall": "npx npm-force-resolutions", "ng": "ng", From 321cae2da9ddfacde75add75d556ee0ada3fee66 Mon Sep 17 00:00:00 2001 From: Jimmy Jaramillo Date: Mon, 22 Aug 2022 15:05:20 -0500 Subject: [PATCH 5/5] fix: TTA-141 Fix broken tests and test coverage in the UI --- src/app/modules/login/login.component.spec.ts | 16 +++++ src/app/modules/login/login.component.ts | 10 ++-- .../login/services/login.service.spec.ts | 58 ++++++++++++++++--- .../time-clock/pages/time-clock.component.ts | 2 +- .../time-clock/services/entry.service.ts | 3 +- .../modules/time-clock/store/entry.reducer.ts | 2 +- .../time-clock/store/entry.selectors.spec.ts | 2 +- .../user/services/user-info.service.spec.ts | 9 +++ 8 files changed, 85 insertions(+), 17 deletions(-) diff --git a/src/app/modules/login/login.component.spec.ts b/src/app/modules/login/login.component.spec.ts index 717bde7a1..9de359249 100644 --- a/src/app/modules/login/login.component.spec.ts +++ b/src/app/modules/login/login.component.spec.ts @@ -8,12 +8,15 @@ import { FeatureToggleCookiesService } from '../shared/feature-toggles/feature-t import { LoginService } from './services/login.service'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { SocialAuthService } from 'angularx-social-login'; +import { UserService } from '../user/services/user.service'; + describe('LoginComponent', () => { let component: LoginComponent; let fixture: ComponentFixture; let azureAdB2CService: AzureAdB2CService; let loginService: LoginService; + let userService: UserService; let featureToggleCookiesService: FeatureToggleCookiesService; const azureAdB2CServiceStub = { @@ -38,6 +41,16 @@ describe('LoginComponent', () => { } }; + const userTest = { + name: 'user', + email: 'test@test.com', + roles: ['admin'], + groups: ['admin'], + id: 'user_id', + tenant_id: 'tenant_test', + deleted: 'no', + }; + const featureToggleCookiesServiceStub = { setCookies() { return null; @@ -66,6 +79,7 @@ describe('LoginComponent', () => { fixture.detectChanges(); azureAdB2CService = TestBed.inject(AzureAdB2CService); loginService = TestBed.inject(LoginService); + userService = TestBed.inject(UserService); featureToggleCookiesService = TestBed.inject(FeatureToggleCookiesService); }); @@ -90,6 +104,7 @@ describe('LoginComponent', () => { spyOn(azureAdB2CService, 'setCookies').and.returnValue(); spyOn(azureAdB2CService, 'signIn').and.returnValue(of(() => {})); spyOn(azureAdB2CService, 'getUserId').and.returnValue('userId_123'); + spyOn(userService, 'loadUser').withArgs('userId_123').and.returnValue(of(userTest)); spyOn(featureToggleCookiesService, 'setCookies').and.returnValue(featureToggleCookiesService.setCookies()); component.login(); @@ -98,6 +113,7 @@ describe('LoginComponent', () => { expect(azureAdB2CService.setCookies).toHaveBeenCalled(); expect(azureAdB2CService.getUserId).toHaveBeenCalled(); expect(featureToggleCookiesService.setCookies).toHaveBeenCalled(); + expect(userService.loadUser).toHaveBeenCalledWith('userId_123'); })); it('should not sign-up or login with google if is already logged-in into the app on Production', inject([Router], (router: Router) => { diff --git a/src/app/modules/login/login.component.ts b/src/app/modules/login/login.component.ts index 1e26d139a..738a9ec17 100644 --- a/src/app/modules/login/login.component.ts +++ b/src/app/modules/login/login.component.ts @@ -89,14 +89,14 @@ export class LoginComponent implements OnInit { this.azureAdB2CService.signIn().subscribe(() => { this.featureToggleCookiesService.setCookies(); this.azureAdB2CService.setCookies(); - const userId = this.azureAdB2CService.getUserId() + const userId = this.azureAdB2CService.getUserId(); this.userService.loadUser(userId).subscribe((user) => { - const user_groups = { + const userGroups = { groups: user.groups - } - this.loginService.setLocalStorage('user', JSON.stringify(user_groups)); + }; + this.loginService.setLocalStorage('user', JSON.stringify(userGroups)); this.router.navigate(['']); - }) + }); }); } } diff --git a/src/app/modules/login/services/login.service.spec.ts b/src/app/modules/login/services/login.service.spec.ts index 6530662b0..94e246cc6 100644 --- a/src/app/modules/login/services/login.service.spec.ts +++ b/src/app/modules/login/services/login.service.spec.ts @@ -1,4 +1,5 @@ -import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { HttpClient } from '@angular/common/http'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { TestBed } from '@angular/core/testing'; import { JwtHelperService } from '@auth0/angular-jwt'; import { SocialAuthService } from 'angularx-social-login'; @@ -9,11 +10,11 @@ import { LoginService } from './login.service'; describe('LoginService', () => { let service: LoginService; - let httpMock: HttpTestingController; let cookieService: CookieService; let socialAuthService: SocialAuthService; let account; const socialAuthServiceStub = jasmine.createSpyObj('SocialAuthService', ['signOut', 'signIn']); + const httpClientSpy = jasmine.createSpyObj('HttpClient', ['post', 'get']); const cookieStoreStub = {}; const helper = new JwtHelperService(); const getAccountInfo = () => { @@ -26,11 +27,11 @@ describe('LoginService', () => { providers: [ { providers: CookieService, useValue: cookieStoreStub }, { provide: SocialAuthService, useValue: socialAuthServiceStub }, + { provide: HttpClient, useValue: httpClientSpy } ], }); service = TestBed.inject(LoginService); cookieService = TestBed.inject(CookieService); - httpMock = TestBed.inject(HttpTestingController); socialAuthService = TestBed.inject(SocialAuthService); account = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImFiYyIsIm5hbWUiOiJhYmMiLCJlbWFpbCI6ImFiYyIsImdyb3VwcyI6WyJhYmMiXX0.UNxyDT8XzXJhI1F3LySBU7TJlpENPUPHj8my7Obw2ZM'; let store = {}; @@ -49,6 +50,7 @@ describe('LoginService', () => { spyOn(localStorage, 'setItem').and.callFake(mockLocalStorage.setItem); spyOn(localStorage, 'clear').and.callFake(mockLocalStorage.clear); localStorage.setItem('user', account); + localStorage.setItem('user2', '"test_token_123"'); }); it('should be created', () => { @@ -90,12 +92,16 @@ describe('LoginService', () => { }); it('load a user by sending a token using POST', () => { + const token = 'test_123'; service.baseUrl = '/users'; - service.getUser('token').subscribe(); - - const loadUserRequest = httpMock.expectOne(`${service.baseUrl}/login`); - expect(loadUserRequest.request.method).toBe('POST'); - }); + const mockSuccessDataPost = { + SUCCESS: true, + data: {} + }; + httpClientSpy.post.and.returnValue(of(mockSuccessDataPost)); + service.getUser(token).subscribe(); + expect(httpClientSpy.post).toHaveBeenCalled(); + }); it('should return true when user is Login', () => { spyOn(cookieService, 'check').and.returnValue(true); @@ -122,4 +128,40 @@ describe('LoginService', () => { expect(localStorage.clear).toHaveBeenCalled(); expect(cookieService.deleteAll).toHaveBeenCalled(); }); + + it('should call cookieService when app is isLegacyProd', () => { + service.isLegacyProd = true; + service.localStorageKey = 'user2'; + spyOn(cookieService, 'check').and.returnValue(true); + spyOn(service, 'isValidToken').and.returnValue(of(true)); + service.isLogin().subscribe(isLogin => { + expect(cookieService.check).toHaveBeenCalled(); + }); + }); + + it('should call JSON parse when app is isLegacyProd', () => { + spyOn(JSON, 'parse').and.returnValue('test_user_123'); + service.isLegacyProd = true; + service.localStorageKey = 'user2'; + service.getUserId(); + service.getName(); + service.getUserEmail(); + service.getUserGroup(); + expect(JSON.parse).toHaveBeenCalled(); + }); + + it('should call setLocalStorage when there is a new_token ', () => { + spyOn(cookieService, 'check').and.returnValue(true); + spyOn(service, 'setLocalStorage'); + const token = 'test123'; + service.baseUrl = '/users'; + const mockSuccessDataPost = { + SUCCESS: true, + new_token: 'test_token' + }; + httpClientSpy.post.and.returnValue(of(mockSuccessDataPost)); + service.isValidToken(token).subscribe(); + expect(service.setLocalStorage).toHaveBeenCalled(); + expect(cookieService.check).toHaveBeenCalled(); + }); }); diff --git a/src/app/modules/time-clock/pages/time-clock.component.ts b/src/app/modules/time-clock/pages/time-clock.component.ts index c24f2b6ca..42078d5f3 100644 --- a/src/app/modules/time-clock/pages/time-clock.component.ts +++ b/src/app/modules/time-clock/pages/time-clock.component.ts @@ -43,7 +43,7 @@ export class TimeClockComponent implements OnInit, OnDestroy { }else{ this.loginService.isLogin().subscribe(isLogin => { this.username = isLogin ? this.loginService.getName() : ''; - }) + }); } this.storeSubscription = this.store.pipe(select(getActiveTimeEntry)).subscribe((activeTimeEntry) => { this.activeTimeEntry = activeTimeEntry; diff --git a/src/app/modules/time-clock/services/entry.service.ts b/src/app/modules/time-clock/services/entry.service.ts index 125041202..e8b9a1b63 100644 --- a/src/app/modules/time-clock/services/entry.service.ts +++ b/src/app/modules/time-clock/services/entry.service.ts @@ -46,7 +46,8 @@ export class EntryService { } stopEntryRunning(idEntry: string): Observable { - return (this.urlInProductionLegacy ? this.http.post(`${this.baseUrl}/${idEntry}/stop`, null) : this.http.put(`${this.baseUrl}/stop`, null) ); + return (this.urlInProductionLegacy ? + this.http.post(`${this.baseUrl}/${idEntry}/stop`, null) : this.http.put(`${this.baseUrl}/stop`, null) ); } restartEntry(idEntry: string): Observable { diff --git a/src/app/modules/time-clock/store/entry.reducer.ts b/src/app/modules/time-clock/store/entry.reducer.ts index d3af715f8..023328efb 100644 --- a/src/app/modules/time-clock/store/entry.reducer.ts +++ b/src/app/modules/time-clock/store/entry.reducer.ts @@ -266,7 +266,7 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi return { ...state, isLoading: true, - resultSumEntriesSelected:{hours:0, minutes:0, seconds:0}, + resultSumEntriesSelected: {hours: 0, minutes: 0, seconds: 0}, reportDataSource: { data: [], isLoading: true diff --git a/src/app/modules/time-clock/store/entry.selectors.spec.ts b/src/app/modules/time-clock/store/entry.selectors.spec.ts index 06c3c02e2..1d5c088c0 100644 --- a/src/app/modules/time-clock/store/entry.selectors.spec.ts +++ b/src/app/modules/time-clock/store/entry.selectors.spec.ts @@ -55,7 +55,7 @@ describe('Entry selectors', () => { }); it('should select resultSumEntriesSelected', () => { - const resultSumEntriesSelected:TotalHours = { hours:0, minutes:0, seconds:0 }; + const resultSumEntriesSelected: TotalHours = { hours: 0, minutes: 0, seconds: 0 }; const entryState = { resultSumEntriesSelected }; expect(selectors.getResultSumEntriesSelected.projector(entryState)).toEqual(resultSumEntriesSelected); diff --git a/src/app/modules/user/services/user-info.service.spec.ts b/src/app/modules/user/services/user-info.service.spec.ts index 79d2ef782..04f17c586 100644 --- a/src/app/modules/user/services/user-info.service.spec.ts +++ b/src/app/modules/user/services/user-info.service.spec.ts @@ -75,4 +75,13 @@ describe('UserInfoService', () => { }); }); + it('should return true if is Admin and isLegacyProduction', () => { + const groupsTT = {groups: ['fake-admin', 'fake-admin-tt']}; + spyOn(mockLoginService, 'getLocalStorage').and.returnValue(JSON.stringify(groupsTT)); + service.isLegacyProduction = true; + service.isMemberOf('fake-admin').subscribe((value) => { + expect(value).toEqual(true); + }); + }); + });