diff --git a/modules/data-access/product/src/lib/state/cart/cart.service.spec.ts b/modules/data-access/product/src/lib/state/cart/cart.service.spec.ts new file mode 100644 index 0000000..cb4a750 --- /dev/null +++ b/modules/data-access/product/src/lib/state/cart/cart.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { CartService } from './cart.service'; + +describe('CartService', () => { + let service: CartService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(CartService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/modules/data-access/product/src/lib/state/cart/cart.service.ts b/modules/data-access/product/src/lib/state/cart/cart.service.ts new file mode 100644 index 0000000..55d7aa4 --- /dev/null +++ b/modules/data-access/product/src/lib/state/cart/cart.service.ts @@ -0,0 +1,8 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root', +}) +export class CartService { + constructor() {} +} diff --git a/src/app/interceptors/http-errors/http-errors.interceptor.spec.ts b/src/app/interceptors/http-errors/http-errors.interceptor.spec.ts index 94d469a..14ce270 100644 --- a/src/app/interceptors/http-errors/http-errors.interceptor.spec.ts +++ b/src/app/interceptors/http-errors/http-errors.interceptor.spec.ts @@ -1,13 +1,35 @@ import { TestBed } from '@angular/core/testing'; import { HttpErrorsInterceptor } from './http-errors.interceptor'; +import { HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http'; +import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; +import { + HttpClientTestingModule, + HttpTestingController, +} from '@angular/common/http/testing'; describe('HttpErrorsInterceptor', () => { - beforeEach(() => + let httpClient: HttpClient; + let httpMock: HttpTestingController; + let matSnackBar: MatSnackBar; + + beforeEach(() => { TestBed.configureTestingModule({ - providers: [HttpErrorsInterceptor], - }) - ); + imports: [HttpClientTestingModule, MatSnackBarModule], + providers: [ + HttpErrorsInterceptor, + { + provide: HTTP_INTERCEPTORS, + useClass: HttpErrorsInterceptor, + multi: true, + }, + ], + }); + + httpClient = TestBed.inject(HttpClient); + httpMock = TestBed.inject(HttpTestingController); + matSnackBar = TestBed.inject(MatSnackBar); + }); it('should be created', () => { const interceptor: HttpErrorsInterceptor = TestBed.inject( @@ -15,4 +37,15 @@ describe('HttpErrorsInterceptor', () => { ); expect(interceptor).toBeTruthy(); }); + + it('should open notification on http error', () => { + jest.spyOn(matSnackBar, 'open'); + httpClient.get('/test').subscribe(); + + const request = httpMock.expectOne('/test'); + request.error(new ProgressEvent('error')); + + expect(matSnackBar.open).toHaveBeenCalled(); + expect(request.request.headers.has('x-access-token')).toBe(true); + }); });