From 22762d7d848d2b435dd92599924f853cb19b1084 Mon Sep 17 00:00:00 2001 From: Fabio Formosa Date: Wed, 5 Oct 2022 00:43:18 +0200 Subject: [PATCH] #66 fixed lint errors --- quartz-manager-frontend/angular.json | 1 + quartz-manager-frontend/src/app/app.module.ts | 2 +- .../logs-panel/logs-panel.component.ts | 39 +++--- .../progress-panel.component.ts | 12 +- .../trigger-list.component.spec.ts | 3 +- .../trigger-list/trigger-list.component.ts | 27 ++-- .../src/app/model/SocketEndpoint.model.ts | 8 +- .../src/app/model/SocketOption.model.ts | 33 ++--- .../src/app/services/api.service.spec.ts | 126 +++++++++--------- .../src/app/services/api.service.ts | 16 +-- .../src/app/services/websocket.service.ts | 7 +- 11 files changed, 144 insertions(+), 130 deletions(-) diff --git a/quartz-manager-frontend/angular.json b/quartz-manager-frontend/angular.json index 481e9c6..e0a45cd 100644 --- a/quartz-manager-frontend/angular.json +++ b/quartz-manager-frontend/angular.json @@ -5,6 +5,7 @@ "projects": { "angular-spring-starter": { "root": "", + "prefix": "qrzmng", "sourceRoot": "src", "projectType": "application", "architect": { diff --git a/quartz-manager-frontend/src/app/app.module.ts b/quartz-manager-frontend/src/app/app.module.ts index 351a6ee..7b13b2e 100644 --- a/quartz-manager-frontend/src/app/app.module.ts +++ b/quartz-manager-frontend/src/app/app.module.ts @@ -3,7 +3,7 @@ import { NgModule, APP_INITIALIZER} from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { HttpClientModule } from '@angular/common/http'; -import {JWT_OPTIONS, JwtModule} from "@auth0/angular-jwt"; +import {JWT_OPTIONS, JwtModule} from '@auth0/angular-jwt'; // material import {MatIconRegistry} from '@angular/material/icon'; diff --git a/quartz-manager-frontend/src/app/components/logs-panel/logs-panel.component.ts b/quartz-manager-frontend/src/app/components/logs-panel/logs-panel.component.ts index 95dc4ee..a9dc720 100644 --- a/quartz-manager-frontend/src/app/components/logs-panel/logs-panel.component.ts +++ b/quartz-manager-frontend/src/app/components/logs-panel/logs-panel.component.ts @@ -1,7 +1,7 @@ -import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core'; -import { LogsWebsocketService, ApiService } from '../../services'; -import { Observable } from 'rxjs'; +import {LogsWebsocketService, ApiService} from '../../services'; +import {Observable} from 'rxjs'; @Component({ selector: 'logs-panel', @@ -10,39 +10,44 @@ import { Observable } from 'rxjs'; }) export class LogsPanelComponent implements OnInit { - MAX_LOGS : number = 30; + MAX_LOGS = 30; - logs : Array = new Array(); + logs = new Array(); constructor( private logsWebsocketService: LogsWebsocketService, - private apiService : ApiService - ) { } + private apiService: ApiService + ) { + } ngOnInit() { const obs = this.logsWebsocketService.getObservable() obs.subscribe({ - 'next' : this.onNewLogMsg, - 'error' : (err) => {console.log(err)} + 'next': this.onNewLogMsg, + 'error': (err) => { + console.log(err) + } }); } onNewLogMsg = (receivedMsg) => { - if(receivedMsg.type == 'SUCCESS') + if (receivedMsg.type === 'SUCCESS') { this._showNewLog(receivedMsg.message); - else if(receivedMsg.type == 'ERROR') - this._refreshSession(); //if websocket has been closed for session expiration, try to refresh it + } else if (receivedMsg.type === 'ERROR') { + this._refreshSession(); + } // if websocket has been closed for session expiration, try to refresh it }; _showNewLog = (logRecord) => { - if(this.logs.length > this.MAX_LOGS) + if (this.logs.length > this.MAX_LOGS) { this.logs.pop(); + } this.logs.unshift({ - time : logRecord.date, - type : logRecord.type, - msg : logRecord.message, - threadName : logRecord.threadName + time: logRecord.date, + type: logRecord.type, + msg: logRecord.message, + threadName: logRecord.threadName }); } diff --git a/quartz-manager-frontend/src/app/components/progress-panel/progress-panel.component.ts b/quartz-manager-frontend/src/app/components/progress-panel/progress-panel.component.ts index 324c51b..0e3ef54 100644 --- a/quartz-manager-frontend/src/app/components/progress-panel/progress-panel.component.ts +++ b/quartz-manager-frontend/src/app/components/progress-panel/progress-panel.component.ts @@ -19,8 +19,8 @@ import { Observable } from 'rxjs'; }) export class ProgressPanelComponent implements OnInit { - progress : any = {} - percentageStr : string + progress = {}; + percentageStr: string; // // Stream of messages // private subscription: Subscription; @@ -31,7 +31,7 @@ export class ProgressPanelComponent implements OnInit { // public mq: Array = []; - // private socketSubscription + // private socketSubscription constructor( private progressWebsocketService: ProgressWebsocketService, @@ -40,15 +40,15 @@ export class ProgressPanelComponent implements OnInit { ) { } onNewProgressMsg = (receivedMsg) => { - if (receivedMsg.type == 'SUCCESS') { - var newStatus = receivedMsg.message; + if (receivedMsg.type === 'SUCCESS') { + const newStatus = receivedMsg.message; this.progress = newStatus; this.percentageStr = this.progress.percentage + '%'; } } ngOnInit() { - let obs = this.progressWebsocketService.getObservable() + const obs = this.progressWebsocketService.getObservable() obs.subscribe({ 'next' : this.onNewProgressMsg, 'error' : (err) => {console.log(err)} diff --git a/quartz-manager-frontend/src/app/components/trigger-list/trigger-list.component.spec.ts b/quartz-manager-frontend/src/app/components/trigger-list/trigger-list.component.spec.ts index dddeab5..10df4b2 100644 --- a/quartz-manager-frontend/src/app/components/trigger-list/trigger-list.component.spec.ts +++ b/quartz-manager-frontend/src/app/components/trigger-list/trigger-list.component.spec.ts @@ -23,7 +23,8 @@ describe('TriggerListComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - imports: [MatCardModule, MatDialogModule, MatDividerModule, MatIconModule, MatListModule, HttpClientTestingModule, RouterTestingModule], + imports: [MatCardModule, MatDialogModule, MatDividerModule, + MatIconModule, MatListModule, HttpClientTestingModule, RouterTestingModule], declarations: [TriggerListComponent], providers: [TriggerService, ApiService, ConfigService] }).compileComponents(); diff --git a/quartz-manager-frontend/src/app/components/trigger-list/trigger-list.component.ts b/quartz-manager-frontend/src/app/components/trigger-list/trigger-list.component.ts index 9d85156..1d759dd 100644 --- a/quartz-manager-frontend/src/app/components/trigger-list/trigger-list.component.ts +++ b/quartz-manager-frontend/src/app/components/trigger-list/trigger-list.component.ts @@ -4,6 +4,13 @@ import {TriggerKey} from '../../model/triggerKey.model'; import {SimpleTrigger} from '../../model/simple-trigger.model'; import {MatDialog} from '@angular/material/dialog'; +@Component({ + template: 'Multiple jobs not supported yet - Coming Soon...', +}) +// tslint:disable-next-line:component-class-suffix +export class UnsupportedMultipleJobsDialog { +} + @Component({ selector: 'qrzmng-trigger-list', templateUrl: './trigger-list.component.html', @@ -26,7 +33,8 @@ export class TriggerListComponent implements OnInit { constructor( private triggerService: TriggerService, public dialog: MatDialog - ) { } + ) { + } ngOnInit() { this.loading = true; @@ -34,7 +42,7 @@ export class TriggerListComponent implements OnInit { } @Input() - set openedNewTriggerForm(triggerFormIsOpen: boolean){ + set openedNewTriggerForm(triggerFormIsOpen: boolean) { this.triggerFormIsOpen = triggerFormIsOpen; } @@ -61,20 +69,17 @@ export class TriggerListComponent implements OnInit { } onNewTriggerBtnClicked() { - if (this.triggerKeys && this.triggerKeys.length > 0) + if (this.triggerKeys && this.triggerKeys.length > 0) { this.dialog.open(UnsupportedMultipleJobsDialog) - else + } else { this.onNewTriggerClicked.emit(); + } } onNewTrigger(newTrigger: SimpleTrigger) { - this.newTriggers = [newTrigger, ...this.newTriggers]; - this.selectedTrigger = newTrigger.triggerKeyDTO; + this.newTriggers = [newTrigger, ...this.newTriggers]; + this.selectedTrigger = newTrigger.triggerKeyDTO; } } -@Component({ - template: 'Multiple jobs not supported yet - Coming Soon...', -}) -// tslint:disable-next-line:component-class-suffix -export class UnsupportedMultipleJobsDialog {} + diff --git a/quartz-manager-frontend/src/app/model/SocketEndpoint.model.ts b/quartz-manager-frontend/src/app/model/SocketEndpoint.model.ts index 6adb24f..12b36aa 100644 --- a/quartz-manager-frontend/src/app/model/SocketEndpoint.model.ts +++ b/quartz-manager-frontend/src/app/model/SocketEndpoint.model.ts @@ -1,4 +1,4 @@ -export class SocketEndpoint{ - client : any - stomp : any -} \ No newline at end of file +export class SocketEndpoint { + client: any + stomp: any +} diff --git a/quartz-manager-frontend/src/app/model/SocketOption.model.ts b/quartz-manager-frontend/src/app/model/SocketOption.model.ts index 529da9d..43de503 100644 --- a/quartz-manager-frontend/src/app/model/SocketOption.model.ts +++ b/quartz-manager-frontend/src/app/model/SocketOption.model.ts @@ -1,17 +1,20 @@ -export class SocketOption{ - socketUrl : string; - topicName : string; - brokerName : string; - reconnectionTimeout : number = 30000 +export class SocketOption { + socketUrl: string; + topicName: string; + brokerName: string; + reconnectionTimeout = 30000 - getAccessToken: Function = () => null; + getAccessToken: Function = () => null; - constructor(socketUrl : string, topicName : string, getAccessToken?: Function, brokerName : string = null, reconnectionTimeout : number = 30000){ - this.socketUrl = socketUrl; - this.topicName = topicName; - this.brokerName = brokerName; - this.reconnectionTimeout = reconnectionTimeout; - this.getAccessToken = getAccessToken || (() => null); - } - -} \ No newline at end of file + constructor(socketUrl: string, + topicName: string, + getAccessToken?: Function, + brokerName: string = null, + reconnectionTimeout: number = 30000) { + this.socketUrl = socketUrl; + this.topicName = topicName; + this.brokerName = brokerName; + this.reconnectionTimeout = reconnectionTimeout; + this.getAccessToken = getAccessToken || (() => null); + } +} diff --git a/quartz-manager-frontend/src/app/services/api.service.spec.ts b/quartz-manager-frontend/src/app/services/api.service.spec.ts index a67abde..042dfe2 100644 --- a/quartz-manager-frontend/src/app/services/api.service.spec.ts +++ b/quartz-manager-frontend/src/app/services/api.service.spec.ts @@ -1,83 +1,83 @@ -import { TestBed } from "@angular/core/testing"; -import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; -import { ApiService } from './api.service'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { Router} from '@angular/router'; +import {TestBed} from '@angular/core/testing'; +import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; +import {ApiService} from './api.service'; +import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {Router} from '@angular/router'; import {jest} from '@jest/globals' -class Data{ - name: string +class Data { + name: string } class HttpResponseMock { - constructor( - public body: unknown, - public opts?: { - headers?: - | HttpHeaders - | { - [name: string]: string | string[]; - }; - status?: number; - statusText?: string; - } - ) {} + constructor( + public body: unknown, + public opts?: { + headers?: + | HttpHeaders + | { + [name: string]: string | string[]; + }; + status?: number; + statusText?: string; + } + ) { } +} const routerSpy = jest.spyOn(Router.prototype, 'navigateByUrl'); describe('ApiServiceTest', () => { - let apiService: ApiService; - let httpClient: HttpClient; - let httpTestingController: HttpTestingController; + let apiService: ApiService; + let httpClient: HttpClient; + let httpTestingController: HttpTestingController; - const SAMPLE_URL = '/sample-url'; - const URL_401 = '/url-response-401'; - const testData: Data = {name: 'Test Data'}; + const SAMPLE_URL = '/sample-url'; + const URL_401 = '/url-response-401'; + const testData: Data = {name: 'Test Data'}; - beforeEach(() => { + beforeEach(() => { - TestBed.configureTestingModule({ - imports: [HttpClientTestingModule], - providers: [ApiService, {provide: Router, useValue: routerSpy}] - }); - apiService = TestBed.inject(ApiService); + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ApiService, {provide: Router, useValue: routerSpy}] + }); + apiService = TestBed.inject(ApiService); - httpClient = TestBed.inject(HttpClient); - httpTestingController = TestBed.inject(HttpTestingController); + httpClient = TestBed.inject(HttpClient); + httpTestingController = TestBed.inject(HttpTestingController); + }); + + it('should be created', (): void => { + expect(apiService).toBeTruthy(); + }); + + it('can test HttpClient.get', (): void => { + + apiService.get(SAMPLE_URL).subscribe((res: Data) => { + expect(res).toEqual(testData); }); - it('should be created', (): void => { - expect(apiService).toBeTruthy(); + const req = httpTestingController.expectOne(SAMPLE_URL) + expect(req.request.method).toEqual('GET'); + req.flush(new HttpResponseMock(testData)); + httpTestingController.verify(); + }); + + it('doesn\'t do anything if 401 is received', (): void => { + + apiService.get(URL_401).subscribe((res: Data) => { + expect(false); + }, (error) => { + expect(error.status).toBe(401); + expect(routerSpy).toHaveBeenCalledTimes(1); }); - it('can test HttpClient.get', (): void => { + const req = httpTestingController.expectOne(URL_401) + expect(req.request.method).toEqual('GET'); + req.flush(null, {status: 401, statusText: 'unauthenticated'}); + httpTestingController.verify(); + }); - apiService.get(SAMPLE_URL).subscribe((res: Data) => { - expect(res).toEqual(testData); - }); - - const req = httpTestingController.expectOne(SAMPLE_URL) - expect(req.request.method).toEqual('GET'); - req.flush(new HttpResponseMock(testData)); - httpTestingController.verify(); - }); - - it('doesn\'t do anything if 401 is received', (): void => { - - apiService.get(URL_401).subscribe((res: Data) => { - expect(false); - }, (error) => - { - expect(error.status).toBe(401); - expect(routerSpy).toHaveBeenCalledTimes(1); - }); - - const req = httpTestingController.expectOne(URL_401) - expect(req.request.method).toEqual('GET'); - req.flush(null, {status: 401, statusText: 'unauthenticated'}); - httpTestingController.verify(); - }); - -}); \ No newline at end of file +}); diff --git a/quartz-manager-frontend/src/app/services/api.service.ts b/quartz-manager-frontend/src/app/services/api.service.ts index 742c550..3b62914 100644 --- a/quartz-manager-frontend/src/app/services/api.service.ts +++ b/quartz-manager-frontend/src/app/services/api.service.ts @@ -18,9 +18,16 @@ export enum RequestMethod { @Injectable() export class ApiService { + headers = new HttpHeaders({ + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }); + + private jwtToken: string; + private static extractTokenFromHttpResponse(res: HttpResponse): string { let authorization: string = null; - let headers: HttpHeaders = res.headers; + const headers: HttpHeaders = res.headers; if (headers && headers.has('Authorization')) { authorization = headers.get('Authorization'); if (authorization.startsWith('Bearer ')) { @@ -30,13 +37,6 @@ export class ApiService { return authorization; } - headers = new HttpHeaders({ - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }); - - private jwtToken: string; - constructor(private http: HttpClient, private router: Router) { } diff --git a/quartz-manager-frontend/src/app/services/websocket.service.ts b/quartz-manager-frontend/src/app/services/websocket.service.ts index 55450e4..3615b51 100644 --- a/quartz-manager-frontend/src/app/services/websocket.service.ts +++ b/quartz-manager-frontend/src/app/services/websocket.service.ts @@ -14,7 +14,7 @@ export class WebsocketService { observableStompConnection: Observable; subscribers: Array = []; - subscriberIndex: number = 0; + subscriberIndex = 0; _messageIds: Array = []; @@ -26,9 +26,7 @@ export class WebsocketService { this.connect(); } - //TO BE OVERRIDEN getOptions = () => { - return {} } private createObservableSocket = () => { @@ -45,6 +43,7 @@ export class WebsocketService { removeFromSubscribers = (index) => { if (index > this.subscribers.length) { + // tslint:disable-next-line:max-line-length throw new Error(`Unexpected error removing subscriber from websocket, because index ${index} is greater than subscriber length ${this.subscribers.length}`); } this.subscribers.splice(index, 1); @@ -101,7 +100,7 @@ export class WebsocketService { }; send = (message) => { - var id = Math.floor(Math.random() * 1000000); + const id = Math.floor(Math.random() * 1000000); this._socket.stomp.send(this._options.brokerName, { priority: 9 }, JSON.stringify({