-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from FelipeDuarteLuna/03-01-24
01/01/2024 - Gerenciamento de estado
- Loading branch information
Showing
3 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
modules/data-access/product/src/lib/state/cart/cart.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
modules/data-access/product/src/lib/state/cart/cart.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class CartService { | ||
constructor() {} | ||
} |
41 changes: 37 additions & 4 deletions
41
src/app/interceptors/http-errors/http-errors.interceptor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,51 @@ | ||
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( | ||
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); | ||
}); | ||
}); |