@scm-manager/ui-api 2.36.1 → 2.36.2-20220522-120507
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +735 -0
- package/build/index.js +3200 -0
- package/build/index.mjs +3031 -0
- package/package.json +15 -10
- package/LICENSE.txt +0 -21
- package/src/ApiProvider.test.tsx +0 -60
- package/src/ApiProvider.tsx +0 -80
- package/src/LegacyContext.test.tsx +0 -52
- package/src/LegacyContext.tsx +0 -75
- package/src/admin.test.ts +0 -55
- package/src/admin.ts +0 -42
- package/src/alerts.ts +0 -107
- package/src/annotations.ts +0 -45
- package/src/apiKeys.ts +0 -82
- package/src/apiclient.test.ts +0 -126
- package/src/apiclient.ts +0 -336
- package/src/base.test.ts +0 -238
- package/src/base.ts +0 -120
- package/src/branches.test.ts +0 -234
- package/src/branches.ts +0 -201
- package/src/changesets.test.ts +0 -178
- package/src/changesets.ts +0 -82
- package/src/compare.ts +0 -90
- package/src/config.test.ts +0 -118
- package/src/config.ts +0 -60
- package/src/configLink.test.ts +0 -169
- package/src/configLink.ts +0 -89
- package/src/contentType.ts +0 -58
- package/src/diff.test.ts +0 -234
- package/src/diff.ts +0 -93
- package/src/errors.test.ts +0 -59
- package/src/errors.ts +0 -133
- package/src/fileContent.ts +0 -33
- package/src/groupSuggestions.ts +0 -32
- package/src/groups.test.ts +0 -241
- package/src/groups.ts +0 -141
- package/src/help/search/modal.de.ts +0 -33
- package/src/help/search/modal.en.ts +0 -33
- package/src/help/search/syntax.de.ts +0 -148
- package/src/help/search/syntax.en.ts +0 -145
- package/src/history.ts +0 -62
- package/src/import.ts +0 -114
- package/src/index.ts +0 -72
- package/src/keys.ts +0 -48
- package/src/links.test.ts +0 -99
- package/src/links.ts +0 -54
- package/src/login.test.ts +0 -240
- package/src/login.ts +0 -128
- package/src/loginInfo.ts +0 -43
- package/src/namespaceSuggestions.ts +0 -32
- package/src/namespaces.test.ts +0 -95
- package/src/namespaces.ts +0 -43
- package/src/notifications.ts +0 -183
- package/src/permissions.test.ts +0 -345
- package/src/permissions.ts +0 -202
- package/src/plugins.test.ts +0 -336
- package/src/plugins.ts +0 -259
- package/src/publicKeys.ts +0 -83
- package/src/repositories.test.ts +0 -508
- package/src/repositories.ts +0 -375
- package/src/repository-roles.test.ts +0 -229
- package/src/repository-roles.ts +0 -142
- package/src/reset.ts +0 -36
- package/src/search.ts +0 -153
- package/src/sources.test.ts +0 -233
- package/src/sources.ts +0 -136
- package/src/suggestions.ts +0 -47
- package/src/tags.test.ts +0 -272
- package/src/tags.ts +0 -118
- package/src/tests/createInfiniteCachingClient.ts +0 -37
- package/src/tests/createWrapper.tsx +0 -37
- package/src/tests/indexLinks.ts +0 -43
- package/src/urls.test.ts +0 -104
- package/src/urls.ts +0 -118
- package/src/usePluginCenterAuthInfo.ts +0 -91
- package/src/userSuggestions.ts +0 -32
- package/src/users.test.ts +0 -310
- package/src/users.ts +0 -240
- package/src/utils.ts +0 -29
package/src/changesets.test.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
import { Branch, Changeset, ChangesetCollection, Repository } from "@scm-manager/ui-types";
|
|
25
|
-
import fetchMock from "fetch-mock-jest";
|
|
26
|
-
import createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
|
|
27
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
28
|
-
import createWrapper from "./tests/createWrapper";
|
|
29
|
-
import { useChangeset, useChangesets } from "./changesets";
|
|
30
|
-
|
|
31
|
-
describe("Test changeset hooks", () => {
|
|
32
|
-
const repository: Repository = {
|
|
33
|
-
namespace: "hitchhiker",
|
|
34
|
-
name: "heart-of-gold",
|
|
35
|
-
type: "hg",
|
|
36
|
-
_links: {
|
|
37
|
-
changesets: {
|
|
38
|
-
href: "/r/c"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const develop: Branch = {
|
|
44
|
-
name: "develop",
|
|
45
|
-
revision: "42",
|
|
46
|
-
lastCommitter: { name: "trillian" },
|
|
47
|
-
_links: {
|
|
48
|
-
history: {
|
|
49
|
-
href: "/r/b/c"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const changeset: Changeset = {
|
|
55
|
-
id: "42",
|
|
56
|
-
description: "Awesome change",
|
|
57
|
-
date: new Date(),
|
|
58
|
-
author: {
|
|
59
|
-
name: "Arthur Dent"
|
|
60
|
-
},
|
|
61
|
-
_embedded: {},
|
|
62
|
-
_links: {}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const changesets: ChangesetCollection = {
|
|
66
|
-
page: 1,
|
|
67
|
-
pageTotal: 1,
|
|
68
|
-
_embedded: {
|
|
69
|
-
changesets: [changeset]
|
|
70
|
-
},
|
|
71
|
-
_links: {}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const expectChangesetCollection = (result?: ChangesetCollection) => {
|
|
75
|
-
expect(result?._embedded?.changesets[0].id).toBe(changesets._embedded?.changesets[0].id);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
fetchMock.reset();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe("useChangesets tests", () => {
|
|
83
|
-
it("should return changesets", async () => {
|
|
84
|
-
fetchMock.getOnce("/api/v2/r/c", changesets);
|
|
85
|
-
|
|
86
|
-
const queryClient = createInfiniteCachingClient();
|
|
87
|
-
|
|
88
|
-
const { result, waitFor } = renderHook(() => useChangesets(repository), {
|
|
89
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
await waitFor(() => {
|
|
93
|
-
return !!result.current.data;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
expectChangesetCollection(result.current.data);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should return changesets for page", async () => {
|
|
100
|
-
fetchMock.getOnce("/api/v2/r/c", changesets, {
|
|
101
|
-
query: {
|
|
102
|
-
page: 42
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const queryClient = createInfiniteCachingClient();
|
|
107
|
-
|
|
108
|
-
const { result, waitFor } = renderHook(() => useChangesets(repository, { page: 42 }), {
|
|
109
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
await waitFor(() => {
|
|
113
|
-
return !!result.current.data;
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
expectChangesetCollection(result.current.data);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("should use link from branch", async () => {
|
|
120
|
-
fetchMock.getOnce("/api/v2/r/b/c", changesets);
|
|
121
|
-
|
|
122
|
-
const queryClient = createInfiniteCachingClient();
|
|
123
|
-
|
|
124
|
-
const { result, waitFor } = renderHook(() => useChangesets(repository, { branch: develop }), {
|
|
125
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
await waitFor(() => {
|
|
129
|
-
return !!result.current.data;
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
expectChangesetCollection(result.current.data);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it("should populate changeset cache", async () => {
|
|
136
|
-
fetchMock.getOnce("/api/v2/r/c", changesets);
|
|
137
|
-
|
|
138
|
-
const queryClient = createInfiniteCachingClient();
|
|
139
|
-
|
|
140
|
-
const { result, waitFor } = renderHook(() => useChangesets(repository), {
|
|
141
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
await waitFor(() => {
|
|
145
|
-
return !!result.current.data;
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const changeset: Changeset | undefined = queryClient.getQueryData([
|
|
149
|
-
"repository",
|
|
150
|
-
"hitchhiker",
|
|
151
|
-
"heart-of-gold",
|
|
152
|
-
"changeset",
|
|
153
|
-
"42"
|
|
154
|
-
]);
|
|
155
|
-
|
|
156
|
-
expect(changeset?.id).toBe("42");
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe("useChangeset tests", () => {
|
|
161
|
-
it("should return changes", async () => {
|
|
162
|
-
fetchMock.get("/api/v2/r/c/42", changeset);
|
|
163
|
-
|
|
164
|
-
const queryClient = createInfiniteCachingClient();
|
|
165
|
-
|
|
166
|
-
const { result, waitFor } = renderHook(() => useChangeset(repository, "42"), {
|
|
167
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
await waitFor(() => {
|
|
171
|
-
return !!result.current.data;
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const c = result.current.data;
|
|
175
|
-
expect(c?.description).toBe("Awesome change");
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
});
|
package/src/changesets.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
import { Branch, Changeset, ChangesetCollection, NamespaceAndName, Repository } from "@scm-manager/ui-types";
|
|
25
|
-
import { useQuery, useQueryClient } from "react-query";
|
|
26
|
-
import { requiredLink } from "./links";
|
|
27
|
-
import { apiClient } from "./apiclient";
|
|
28
|
-
import { ApiResult, ApiResultWithFetching } from "./base";
|
|
29
|
-
import { branchQueryKey, repoQueryKey } from "./keys";
|
|
30
|
-
import { concat } from "./urls";
|
|
31
|
-
|
|
32
|
-
type UseChangesetsRequest = {
|
|
33
|
-
branch?: Branch;
|
|
34
|
-
page?: string | number;
|
|
35
|
-
limit?: number;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const changesetQueryKey = (repository: NamespaceAndName, id: string) => {
|
|
39
|
-
return repoQueryKey(repository, "changeset", id);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const useChangesets = (
|
|
43
|
-
repository: Repository,
|
|
44
|
-
request?: UseChangesetsRequest
|
|
45
|
-
): ApiResultWithFetching<ChangesetCollection> => {
|
|
46
|
-
const queryClient = useQueryClient();
|
|
47
|
-
|
|
48
|
-
let link: string;
|
|
49
|
-
let branch = "_";
|
|
50
|
-
if (request?.branch) {
|
|
51
|
-
link = requiredLink(request.branch, "history");
|
|
52
|
-
branch = request.branch.name;
|
|
53
|
-
} else {
|
|
54
|
-
link = requiredLink(repository, "changesets");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (request?.page || request?.limit) {
|
|
58
|
-
if (request?.page && request?.limit) {
|
|
59
|
-
link = `${link}?page=${request.page}&pageSize=${request.limit}`;
|
|
60
|
-
} else if (request.page) {
|
|
61
|
-
link = `${link}?page=${request.page}`;
|
|
62
|
-
} else if (request.limit) {
|
|
63
|
-
link = `${link}?pageSize=${request.limit}`;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const key = branchQueryKey(repository, branch, "changesets", request?.page || 0);
|
|
68
|
-
return useQuery<ChangesetCollection, Error>(key, () => apiClient.get(link).then((response) => response.json()), {
|
|
69
|
-
onSuccess: (changesetCollection) => {
|
|
70
|
-
changesetCollection._embedded?.changesets.forEach((changeset) => {
|
|
71
|
-
queryClient.setQueryData(changesetQueryKey(repository, changeset.id), changeset);
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const useChangeset = (repository: Repository, id: string): ApiResult<Changeset> => {
|
|
78
|
-
const changesetsLink = requiredLink(repository, "changesets");
|
|
79
|
-
return useQuery<Changeset, Error>(changesetQueryKey(repository, id), () =>
|
|
80
|
-
apiClient.get(concat(changesetsLink, id)).then((response) => response.json())
|
|
81
|
-
);
|
|
82
|
-
};
|
package/src/compare.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { ChangesetCollection, Link, Repository } from "@scm-manager/ui-types";
|
|
26
|
-
import { useQuery, useQueryClient } from "react-query";
|
|
27
|
-
import { ApiResultWithFetching } from "./base";
|
|
28
|
-
import { apiClient } from "./apiclient";
|
|
29
|
-
import { changesetQueryKey } from "./changesets";
|
|
30
|
-
|
|
31
|
-
function createIncomingUrl(repository: Repository, linkName: string, source: string, target: string) {
|
|
32
|
-
const link = repository._links[linkName];
|
|
33
|
-
if ((link as Link)?.templated) {
|
|
34
|
-
return (link as Link).href
|
|
35
|
-
.replace("{source}", encodeURIComponent(source))
|
|
36
|
-
.replace("{target}", encodeURIComponent(target));
|
|
37
|
-
} else {
|
|
38
|
-
return (link as Link).href;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function createChangesetUrl(repository: Repository, source: string, target: string) {
|
|
43
|
-
return createIncomingUrl(repository, "incomingChangesets", source, target);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function createDiffUrl(repository: Repository, source: string, target: string) {
|
|
47
|
-
if (repository._links.incomingDiffParsed) {
|
|
48
|
-
return createIncomingUrl(repository, "incomingDiffParsed", source, target);
|
|
49
|
-
} else {
|
|
50
|
-
return createIncomingUrl(repository, "incomingDiff", source, target);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
type UseIncomingChangesetsRequest = {
|
|
55
|
-
page?: string | number;
|
|
56
|
-
limit?: number;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const useIncomingChangesets = (
|
|
60
|
-
repository: Repository,
|
|
61
|
-
source: string,
|
|
62
|
-
target: string,
|
|
63
|
-
request?: UseIncomingChangesetsRequest
|
|
64
|
-
): ApiResultWithFetching<ChangesetCollection> => {
|
|
65
|
-
const queryClient = useQueryClient();
|
|
66
|
-
|
|
67
|
-
let link = createChangesetUrl(repository, source, target);
|
|
68
|
-
|
|
69
|
-
if (request?.page || request?.limit) {
|
|
70
|
-
if (request?.page && request?.limit) {
|
|
71
|
-
link = `${link}?page=${request.page}&pageSize=${request.limit}`;
|
|
72
|
-
} else if (request.page) {
|
|
73
|
-
link = `${link}?page=${request.page}`;
|
|
74
|
-
} else if (request.limit) {
|
|
75
|
-
link = `${link}?pageSize=${request.limit}`;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return useQuery<ChangesetCollection, Error>(
|
|
80
|
-
["repository", repository.namespace, repository.name, "compare", source, target, "changesets", request?.page || 0],
|
|
81
|
-
() => apiClient.get(link).then(response => response.json()),
|
|
82
|
-
{
|
|
83
|
-
onSuccess: changesetCollection => {
|
|
84
|
-
changesetCollection._embedded?.changesets.forEach(changeset => {
|
|
85
|
-
queryClient.setQueryData(changesetQueryKey(repository, changeset.id), changeset);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
};
|
package/src/config.test.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { Config } from "@scm-manager/ui-types";
|
|
26
|
-
import fetchMock from "fetch-mock-jest";
|
|
27
|
-
import createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
|
|
28
|
-
import { setIndexLink } from "./tests/indexLinks";
|
|
29
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
30
|
-
import createWrapper from "./tests/createWrapper";
|
|
31
|
-
import { useConfig, useUpdateConfig } from "./config";
|
|
32
|
-
import { act } from "react-test-renderer";
|
|
33
|
-
|
|
34
|
-
describe("Test config hooks", () => {
|
|
35
|
-
const config: Config = {
|
|
36
|
-
anonymousAccessEnabled: false,
|
|
37
|
-
anonymousMode: "OFF",
|
|
38
|
-
baseUrl: "",
|
|
39
|
-
dateFormat: "",
|
|
40
|
-
disableGroupingGrid: false,
|
|
41
|
-
enableProxy: false,
|
|
42
|
-
enabledUserConverter: false,
|
|
43
|
-
enabledXsrfProtection: false,
|
|
44
|
-
enabledApiKeys: false,
|
|
45
|
-
forceBaseUrl: false,
|
|
46
|
-
loginAttemptLimit: 0,
|
|
47
|
-
loginAttemptLimitTimeout: 0,
|
|
48
|
-
loginInfoUrl: "",
|
|
49
|
-
mailDomainName: "",
|
|
50
|
-
namespaceStrategy: "",
|
|
51
|
-
emergencyContacts: [],
|
|
52
|
-
pluginUrl: "",
|
|
53
|
-
pluginAuthUrl: "",
|
|
54
|
-
proxyExcludes: [],
|
|
55
|
-
proxyPassword: null,
|
|
56
|
-
proxyPort: 0,
|
|
57
|
-
proxyServer: "",
|
|
58
|
-
proxyUser: null,
|
|
59
|
-
realmDescription: "",
|
|
60
|
-
alertsUrl: "",
|
|
61
|
-
feedbackUrl: "",
|
|
62
|
-
releaseFeedUrl: "",
|
|
63
|
-
skipFailedAuthenticators: false,
|
|
64
|
-
_links: {
|
|
65
|
-
update: {
|
|
66
|
-
href: "/config"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
afterEach(() => {
|
|
72
|
-
fetchMock.reset();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe("useConfig tests", () => {
|
|
76
|
-
it("should return config", async () => {
|
|
77
|
-
const queryClient = createInfiniteCachingClient();
|
|
78
|
-
setIndexLink(queryClient, "config", "/config");
|
|
79
|
-
fetchMock.get("/api/v2/config", config);
|
|
80
|
-
const { result, waitFor } = renderHook(() => useConfig(), {
|
|
81
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
82
|
-
});
|
|
83
|
-
await waitFor(() => !!result.current.data);
|
|
84
|
-
expect(result.current.data).toEqual(config);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe("useUpdateConfig tests", () => {
|
|
89
|
-
it("should update config", async () => {
|
|
90
|
-
const queryClient = createInfiniteCachingClient();
|
|
91
|
-
setIndexLink(queryClient, "config", "/config");
|
|
92
|
-
|
|
93
|
-
const newConfig = {
|
|
94
|
-
...config,
|
|
95
|
-
baseUrl: "/hog"
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
fetchMock.putOnce("/api/v2/config", {
|
|
99
|
-
status: 200
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const { result, waitForNextUpdate } = renderHook(() => useUpdateConfig(), {
|
|
103
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
await act(() => {
|
|
107
|
-
const { update } = result.current;
|
|
108
|
-
update(newConfig);
|
|
109
|
-
return waitForNextUpdate();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
expect(result.current.error).toBeFalsy();
|
|
113
|
-
expect(result.current.isUpdated).toBe(true);
|
|
114
|
-
expect(result.current.isLoading).toBe(false);
|
|
115
|
-
expect(queryClient.getQueryData(["config"])).toBeUndefined();
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
package/src/config.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { ApiResult, useIndexLink } from "./base";
|
|
26
|
-
import { Config } from "@scm-manager/ui-types";
|
|
27
|
-
import { useMutation, useQuery, useQueryClient } from "react-query";
|
|
28
|
-
import { apiClient } from "./apiclient";
|
|
29
|
-
import { requiredLink } from "./links";
|
|
30
|
-
|
|
31
|
-
export const useConfig = (): ApiResult<Config> => {
|
|
32
|
-
const indexLink = useIndexLink("config");
|
|
33
|
-
return useQuery<Config, Error>("config", () => apiClient.get(indexLink!).then(response => response.json()), {
|
|
34
|
-
enabled: !!indexLink
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const useUpdateConfig = () => {
|
|
39
|
-
const queryClient = useQueryClient();
|
|
40
|
-
const { mutate, isLoading, error, data, reset } = useMutation<unknown, Error, Config>(
|
|
41
|
-
config => {
|
|
42
|
-
const updateUrl = requiredLink(config, "update");
|
|
43
|
-
return apiClient.put(updateUrl, config, "application/vnd.scmm-config+json;v=2");
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
onSuccess: async () => {
|
|
47
|
-
await queryClient.invalidateQueries("config");
|
|
48
|
-
await queryClient.invalidateQueries("index");
|
|
49
|
-
await queryClient.invalidateQueries("pluginCenterAuth");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
return {
|
|
54
|
-
update: (config: Config) => mutate(config),
|
|
55
|
-
isLoading,
|
|
56
|
-
error,
|
|
57
|
-
isUpdated: !!data,
|
|
58
|
-
reset
|
|
59
|
-
};
|
|
60
|
-
};
|
package/src/configLink.test.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import fetchMock from "fetch-mock-jest";
|
|
26
|
-
import { HalRepresentation } from "@scm-manager/ui-types";
|
|
27
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
28
|
-
import createWrapper from "./tests/createWrapper";
|
|
29
|
-
import { useConfigLink } from "./configLink";
|
|
30
|
-
import createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
|
|
31
|
-
import { act } from "react-test-renderer";
|
|
32
|
-
|
|
33
|
-
describe("useConfigLink tests", () => {
|
|
34
|
-
type MyConfig = HalRepresentation & {
|
|
35
|
-
name: string;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const myReadOnlyConfig: MyConfig = {
|
|
39
|
-
name: "Hansolo",
|
|
40
|
-
_links: {},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const myConfig: MyConfig = {
|
|
44
|
-
name: "Lea",
|
|
45
|
-
_links: {
|
|
46
|
-
update: {
|
|
47
|
-
href: "/my/config-write",
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
afterEach(() => {
|
|
53
|
-
fetchMock.reset();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const fetchConfiguration = async (config: MyConfig) => {
|
|
57
|
-
fetchMock.getOnce("/api/v2/my/config", config);
|
|
58
|
-
|
|
59
|
-
const queryClient = createInfiniteCachingClient();
|
|
60
|
-
|
|
61
|
-
const { result, waitFor } = renderHook(() => useConfigLink<MyConfig>("/my/config"), {
|
|
62
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
63
|
-
});
|
|
64
|
-
await waitFor(() => {
|
|
65
|
-
return !!result.current.initialConfiguration;
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return result.current;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
it("should return read only configuration without update link", async () => {
|
|
72
|
-
const { isReadOnly } = await fetchConfiguration(myReadOnlyConfig);
|
|
73
|
-
|
|
74
|
-
expect(isReadOnly).toBe(true);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("should not be read only with update link", async () => {
|
|
78
|
-
const { isReadOnly } = await fetchConfiguration(myConfig);
|
|
79
|
-
|
|
80
|
-
expect(isReadOnly).toBe(false);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("should call update url", async () => {
|
|
84
|
-
const queryClient = createInfiniteCachingClient();
|
|
85
|
-
|
|
86
|
-
fetchMock.get("/api/v2/my/config", myConfig);
|
|
87
|
-
|
|
88
|
-
const { result, waitFor, waitForNextUpdate } = renderHook(() => useConfigLink<MyConfig>("/my/config"), {
|
|
89
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
await waitFor(() => {
|
|
93
|
-
return !!result.current.initialConfiguration;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const { update } = result.current;
|
|
97
|
-
|
|
98
|
-
const lukesConfig = {
|
|
99
|
-
...myConfig,
|
|
100
|
-
name: "Luke",
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
fetchMock.putOnce(
|
|
104
|
-
{
|
|
105
|
-
url: "/api/v2/my/config-write",
|
|
106
|
-
headers: {
|
|
107
|
-
"Content-Type": "application/json",
|
|
108
|
-
},
|
|
109
|
-
body: lukesConfig,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
status: 204,
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
await act(() => {
|
|
117
|
-
update(lukesConfig);
|
|
118
|
-
return waitForNextUpdate();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
expect(result.current.isUpdated).toBe(true);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("should capture content type update url", async () => {
|
|
125
|
-
const queryClient = createInfiniteCachingClient();
|
|
126
|
-
|
|
127
|
-
fetchMock.get("/api/v2/my/config", {
|
|
128
|
-
headers: {
|
|
129
|
-
"Content-Type": "application/myconfig+json",
|
|
130
|
-
},
|
|
131
|
-
body: myConfig,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
const { result, waitFor, waitForNextUpdate } = renderHook(() => useConfigLink<MyConfig>("/my/config"), {
|
|
135
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
await waitFor(() => {
|
|
139
|
-
return !!result.current.initialConfiguration;
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const { update } = result.current;
|
|
143
|
-
|
|
144
|
-
const lukesConfig = {
|
|
145
|
-
...myConfig,
|
|
146
|
-
name: "Luke",
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
fetchMock.putOnce(
|
|
150
|
-
{
|
|
151
|
-
url: "/api/v2/my/config-write",
|
|
152
|
-
headers: {
|
|
153
|
-
"Content-Type": "application/myconfig+json",
|
|
154
|
-
},
|
|
155
|
-
body: lukesConfig,
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
status: 204,
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
await act(() => {
|
|
163
|
-
update(lukesConfig);
|
|
164
|
-
return waitForNextUpdate();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
expect(result.current.isUpdated).toBe(true);
|
|
168
|
-
});
|
|
169
|
-
});
|