| /******************************************************************************** |
| * Copyright (c) 2020 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0 |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ********************************************************************************/ |
| |
| import {HttpErrorResponse} from "@angular/common/http"; |
| import {EHttpStatusCodes} from "./EHttpStatusCodes"; |
| import {isHttpErrorWithStatus, urlJoin} from "./http.util"; |
| |
| describe("HttpUtil", () => { |
| |
| it("should join URLs", () => { |
| expect(urlJoin("ab", "cd")).toBe("ab/cd"); |
| expect(urlJoin("/ab", "///", "cd", "///ef")).toBe("/ab/cd/ef"); |
| expect(urlJoin("https://", "/////", "www.abc.de", "///", "/fg/")).toBe("https://www.abc.de/fg/"); |
| expect(urlJoin()).toBe(""); |
| }); |
| |
| it("should recognize HttpErrorResponses", () => { |
| let httpError: any; |
| |
| httpError = new HttpErrorResponse({status: EHttpStatusCodes.UNAUTHORIZED}); |
| expect(isHttpErrorWithStatus(httpError, EHttpStatusCodes.UNAUTHORIZED)).toBeTrue(); |
| expect(isHttpErrorWithStatus(httpError, EHttpStatusCodes.UNAUTHORIZED, EHttpStatusCodes.FORBIDDEN)).toBeTrue(); |
| |
| httpError = {status: EHttpStatusCodes.UNAUTHORIZED}; |
| expect(isHttpErrorWithStatus(httpError, EHttpStatusCodes.UNAUTHORIZED)).toBeFalse(); |
| expect(isHttpErrorWithStatus(httpError, EHttpStatusCodes.UNAUTHORIZED, EHttpStatusCodes.FORBIDDEN)).toBeFalse(); |
| |
| httpError = new HttpErrorResponse({status: EHttpStatusCodes.FORBIDDEN}); |
| expect(isHttpErrorWithStatus(httpError, EHttpStatusCodes.UNAUTHORIZED)).toBeFalse(); |
| expect(isHttpErrorWithStatus(httpError, EHttpStatusCodes.UNAUTHORIZED, EHttpStatusCodes.FORBIDDEN)).toBeTrue(); |
| }); |
| |
| }); |
| |