From 85d680b46f0c2771535150679856d88c13b3dfd7 Mon Sep 17 00:00:00 2001 From: Arash <102375769+Arash-Azarpoor@users.noreply.github.com> Date: Sat, 17 Aug 2024 13:39:26 +0330 Subject: [PATCH] refactor(Auth): lint (#27) --- src/app/components/sign-in/sign-in.component.spec.ts | 4 ++++ src/app/components/sign-in/sign-in.component.ts | 4 ++-- src/app/services/login/login.service.spec.ts | 2 +- src/app/services/login/login.service.ts | 6 +++--- src/app/services/notification/notification.service.ts | 5 ++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/app/components/sign-in/sign-in.component.spec.ts b/src/app/components/sign-in/sign-in.component.spec.ts index 07e6772..9ad8477 100644 --- a/src/app/components/sign-in/sign-in.component.spec.ts +++ b/src/app/components/sign-in/sign-in.component.spec.ts @@ -4,6 +4,8 @@ import { HttpClient, HttpHandler } from '@angular/common/http'; import { LoginService } from '../../services/login/login.service'; import { of } from 'rxjs'; import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { NotificationService } from '../../services/notification/notification.service'; +import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; describe('SignInComponent', () => { let component: SignInComponent; @@ -19,6 +21,8 @@ describe('SignInComponent', () => { HttpClient, HttpHandler, LoginService, + NotificationService, + provideAnimationsAsync(), { provide: LoginService, useValue: loginServiceSpy }, ], }).compileComponents(); diff --git a/src/app/components/sign-in/sign-in.component.ts b/src/app/components/sign-in/sign-in.component.ts index 7131714..f9acb69 100644 --- a/src/app/components/sign-in/sign-in.component.ts +++ b/src/app/components/sign-in/sign-in.component.ts @@ -55,7 +55,7 @@ export class SignInComponent { const { username, password } = this.signInForm.value; this.loginService.login(username, password).subscribe({ - next: (response: any) => { + next: (response: loginResponse) => { if (response.message === 'Login was successful!') { this.notificationService.createNotification( 'success', @@ -92,7 +92,7 @@ export class SignInComponent { } } - private triggerShakeAnimation(): void { + public triggerShakeAnimation(): void { this.inputFields.forEach((field) => { const element = field.nativeElement; const elementName = element.placeholder.toLowerCase().replace('-', ''); diff --git a/src/app/services/login/login.service.spec.ts b/src/app/services/login/login.service.spec.ts index 3da57cb..9c27f38 100644 --- a/src/app/services/login/login.service.spec.ts +++ b/src/app/services/login/login.service.spec.ts @@ -23,7 +23,7 @@ describe('LoginService', () => { it('SHOULD call post method with proper data WHEN submited', () => { // Arrange const spy = spyOn(httpClient, 'post').and.callThrough(); - const apiUrl = 'http://192.168.24.180:5293/api/Auth/Login'; + const apiUrl = 'http://192.168.24.166:5293/api/Auth/Login'; const body = { username: 'armin', password: '123' }; // Act service.login('armin', '123'); diff --git a/src/app/services/login/login.service.ts b/src/app/services/login/login.service.ts index 8f5f803..f2bb567 100644 --- a/src/app/services/login/login.service.ts +++ b/src/app/services/login/login.service.ts @@ -1,4 +1,4 @@ -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { loginResponse } from '../../models/login-response'; @@ -11,11 +11,11 @@ export class LoginService { constructor(private http: HttpClient) {} - login(username: string, password: string): Observable { + login(username: string, password: string): Observable { const body = { username, password }; const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); - return this.http.post(this.apiUrl, body, { headers }); + return this.http.post(this.apiUrl, body, { headers }); } } diff --git a/src/app/services/notification/notification.service.ts b/src/app/services/notification/notification.service.ts index 86d3231..fe7ae39 100644 --- a/src/app/services/notification/notification.service.ts +++ b/src/app/services/notification/notification.service.ts @@ -11,12 +11,11 @@ export class NotificationService { type: 'success' | 'error' | 'info' | 'warning', title: string, message: string, - duration: number = 3000, - style?: { [key: string]: string } + duration = 3000, ): void { this.notification.create(type, title, message, { nzDuration: duration, - nzStyle: style, + nzStyle: {borderRadius: '10px'}, }); } }