mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
fix bug in createUrl of apiclient and added tests
This commit is contained in:
@@ -26,15 +26,15 @@ function handleStatusCode(response: Response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
function createUrl(url: string) {
|
||||
export function createUrl(url: string) {
|
||||
if (url.indexOf("://") > 0) {
|
||||
return url;
|
||||
}
|
||||
let urlWithEndingSlash = url;
|
||||
let urlWithStartingSlash = url;
|
||||
if (url.indexOf("/") !== 0) {
|
||||
urlWithEndingSlash += "/";
|
||||
urlWithStartingSlash = "/" + urlWithStartingSlash;
|
||||
}
|
||||
return `${apiUrl}/api/rest/v2${urlWithEndingSlash}`;
|
||||
return `${apiUrl}/api/rest/v2${urlWithStartingSlash}`;
|
||||
}
|
||||
|
||||
class ApiClient {
|
||||
|
||||
13
scm-ui/src/apiclient.test.js
Normal file
13
scm-ui/src/apiclient.test.js
Normal file
@@ -0,0 +1,13 @@
|
||||
// @flow
|
||||
import { createUrl } from "./apiclient";
|
||||
|
||||
test("create url, should not change absolute urls", () => {
|
||||
expect(createUrl("https://www.scm-manager.org")).toBe(
|
||||
"https://www.scm-manager.org"
|
||||
);
|
||||
});
|
||||
|
||||
test("create url, should add prefix for api", () => {
|
||||
expect(createUrl("/users")).toBe("/scm/api/rest/v2/users");
|
||||
expect(createUrl("users")).toBe("/scm/api/rest/v2/users");
|
||||
});
|
||||
Reference in New Issue
Block a user