diff --git a/src/app/api/models/errorResponse.ts b/src/app/api/models/errorResponse.ts index e6ac857..73925d2 100644 --- a/src/app/api/models/errorResponse.ts +++ b/src/app/api/models/errorResponse.ts @@ -1,10 +1,10 @@ -import { HttpErrorResponse } from "@angular/common/http"; +import { HttpErrorResponse } from '@angular/common/http'; interface Error { - message: string; - reason: string; + message: string; + reason: string; } export interface OverriddenHttpErrorResponse extends HttpErrorResponse { - error: Error; + error: Error; } diff --git a/src/app/api/models/user.ts b/src/app/api/models/user.ts index ef11bde..25f4c7e 100644 --- a/src/app/api/models/user.ts +++ b/src/app/api/models/user.ts @@ -1,4 +1,4 @@ export interface User { - email: string; - password: string; -} \ No newline at end of file + email: string; + password: string; +} diff --git a/src/app/api/signUpService/sign-up.service.spec.ts b/src/app/api/signUpService/sign-up.service.spec.ts index bb6af63..fb4634c 100644 --- a/src/app/api/signUpService/sign-up.service.spec.ts +++ b/src/app/api/signUpService/sign-up.service.spec.ts @@ -1,9 +1,10 @@ -import { TestBed } from '@angular/core/testing'; import { provideHttpClient } from '@angular/common/http'; import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; -import { SignUpService } from './sign-up.service'; -import { User } from '../models/user'; +import { TestBed } from '@angular/core/testing'; + import { OverriddenHttpErrorResponse } from '../models/errorResponse'; +import { User } from '../models/user'; +import { SignUpService } from './sign-up.service'; describe('SignUpService', () => { let service: SignUpService; @@ -11,10 +12,7 @@ describe('SignUpService', () => { beforeEach(() => { TestBed.configureTestingModule({ - providers: [ - provideHttpClient(), - provideHttpClientTesting(), - ], + providers: [provideHttpClient(), provideHttpClientTesting()], }); service = TestBed.inject(SignUpService); httpTestingController = TestBed.inject(HttpTestingController); @@ -32,7 +30,7 @@ describe('SignUpService', () => { const userData: User = { email: 'test@test.com', password: 'Abcdefghigk' }; service.signUp(userData).subscribe((res) => { expect(res).toEqual({}); - done() + done(); }); const req = httpTestingController.expectOne('/api/signup'); @@ -43,7 +41,7 @@ describe('SignUpService', () => { it('should correctly handle error if user already exist', (done) => { const userData: User = { email: 'iam@exist.com', password: 'Passwordtest' }; - + service.signUp(userData).subscribe({ next: () => fail('expected error from server'), error: (err: OverriddenHttpErrorResponse) => { @@ -52,16 +50,19 @@ describe('SignUpService', () => { expect(err.error.reason).toBe('invalidUniqueKey'); expect(err.ok).toBe(false); done(); - } + }, }); - + const req = httpTestingController.expectOne('/api/signup'); expect(req.request.method).toBe('POST'); expect(req.request.body).toEqual(userData); - - req.flush({ - message: 'User already exists', - reason: 'invalidUniqueKey' - }, { status: 400, statusText: 'Bad Request' }); + + req.flush( + { + message: 'User already exists', + reason: 'invalidUniqueKey', + }, + { status: 400, statusText: 'Bad Request' }, + ); }); }); diff --git a/src/app/api/signUpService/sign-up.service.ts b/src/app/api/signUpService/sign-up.service.ts index 71b9073..65aca40 100644 --- a/src/app/api/signUpService/sign-up.service.ts +++ b/src/app/api/signUpService/sign-up.service.ts @@ -1,6 +1,8 @@ import { HttpClient } from '@angular/common/http'; import { inject, Injectable } from '@angular/core'; + import { Observable } from 'rxjs'; + import { User } from '../models/user'; @Injectable({ @@ -21,4 +23,4 @@ export class SignUpService { console.error(err.error.message); -> errors }, }); -*/ \ No newline at end of file +*/ diff --git a/src/app/app.config.ts b/src/app/app.config.ts index 0741a64..ba9e00c 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -1,7 +1,7 @@ +import { provideHttpClient } from '@angular/common/http'; import { ApplicationConfig, provideExperimentalZonelessChangeDetection } from '@angular/core'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; import { provideRouter, withComponentInputBinding, withInMemoryScrolling, withViewTransitions } from '@angular/router'; -import { provideHttpClient } from '@angular/common/http'; import routes from './app.routes'; @@ -15,7 +15,7 @@ const appConfig: ApplicationConfig = { withInMemoryScrolling({ scrollPositionRestoration: 'enabled' }), ), provideAnimationsAsync(), - provideHttpClient() + provideHttpClient(), ], }; export default appConfig; diff --git a/src/main.ts b/src/main.ts index cc796c4..8b2e2c8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,11 +1,12 @@ import { bootstrapApplication } from '@angular/platform-browser'; import { startServer } from '@planess/train-a-backend'; + import { AppComponent } from './app/app.component'; import appConfig from './app/app.config'; startServer() .then(() => bootstrapApplication(AppComponent, appConfig)) - .catch((err) => { - throw new Error(String(err)) + .catch((err) => { + throw new Error(String(err)); });