Skip to content
Snippets Groups Projects
Commit be8d11af authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2792 Refactoring nach PR Review, Unit Tests hinzufügen

parent 6f67fa02
No related branches found
No related tags found
No related merge requests found
...@@ -30,8 +30,7 @@ export function createError(): unknown { ...@@ -30,8 +30,7 @@ export function createError(): unknown {
} }
export function createHttpErrorResponse(apiError: ApiError = null): HttpErrorResponse { export function createHttpErrorResponse(apiError: ApiError = null): HttpErrorResponse {
return { return <HttpErrorResponse>{
...<HttpErrorResponse>{},
error: { error: {
error: apiError ?? createApiError() error: apiError ?? createApiError()
} }
......
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { ApiRootFacade, ApiRootLinkRel, ApiRootResource } from '@goofy-client/api-root-shared'; import { ApiRootFacade, ApiRootLinkRel, ApiRootResource } from '@goofy-client/api-root-shared';
import { NavigationFacade } from '@goofy-client/navigation-shared'; import { NavigationFacade } from '@goofy-client/navigation-shared';
...@@ -274,4 +274,34 @@ describe('VorgangEffects', () => { ...@@ -274,4 +274,34 @@ describe('VorgangEffects', () => {
expect(effects.searchForPreview$).toBeObservable(expected); expect(effects.searchForPreview$).toBeObservable(expected);
}) })
}) })
describe('search error', () => {
const action = VorgangActions.searchForPreviewFailure({ httpErrorResponse: null });
const error: HttpErrorResponse = createHttpErrorResponse();
it('should trigger showSearchError$', () => {
actions = of(action);
effects.showSearchError = jest.fn();
effects.showSearchError$.subscribe();
expect(effects.showSearchError).toHaveBeenCalled();
})
it('should call snackbarService.showError if HTTP status code is NOT 503 ', () => {
error.error.status = HttpStatusCode.ExpectationFailed;
effects.showSearchError(error);
expect(snackbarService.showError).not.toHaveBeenCalled();
})
it('should call snackbarService.showError if HTTP status code is 503 ', () => {
error.error.status = HttpStatusCode.ServiceUnavailable;
effects.showSearchError(error);
expect(snackbarService.showError).toHaveBeenCalled();
})
})
}); });
\ No newline at end of file
...@@ -12,7 +12,7 @@ import { getSearchLinkRel } from '../vorgang-navigation.util'; ...@@ -12,7 +12,7 @@ import { getSearchLinkRel } from '../vorgang-navigation.util';
import { VorgangMessages } from '../vorgang.messages'; import { VorgangMessages } from '../vorgang.messages';
import { VorgangRepository } from '../vorgang.repository'; import { VorgangRepository } from '../vorgang.repository';
import * as VorgangActions from './vorgang.actions'; import * as VorgangActions from './vorgang.actions';
import { ApiRootAction, SearchVorgaengeByProps } from './vorgang.actions'; import { ApiRootAction, HttpErrorAction, SearchVorgaengeByProps } from './vorgang.actions';
import * as VorgangSelectors from './vorgang.selectors'; import * as VorgangSelectors from './vorgang.selectors';
@Injectable() @Injectable()
...@@ -84,11 +84,11 @@ export class VorgangEffects { ...@@ -84,11 +84,11 @@ export class VorgangEffects {
VorgangActions.searchForPreviewFailure, VorgangActions.searchForPreviewFailure,
VorgangActions.searchVorgaengeByFailure VorgangActions.searchVorgaengeByFailure
), ),
map(({ httpErrorResponse }) => this.showSearchError(httpErrorResponse)), map((action: HttpErrorAction) => this.showSearchError(action.httpErrorResponse)),
), { dispatch: false } ), { dispatch: false }
); );
private showSearchError(error: HttpErrorResponse): void { showSearchError(error: HttpErrorResponse): void {
if (isServiceUnavailable(error.error.status)) { if (isServiceUnavailable(error.error.status)) {
this.snackbarService.showError(VorgangMessages.SEARCH_UNAVAILABLE); this.snackbarService.showError(VorgangMessages.SEARCH_UNAVAILABLE);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment