Skip to content

Commit

Permalink
Improve tests of ErrorHandlingInterceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelwedler committed Apr 15, 2021
1 parent 5ea7be9 commit 41bcfaa
Showing 1 changed file with 23 additions and 55 deletions.
78 changes: 23 additions & 55 deletions src/app/interceptors/error-handling.interceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ describe('ErrorHandlingInterceptor', () => {
let notificationService: NotificationService;
let raidenConfig: RaidenConfig;

const httpResponse400 = {
status: 400,
statusText: '',
};
const httpResponse504 = {
status: 504,
statusText: '',
};

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
Expand Down Expand Up @@ -67,10 +76,7 @@ describe('ErrorHandlingInterceptor', () => {
errors: errorMessage,
};

request.flush(errorBody, {
status: 400,
statusText: '',
});
request.flush(errorBody, httpResponse400);
tick();
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenCalledWith(errorMessage);
Expand All @@ -93,10 +99,7 @@ describe('ErrorHandlingInterceptor', () => {
],
};

request.flush(errorBody, {
status: 400,
statusText: '',
});
request.flush(errorBody, httpResponse400);
tick();
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenCalledWith(errorMessage);
Expand All @@ -115,10 +118,7 @@ describe('ErrorHandlingInterceptor', () => {
errors: '',
};

request.flush(errorBody, {
status: 400,
statusText: '',
});
request.flush(errorBody, httpResponse400);
tick();
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenCalledWith(errorMessage);
Expand All @@ -132,18 +132,13 @@ describe('ErrorHandlingInterceptor', () => {

let request = httpMock.expectOne(raidenConfig.api);

request.flush(
{},
{
status: 504,
statusText: '',
}
);
request.flush({}, httpResponse504);
tick();

expect(notificationService.addErrorNotification).toHaveBeenCalledTimes(
1
);
expect(notificationService.apiError).toBeTruthy();
expect(errorSpy).toHaveBeenCalledTimes(1);

service.getData().subscribe(() => {
Expand All @@ -162,6 +157,7 @@ describe('ErrorHandlingInterceptor', () => {
expect(notificationService.addErrorNotification).toHaveBeenCalledTimes(
1
);
expect(notificationService.apiError).toBeTruthy();
expect(errorSpy).toHaveBeenCalledTimes(2);
}));

Expand All @@ -173,32 +169,21 @@ describe('ErrorHandlingInterceptor', () => {

let request = httpMock.expectOne(raidenConfig.api);

request.flush(
{},
{
status: 504,
statusText: '',
}
);

request.flush({}, httpResponse504);
tick();

notificationService.apiError.retrying = true;
service.getData().subscribe(() => {
fail('On next should not be called');
}, errorSpy);
request = httpMock.expectOne(raidenConfig.api);
request.flush(
{},
{
status: 504,
statusText: '',
}
);
request.flush({}, httpResponse504);
tick();

expect(notificationService.addErrorNotification).toHaveBeenCalledTimes(
2
);
expect(notificationService.apiError).toBeTruthy();
expect(errorSpy).toHaveBeenCalledTimes(2);
}));

Expand All @@ -217,13 +202,7 @@ describe('ErrorHandlingInterceptor', () => {

let request = httpMock.expectOne(raidenConfig.api);

request.flush(
{},
{
status: 504,
statusText: '',
}
);
request.flush({}, httpResponse504);
tick();

service.getData().subscribe((data) => {
Expand Down Expand Up @@ -257,18 +236,13 @@ describe('ErrorHandlingInterceptor', () => {
}, errorSpy);

const request = httpMock.expectOne(requestUrl);
request.flush(
{},
{
status: 504,
statusText: '',
}
);
request.flush({}, httpResponse504);
tick();

expect(notificationService.addErrorNotification).toHaveBeenCalledTimes(
1
);
expect(notificationService.apiError).toBeTruthy();
expect(errorSpy).toHaveBeenCalledTimes(1);
}));

Expand All @@ -282,13 +256,7 @@ describe('ErrorHandlingInterceptor', () => {
}, errorSpy);

const request = httpMock.expectOne(requestUrl);
request.flush(
{},
{
status: 504,
statusText: '',
}
);
request.flush({}, httpResponse504);
tick();

expect(notificationService.addErrorNotification).toHaveBeenCalledTimes(
Expand Down

0 comments on commit 41bcfaa

Please sign in to comment.