Skip to content

Commit 470a043

Browse files
author
Abigail Cabascango
committed
fix: TTA-115 Merge master into TTA-115
2 parents 940f4b8 + 3dc8359 commit 470a043

File tree

18 files changed

+159
-61
lines changed

18 files changed

+159
-61
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ We strongly recommend that you install it using Node Version Management [https:/
3535

3636
Angular CLI is a Command Line Interface (CLI) to speed up your development with Angular.
3737

38-
Run `npm install -g @angular/cli` to install Angular CLI
38+
Run `npm install -g @angular/cli` to install Angular CLI.
3939

4040
### Docker
4141

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "time-tracker",
3-
"version": "1.75.1",
3+
"version": "1.75.19",
44
"scripts": {
55
"preinstall": "npx npm-force-resolutions",
66
"ng": "ng",
@@ -111,12 +111,12 @@
111111
"husky": {
112112
"hooks": {
113113
"commit-msg": "commit-message-validator",
114-
"pre-commit": "ng lint && ng test --watch=false --browsers=ChromeHeadless"
114+
"pre-commit": "ng lint"
115115
}
116116
},
117117
"config": {
118118
"commit-message-validator": {
119-
"pattern": "^(fix: TT-|feat: TT-|perf: TT-|build: TT-|ci: TT-|docs: TT-|refactor: TT-|style: TT-|test: TT-|code-smell: TT-)[0-9].*",
119+
"pattern": "^(fix: TTA-|feat: TTA-|perf: TTA-|build: TTA-|ci: TTA-|docs: TTA-|refactor: TTA-|style: TTA-|test: TTA-|code-smell: TTA-)[0-9].*",
120120
"errorMessage": "Your commit message needs to start with fix: , feat:, or perf: followed by any commit message, e.g. fix: TT-43 any commit message."
121121
}
122122
},

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import { FeatureToggleCookiesService } from '../shared/feature-toggles/feature-t
88
import { LoginService } from './services/login.service';
99
import { HttpClientTestingModule } from '@angular/common/http/testing';
1010
import { SocialAuthService } from 'angularx-social-login';
11+
import { UserService } from '../user/services/user.service';
12+
1113

1214
describe('LoginComponent', () => {
1315
let component: LoginComponent;
1416
let fixture: ComponentFixture<LoginComponent>;
1517
let azureAdB2CService: AzureAdB2CService;
1618
let loginService: LoginService;
19+
let userService: UserService;
1720
let featureToggleCookiesService: FeatureToggleCookiesService;
1821

1922
const azureAdB2CServiceStub = {
@@ -38,6 +41,16 @@ describe('LoginComponent', () => {
3841
}
3942
};
4043

44+
const userTest = {
45+
name: 'user',
46+
47+
roles: ['admin'],
48+
groups: ['admin'],
49+
id: 'user_id',
50+
tenant_id: 'tenant_test',
51+
deleted: 'no',
52+
};
53+
4154
const featureToggleCookiesServiceStub = {
4255
setCookies() {
4356
return null;
@@ -66,6 +79,7 @@ describe('LoginComponent', () => {
6679
fixture.detectChanges();
6780
azureAdB2CService = TestBed.inject(AzureAdB2CService);
6881
loginService = TestBed.inject(LoginService);
82+
userService = TestBed.inject(UserService);
6983
featureToggleCookiesService = TestBed.inject(FeatureToggleCookiesService);
7084
});
7185

@@ -90,6 +104,7 @@ describe('LoginComponent', () => {
90104
spyOn(azureAdB2CService, 'setCookies').and.returnValue();
91105
spyOn(azureAdB2CService, 'signIn').and.returnValue(of(() => {}));
92106
spyOn(azureAdB2CService, 'getUserId').and.returnValue('userId_123');
107+
spyOn(userService, 'loadUser').withArgs('userId_123').and.returnValue(of(userTest));
93108
spyOn(featureToggleCookiesService, 'setCookies').and.returnValue(featureToggleCookiesService.setCookies());
94109

95110
component.login();
@@ -98,6 +113,7 @@ describe('LoginComponent', () => {
98113
expect(azureAdB2CService.setCookies).toHaveBeenCalled();
99114
expect(azureAdB2CService.getUserId).toHaveBeenCalled();
100115
expect(featureToggleCookiesService.setCookies).toHaveBeenCalled();
116+
expect(userService.loadUser).toHaveBeenCalledWith('userId_123');
101117
}));
102118

103119
it('should not sign-up or login with google if is already logged-in into the app on Production', inject([Router], (router: Router) => {

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,35 @@ export class LoginComponent implements OnInit {
3636

3737

3838
googleAuthSDK() {
39+
const sdkLoaded = 'googleSDKLoaded';
40+
const gapi = 'gapi';
3941

40-
(<any>window)['googleSDKLoaded'] = () => {
41-
(<any>window)['gapi'].load('auth2', () => {
42-
this.auth2 = (<any>window)['gapi'].auth2.init({
42+
(window as any)[sdkLoaded] = () => {
43+
(window as any)[gapi].load('auth2', () => {
44+
this.auth2 = ( window as any)[gapi].auth2.init({
4345
client_id: this.cliendId,
44-
plugin_name:'login',
46+
plugin_name: 'login',
4547
cookiepolicy: 'single_host_origin',
4648
scope: 'profile email'
4749
});
4850
});
49-
}
50-
(function (d, s, id) {
51-
var js, gjs = d.getElementsByTagName(s)[1];
51+
};
52+
53+
(async (d, s, id) => {
54+
const keyGoogle = 'src';
55+
const gjs = d.getElementsByTagName(s)[1];
56+
let js = gjs;
5257
if (d.getElementById(id)) { return; }
5358
js = d.createElement(s); js.id = id;
54-
js.src = "https://accounts.google.com/gsi/client";
59+
js[keyGoogle] = 'https://accounts.google.com/gsi/client';
5560
gjs.parentNode.insertBefore(js, gjs);
56-
}(document, 'script', 'async defer'));
61+
})(document, 'script', 'async defer');
5762
}
5863

5964
ngOnInit() {
6065

6166
this.googleAuthSDK();
62-
if(this.isProduction && this.azureAdB2CService.isLogin()){
67+
if (this.isProduction && this.azureAdB2CService.isLogin()) {
6368
this.router.navigate(['']);
6469
} else {
6570
this.loginService.isLogin().subscribe(isLogin => {
@@ -72,14 +77,14 @@ export class LoginComponent implements OnInit {
7277
const {credential = ''} = response;
7378
this.featureToggleCookiesService.setCookies();
7479
this.loginService.setLocalStorage('idToken', credential);
75-
this.loginService.getUser(credential).subscribe((response) => {
80+
this.loginService.getUser(credential).subscribe((resp) => {
7681
this.loginService.setCookies();
77-
const tokenObject = JSON.stringify(response);
82+
const tokenObject = JSON.stringify(resp);
7883
const tokenJson = JSON.parse(tokenObject);
7984
this.loginService.setLocalStorage('user', tokenJson.token);
8085
this.ngZone.run(() => this.router.navigate(['']));
8186
});
82-
}
87+
};
8388
}
8489

8590
login(): void {
@@ -89,14 +94,14 @@ export class LoginComponent implements OnInit {
8994
this.azureAdB2CService.signIn().subscribe(() => {
9095
this.featureToggleCookiesService.setCookies();
9196
this.azureAdB2CService.setCookies();
92-
const userId = this.azureAdB2CService.getUserId()
97+
const userId = this.azureAdB2CService.getUserId();
9398
this.userService.loadUser(userId).subscribe((user) => {
94-
const user_groups = {
99+
const userGroups = {
95100
groups: user.groups
96-
}
97-
this.loginService.setLocalStorage('user', JSON.stringify(user_groups));
101+
};
102+
this.loginService.setLocalStorage('user', JSON.stringify(userGroups));
98103
this.router.navigate(['']);
99-
})
104+
});
100105
});
101106
}
102107
}

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

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
1+
import { HttpClient } from '@angular/common/http';
2+
import { HttpClientTestingModule } from '@angular/common/http/testing';
23
import { TestBed } from '@angular/core/testing';
34
import { JwtHelperService } from '@auth0/angular-jwt';
45
import { SocialAuthService } from 'angularx-social-login';
@@ -9,11 +10,11 @@ import { LoginService } from './login.service';
910

1011
describe('LoginService', () => {
1112
let service: LoginService;
12-
let httpMock: HttpTestingController;
1313
let cookieService: CookieService;
1414
let socialAuthService: SocialAuthService;
1515
let account;
1616
const socialAuthServiceStub = jasmine.createSpyObj('SocialAuthService', ['signOut', 'signIn']);
17+
const httpClientSpy = jasmine.createSpyObj('HttpClient', ['post', 'get']);
1718
const cookieStoreStub = {};
1819
const helper = new JwtHelperService();
1920
const getAccountInfo = () => {
@@ -26,11 +27,11 @@ describe('LoginService', () => {
2627
providers: [
2728
{ providers: CookieService, useValue: cookieStoreStub },
2829
{ provide: SocialAuthService, useValue: socialAuthServiceStub },
30+
{ provide: HttpClient, useValue: httpClientSpy }
2931
],
3032
});
3133
service = TestBed.inject(LoginService);
3234
cookieService = TestBed.inject(CookieService);
33-
httpMock = TestBed.inject(HttpTestingController);
3435
socialAuthService = TestBed.inject(SocialAuthService);
3536
account = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImFiYyIsIm5hbWUiOiJhYmMiLCJlbWFpbCI6ImFiYyIsImdyb3VwcyI6WyJhYmMiXX0.UNxyDT8XzXJhI1F3LySBU7TJlpENPUPHj8my7Obw2ZM';
3637
let store = {};
@@ -49,6 +50,7 @@ describe('LoginService', () => {
4950
spyOn(localStorage, 'setItem').and.callFake(mockLocalStorage.setItem);
5051
spyOn(localStorage, 'clear').and.callFake(mockLocalStorage.clear);
5152
localStorage.setItem('user', account);
53+
localStorage.setItem('user2', '"test_token_123"');
5254
});
5355

5456
it('should be created', () => {
@@ -90,12 +92,16 @@ describe('LoginService', () => {
9092
});
9193

9294
it('load a user by sending a token using POST', () => {
95+
const token = 'test_123';
9396
service.baseUrl = '/users';
94-
service.getUser('token').subscribe();
95-
96-
const loadUserRequest = httpMock.expectOne(`${service.baseUrl}/login`);
97-
expect(loadUserRequest.request.method).toBe('POST');
98-
});
97+
const mockSuccessDataPost = {
98+
SUCCESS: true,
99+
data: {}
100+
};
101+
httpClientSpy.post.and.returnValue(of(mockSuccessDataPost));
102+
service.getUser(token).subscribe();
103+
expect(httpClientSpy.post).toHaveBeenCalled();
104+
});
99105

100106
it('should return true when user is Login', () => {
101107
spyOn(cookieService, 'check').and.returnValue(true);
@@ -122,4 +128,40 @@ describe('LoginService', () => {
122128
expect(localStorage.clear).toHaveBeenCalled();
123129
expect(cookieService.deleteAll).toHaveBeenCalled();
124130
});
131+
132+
it('should call cookieService when app is isLegacyProd', () => {
133+
service.isLegacyProd = true;
134+
service.localStorageKey = 'user2';
135+
spyOn(cookieService, 'check').and.returnValue(true);
136+
spyOn(service, 'isValidToken').and.returnValue(of(true));
137+
service.isLogin().subscribe(isLogin => {
138+
expect(cookieService.check).toHaveBeenCalled();
139+
});
140+
});
141+
142+
it('should call JSON parse when app is isLegacyProd', () => {
143+
spyOn(JSON, 'parse').and.returnValue('test_user_123');
144+
service.isLegacyProd = true;
145+
service.localStorageKey = 'user2';
146+
service.getUserId();
147+
service.getName();
148+
service.getUserEmail();
149+
service.getUserGroup();
150+
expect(JSON.parse).toHaveBeenCalled();
151+
});
152+
153+
it('should call setLocalStorage when there is a new_token ', () => {
154+
spyOn(cookieService, 'check').and.returnValue(true);
155+
spyOn(service, 'setLocalStorage');
156+
const token = 'test123';
157+
service.baseUrl = '/users';
158+
const mockSuccessDataPost = {
159+
SUCCESS: true,
160+
new_token: 'test_token'
161+
};
162+
httpClientSpy.post.and.returnValue(of(mockSuccessDataPost));
163+
service.isValidToken(token).subscribe();
164+
expect(service.setLocalStorage).toHaveBeenCalled();
165+
expect(cookieService.check).toHaveBeenCalled();
166+
});
125167
});

src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ describe('Reports Page', () => {
1717
let fixture: ComponentFixture<TimeEntriesTableComponent>;
1818
let store: MockStore<EntryState>;
1919
let getReportDataSourceSelectorMock;
20-
let durationTime: number;
2120
let row: number;
2221
let node: number;
23-
let decimalValidator: RegExp;
2422
const timeEntry: Entry = {
2523
id: '123',
2624
start_date: new Date(),
@@ -102,10 +100,8 @@ describe('Reports Page', () => {
102100
);
103101

104102
beforeEach(() => {
105-
durationTime = new Date().setHours(5, 30);
106103
row = 0;
107104
node = 0;
108-
decimalValidator = /^\d+\.\d{0,2}$/;
109105
});
110106

111107
it('component should be created', async () => {
@@ -155,16 +151,6 @@ describe('Reports Page', () => {
155151
});
156152
});
157153

158-
it('The data should be displayed as a multiple of hour when column is equal to 4', () => {
159-
const column = 4;
160-
expect(component.bodyExportOptions(durationTime, row, column, node)).toMatch(decimalValidator);
161-
});
162-
163-
it('The data should not be displayed as a multiple of hour when column is different of 4', () => {
164-
const column = 5;
165-
expect(component.bodyExportOptions(durationTime, row, column, node)).toBe(durationTime.toString());
166-
});
167-
168154
it('The link Ticket must not contain the ticket URL enclosed with < > when export a file csv, excel or PDF', () => {
169155
const entry = '<a _ngcontent-vlm-c151="" class="is-url">https://TT-392-uri</a>';
170156
const column = 0;
@@ -247,7 +233,7 @@ describe('Reports Page', () => {
247233
'19',
248234
249235
'07/01/2022',
250-
'9.00',
236+
'09:00',
251237
'09:00',
252238
'18:00',
253239
'Project_Name',

src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
105105
ngOnInit(): void {
106106
this.rerenderTableSubscription = this.reportDataSource$.subscribe((ds) => {
107107
this.totalHoursSubscription = this.resultSumEntriesSelected$.subscribe((actTotalHours) => {
108-
this.resultSumEntriesSelected = actTotalHours ;
108+
this.resultSumEntriesSelected = actTotalHours;
109109
this.totalTimeSelected = moment.duration(0);
110110
});
111111
this.sumDates(ds.data);
@@ -144,9 +144,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
144144
}
145145

146146
bodyExportOptions(data, row, column, node) {
147-
const dataFormated = data.toString().replace(/<((.|\n){0,200}?)>/gi, '');
148-
const durationColumnIndex = 4;
149-
return column === durationColumnIndex ? moment.duration(dataFormated).asHours().toFixed(2) : dataFormated;
147+
return data.toString().replace(/<((.|\n){0,200}?)>/gi, '') || '';
150148
}
151149

152150

src/app/modules/time-clock/components/entry-fields/entry-fields.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<input
1818
(blur)="onSubmit()"
1919
type="text"
20-
placeholder="Enter your ticker number"
20+
placeholder="Enter your ticket number"
2121
id="uri"
2222
formControlName="uri"
2323
class="url-ticket-input form-control"

src/app/modules/time-clock/pages/time-clock.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class TimeClockComponent implements OnInit, OnDestroy {
4343
}else{
4444
this.loginService.isLogin().subscribe(isLogin => {
4545
this.username = isLogin ? this.loginService.getName() : '';
46-
})
46+
});
4747
}
4848
this.storeSubscription = this.store.pipe(select(getActiveTimeEntry)).subscribe((activeTimeEntry) => {
4949
this.activeTimeEntry = activeTimeEntry;

0 commit comments

Comments
 (0)