Skip to content

Commit

Permalink
refactor(Auth): lint (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arash-Azarpoor authored Aug 17, 2024
1 parent 3a801b6 commit 85d680b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/app/components/sign-in/sign-in.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +21,8 @@ describe('SignInComponent', () => {
HttpClient,
HttpHandler,
LoginService,
NotificationService,
provideAnimationsAsync(),
{ provide: LoginService, useValue: loginServiceSpy },
],
}).compileComponents();
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/sign-in/sign-in.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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('-', '');
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/login/login.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions src/app/services/login/login.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,11 +11,11 @@ export class LoginService {

constructor(private http: HttpClient) {}

login(username: string, password: string): Observable<any> {
login(username: string, password: string): Observable<loginResponse | HttpErrorResponse> {
const body = { username, password };

const headers = new HttpHeaders({ 'Content-Type': 'application/json' });

return this.http.post<any>(this.apiUrl, body, { headers });
return this.http.post<loginResponse | HttpErrorResponse>(this.apiUrl, body, { headers });
}
}
5 changes: 2 additions & 3 deletions src/app/services/notification/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
});
}
}

0 comments on commit 85d680b

Please sign in to comment.