@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.
Files changed (79) hide show
  1. package/build/index.d.ts +735 -0
  2. package/build/index.js +3200 -0
  3. package/build/index.mjs +3031 -0
  4. package/package.json +15 -10
  5. package/LICENSE.txt +0 -21
  6. package/src/ApiProvider.test.tsx +0 -60
  7. package/src/ApiProvider.tsx +0 -80
  8. package/src/LegacyContext.test.tsx +0 -52
  9. package/src/LegacyContext.tsx +0 -75
  10. package/src/admin.test.ts +0 -55
  11. package/src/admin.ts +0 -42
  12. package/src/alerts.ts +0 -107
  13. package/src/annotations.ts +0 -45
  14. package/src/apiKeys.ts +0 -82
  15. package/src/apiclient.test.ts +0 -126
  16. package/src/apiclient.ts +0 -336
  17. package/src/base.test.ts +0 -238
  18. package/src/base.ts +0 -120
  19. package/src/branches.test.ts +0 -234
  20. package/src/branches.ts +0 -201
  21. package/src/changesets.test.ts +0 -178
  22. package/src/changesets.ts +0 -82
  23. package/src/compare.ts +0 -90
  24. package/src/config.test.ts +0 -118
  25. package/src/config.ts +0 -60
  26. package/src/configLink.test.ts +0 -169
  27. package/src/configLink.ts +0 -89
  28. package/src/contentType.ts +0 -58
  29. package/src/diff.test.ts +0 -234
  30. package/src/diff.ts +0 -93
  31. package/src/errors.test.ts +0 -59
  32. package/src/errors.ts +0 -133
  33. package/src/fileContent.ts +0 -33
  34. package/src/groupSuggestions.ts +0 -32
  35. package/src/groups.test.ts +0 -241
  36. package/src/groups.ts +0 -141
  37. package/src/help/search/modal.de.ts +0 -33
  38. package/src/help/search/modal.en.ts +0 -33
  39. package/src/help/search/syntax.de.ts +0 -148
  40. package/src/help/search/syntax.en.ts +0 -145
  41. package/src/history.ts +0 -62
  42. package/src/import.ts +0 -114
  43. package/src/index.ts +0 -72
  44. package/src/keys.ts +0 -48
  45. package/src/links.test.ts +0 -99
  46. package/src/links.ts +0 -54
  47. package/src/login.test.ts +0 -240
  48. package/src/login.ts +0 -128
  49. package/src/loginInfo.ts +0 -43
  50. package/src/namespaceSuggestions.ts +0 -32
  51. package/src/namespaces.test.ts +0 -95
  52. package/src/namespaces.ts +0 -43
  53. package/src/notifications.ts +0 -183
  54. package/src/permissions.test.ts +0 -345
  55. package/src/permissions.ts +0 -202
  56. package/src/plugins.test.ts +0 -336
  57. package/src/plugins.ts +0 -259
  58. package/src/publicKeys.ts +0 -83
  59. package/src/repositories.test.ts +0 -508
  60. package/src/repositories.ts +0 -375
  61. package/src/repository-roles.test.ts +0 -229
  62. package/src/repository-roles.ts +0 -142
  63. package/src/reset.ts +0 -36
  64. package/src/search.ts +0 -153
  65. package/src/sources.test.ts +0 -233
  66. package/src/sources.ts +0 -136
  67. package/src/suggestions.ts +0 -47
  68. package/src/tags.test.ts +0 -272
  69. package/src/tags.ts +0 -118
  70. package/src/tests/createInfiniteCachingClient.ts +0 -37
  71. package/src/tests/createWrapper.tsx +0 -37
  72. package/src/tests/indexLinks.ts +0 -43
  73. package/src/urls.test.ts +0 -104
  74. package/src/urls.ts +0 -118
  75. package/src/usePluginCenterAuthInfo.ts +0 -91
  76. package/src/userSuggestions.ts +0 -32
  77. package/src/users.test.ts +0 -310
  78. package/src/users.ts +0 -240
  79. package/src/utils.ts +0 -29
@@ -1,375 +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 {
26
- ExportInfo,
27
- Link,
28
- Namespace,
29
- Paths,
30
- Repository,
31
- RepositoryCollection,
32
- RepositoryCreation,
33
- RepositoryTypeCollection
34
- } from "@scm-manager/ui-types";
35
- import { useMutation, useQuery, useQueryClient } from "react-query";
36
- import { apiClient } from "./apiclient";
37
- import { ApiResult, ApiResultWithFetching, useIndexJsonResource, useRequiredIndexLink } from "./base";
38
- import { createQueryString } from "./utils";
39
- import { objectLink, requiredLink } from "./links";
40
- import { repoQueryKey } from "./keys";
41
- import { concat } from "./urls";
42
- import { useEffect, useState } from "react";
43
- import { MissingLinkError, NotFoundError } from "./errors";
44
-
45
- export type UseRepositoriesRequest = {
46
- namespace?: Namespace;
47
- search?: string;
48
- page?: number | string;
49
- disabled?: boolean;
50
- };
51
-
52
- export const useRepositories = (request?: UseRepositoriesRequest): ApiResult<RepositoryCollection> => {
53
- const queryClient = useQueryClient();
54
- const indexLink = useRequiredIndexLink("repositories");
55
- const namespaceLink = (request?.namespace?._links.repositories as Link)?.href;
56
- const link = namespaceLink || indexLink;
57
-
58
- const queryParams: Record<string, string> = {};
59
- if (request?.search) {
60
- queryParams.q = request.search;
61
- }
62
- if (request?.page) {
63
- queryParams.page = request.page.toString();
64
- }
65
- return useQuery<RepositoryCollection, Error>(
66
- ["repositories", request?.namespace?.namespace, request?.search || "", request?.page || 0],
67
- () => apiClient.get(`${link}?${createQueryString(queryParams)}`).then(response => response.json()),
68
- {
69
- enabled: !request?.disabled,
70
- onSuccess: (repositories: RepositoryCollection) => {
71
- // prepare single repository cache
72
- repositories._embedded?.repositories.forEach((repository: Repository) => {
73
- queryClient.setQueryData(["repository", repository.namespace, repository.name], repository);
74
- });
75
- }
76
- }
77
- );
78
- };
79
-
80
- type CreateRepositoryRequest = {
81
- repository: RepositoryCreation;
82
- initialize: boolean;
83
- };
84
-
85
- const createRepository = (link: string) => {
86
- return (request: CreateRepositoryRequest) => {
87
- let createLink = link;
88
- if (request.initialize) {
89
- createLink += "?initialize=true";
90
- }
91
- return apiClient
92
- .post(createLink, request.repository, "application/vnd.scmm-repository+json;v=2")
93
- .then(response => {
94
- const location = response.headers.get("Location");
95
- if (!location) {
96
- throw new Error("Server does not return required Location header");
97
- }
98
- return apiClient.get(location);
99
- })
100
- .then(response => response.json());
101
- };
102
- };
103
-
104
- export const useCreateRepository = () => {
105
- const queryClient = useQueryClient();
106
- // not really the index link,
107
- // but a post to the collection is create by convention
108
- const link = useRequiredIndexLink("repositories");
109
- const { mutate, data, isLoading, error } = useMutation<Repository, Error, CreateRepositoryRequest>(
110
- createRepository(link),
111
- {
112
- onSuccess: repository => {
113
- queryClient.setQueryData(["repository", repository.namespace, repository.name], repository);
114
- return queryClient.invalidateQueries(["repositories"]);
115
- }
116
- }
117
- );
118
- return {
119
- create: (repository: RepositoryCreation, initialize: boolean) => {
120
- mutate({ repository, initialize });
121
- },
122
- isLoading,
123
- error,
124
- repository: data
125
- };
126
- };
127
-
128
- // TODO increase staleTime, infinite?
129
- export const useRepositoryTypes = () => useIndexJsonResource<RepositoryTypeCollection>("repositoryTypes");
130
-
131
- export const useRepository = (namespace: string, name: string): ApiResult<Repository> => {
132
- const link = useRequiredIndexLink("repositories");
133
- return useQuery<Repository, Error>(["repository", namespace, name], () =>
134
- apiClient.get(concat(link, namespace, name)).then(response => response.json())
135
- );
136
- };
137
-
138
- export type UseDeleteRepositoryOptions = {
139
- onSuccess: (repository: Repository) => void;
140
- };
141
-
142
- export const useDeleteRepository = (options?: UseDeleteRepositoryOptions) => {
143
- const queryClient = useQueryClient();
144
- const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
145
- repository => {
146
- const link = requiredLink(repository, "delete");
147
- return apiClient.delete(link);
148
- },
149
- {
150
- onSuccess: async (_, repository) => {
151
- if (options?.onSuccess) {
152
- options.onSuccess(repository);
153
- }
154
- queryClient.removeQueries(repoQueryKey(repository));
155
- await queryClient.invalidateQueries(["repositories"]);
156
- }
157
- }
158
- );
159
- return {
160
- remove: (repository: Repository) => mutate(repository),
161
- isLoading,
162
- error,
163
- isDeleted: !!data
164
- };
165
- };
166
-
167
- export const useUpdateRepository = () => {
168
- const queryClient = useQueryClient();
169
- const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
170
- repository => {
171
- const link = requiredLink(repository, "update");
172
- return apiClient.put(link, repository, "application/vnd.scmm-repository+json;v=2");
173
- },
174
- {
175
- onSuccess: async (_, repository) => {
176
- await queryClient.invalidateQueries(repoQueryKey(repository));
177
- await queryClient.invalidateQueries(["repositories"]);
178
- }
179
- }
180
- );
181
- return {
182
- update: (repository: Repository) => mutate(repository),
183
- isLoading,
184
- error,
185
- isUpdated: !!data
186
- };
187
- };
188
-
189
- export const useArchiveRepository = () => {
190
- const queryClient = useQueryClient();
191
- const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
192
- repository => {
193
- const link = requiredLink(repository, "archive");
194
- return apiClient.post(link);
195
- },
196
- {
197
- onSuccess: async (_, repository) => {
198
- await queryClient.invalidateQueries(repoQueryKey(repository));
199
- await queryClient.invalidateQueries(["repositories"]);
200
- }
201
- }
202
- );
203
- return {
204
- archive: (repository: Repository) => mutate(repository),
205
- isLoading,
206
- error,
207
- isArchived: !!data
208
- };
209
- };
210
-
211
- export const useUnarchiveRepository = () => {
212
- const queryClient = useQueryClient();
213
- const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
214
- repository => {
215
- const link = requiredLink(repository, "unarchive");
216
- return apiClient.post(link);
217
- },
218
- {
219
- onSuccess: async (_, repository) => {
220
- await queryClient.invalidateQueries(repoQueryKey(repository));
221
- await queryClient.invalidateQueries(["repositories"]);
222
- }
223
- }
224
- );
225
- return {
226
- unarchive: (repository: Repository) => mutate(repository),
227
- isLoading,
228
- error,
229
- isUnarchived: !!data
230
- };
231
- };
232
-
233
- export const useRunHealthCheck = () => {
234
- const queryClient = useQueryClient();
235
- const { mutate, isLoading, error, data } = useMutation<unknown, Error, Repository>(
236
- repository => {
237
- const link = requiredLink(repository, "runHealthCheck");
238
- return apiClient.post(link);
239
- },
240
- {
241
- onSuccess: async (_, repository) => {
242
- await queryClient.invalidateQueries(repoQueryKey(repository));
243
- }
244
- }
245
- );
246
- return {
247
- runHealthCheck: (repository: Repository) => mutate(repository),
248
- isLoading,
249
- error,
250
- isRunning: !!data
251
- };
252
- };
253
-
254
- export const useExportInfo = (repository: Repository): ApiResultWithFetching<ExportInfo> => {
255
- const link = requiredLink(repository, "exportInfo");
256
- //TODO Refetch while exporting to update the page
257
- const { isLoading, isFetching, error, data } = useQuery<ExportInfo, Error>(
258
- ["repository", repository.namespace, repository.name, "exportInfo"],
259
- () => apiClient.get(link).then(response => response.json()),
260
- {}
261
- );
262
-
263
- return {
264
- isLoading,
265
- isFetching,
266
- error: error instanceof NotFoundError ? null : error,
267
- data
268
- };
269
- };
270
-
271
- type ExportOptions = {
272
- compressed: boolean;
273
- withMetadata: boolean;
274
- password?: string;
275
- };
276
-
277
- type ExportRepositoryMutateOptions = {
278
- repository: Repository;
279
- options: ExportOptions;
280
- };
281
-
282
- const EXPORT_MEDIA_TYPE = "application/vnd.scmm-repositoryExport+json;v=2";
283
-
284
- export const useExportRepository = () => {
285
- const queryClient = useQueryClient();
286
- const [intervalId, setIntervalId] = useState<ReturnType<typeof setTimeout>>();
287
- useEffect(() => {
288
- return () => {
289
- if (intervalId) {
290
- clearInterval(intervalId);
291
- }
292
- };
293
- }, [intervalId]);
294
- const { mutate, isLoading, error, data } = useMutation<ExportInfo, Error, ExportRepositoryMutateOptions>(
295
- ({ repository, options }) => {
296
- const infolink = requiredLink(repository, "exportInfo");
297
- let link = requiredLink(repository, options.withMetadata ? "fullExport" : "export");
298
- if (options.compressed) {
299
- link += "?compressed=true";
300
- }
301
- return apiClient
302
- .post(link, { password: options.password, async: true }, EXPORT_MEDIA_TYPE)
303
- .then(() => queryClient.invalidateQueries(repoQueryKey(repository)))
304
- .then(() => queryClient.invalidateQueries(["repositories"]))
305
- .then(() => {
306
- return new Promise<ExportInfo>((resolve, reject) => {
307
- const id = setInterval(() => {
308
- apiClient
309
- .get(infolink)
310
- .then(r => r.json())
311
- .then((info: ExportInfo) => {
312
- if (info._links.download) {
313
- clearInterval(id);
314
- resolve(info);
315
- }
316
- })
317
- .catch(e => {
318
- clearInterval(id);
319
- reject(e);
320
- });
321
- }, 1000);
322
- setIntervalId(id);
323
- });
324
- });
325
- },
326
- {
327
- onSuccess: async (_, { repository }) => {
328
- await queryClient.invalidateQueries(repoQueryKey(repository));
329
- await queryClient.invalidateQueries(["repositories"]);
330
- }
331
- }
332
- );
333
- return {
334
- exportRepository: (repository: Repository, options: ExportOptions) => mutate({ repository, options }),
335
- isLoading,
336
- error,
337
- data
338
- };
339
- };
340
-
341
- export const usePaths = (repository: Repository, revision: string): ApiResult<Paths> => {
342
- const link = requiredLink(repository, "paths").replace("{revision}", revision);
343
- return useQuery<Paths, Error>(repoQueryKey(repository, "paths", revision), () =>
344
- apiClient.get(link).then(response => response.json())
345
- );
346
- };
347
-
348
- type RenameRepositoryRequest = {
349
- name: string;
350
- namespace: string;
351
- };
352
-
353
- export const useRenameRepository = (repository: Repository) => {
354
- const queryClient = useQueryClient();
355
-
356
- const url = objectLink(repository, "renameWithNamespace") || objectLink(repository, "rename");
357
-
358
- if (!url) {
359
- throw new MissingLinkError(`could not find rename link on repository ${repository.namespace}/${repository.name}`);
360
- }
361
-
362
- const { mutate, isLoading, error, data } = useMutation<unknown, Error, RenameRepositoryRequest>(
363
- ({ name, namespace }) => apiClient.post(url, { namespace, name }, "application/vnd.scmm-repository+json;v=2"),
364
- {
365
- onSuccess: () => queryClient.removeQueries(repoQueryKey(repository))
366
- }
367
- );
368
-
369
- return {
370
- renameRepository: (namespace: string, name: string) => mutate({ namespace, name }),
371
- isLoading,
372
- error,
373
- isRenamed: !!data
374
- };
375
- };
@@ -1,229 +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 { RepositoryRole, RepositoryRoleCollection } 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 { act } from "react-test-renderer";
32
- import {
33
- useCreateRepositoryRole,
34
- useDeleteRepositoryRole,
35
- useRepositoryRole,
36
- useRepositoryRoles,
37
- useUpdateRepositoryRole,
38
- } from "./repository-roles";
39
-
40
- describe("Test repository-roles hooks", () => {
41
- const roleName = "theroleingstones";
42
- const role: RepositoryRole = {
43
- name: roleName,
44
- verbs: ["rocking"],
45
- _links: {
46
- delete: {
47
- href: "/repositoryRoles/theroleingstones",
48
- },
49
- update: {
50
- href: "/repositoryRoles/theroleingstones",
51
- },
52
- },
53
- };
54
-
55
- const roleCollection: RepositoryRoleCollection = {
56
- page: 0,
57
- pageTotal: 0,
58
- _links: {},
59
- _embedded: {
60
- repositoryRoles: [role],
61
- },
62
- };
63
-
64
- afterEach(() => {
65
- fetchMock.reset();
66
- });
67
-
68
- describe("useRepositoryRoles tests", () => {
69
- it("should return repositoryRoles", async () => {
70
- const queryClient = createInfiniteCachingClient();
71
- setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
72
- fetchMock.get("/api/v2/repositoryRoles", roleCollection);
73
- const { result, waitFor } = renderHook(() => useRepositoryRoles(), {
74
- wrapper: createWrapper(undefined, queryClient),
75
- });
76
- await waitFor(() => !!result.current.data);
77
- expect(result.current.data).toEqual(roleCollection);
78
- });
79
-
80
- it("should return paged repositoryRoles", async () => {
81
- const queryClient = createInfiniteCachingClient();
82
- setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
83
- fetchMock.get("/api/v2/repositoryRoles", roleCollection, {
84
- query: {
85
- page: "42",
86
- },
87
- });
88
- const { result, waitFor } = renderHook(() => useRepositoryRoles({ page: 42 }), {
89
- wrapper: createWrapper(undefined, queryClient),
90
- });
91
- await waitFor(() => !!result.current.data);
92
- expect(result.current.data).toEqual(roleCollection);
93
- });
94
-
95
- it("should update repositoryRole cache", async () => {
96
- const queryClient = createInfiniteCachingClient();
97
- setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
98
- fetchMock.get("/api/v2/repositoryRoles", roleCollection);
99
- const { result, waitFor } = renderHook(() => useRepositoryRoles(), {
100
- wrapper: createWrapper(undefined, queryClient),
101
- });
102
- await waitFor(() => !!result.current.data);
103
- expect(queryClient.getQueryData(["repositoryRole", roleName])).toEqual(role);
104
- });
105
- });
106
-
107
- describe("useRepositoryRole tests", () => {
108
- it("should return repositoryRole", async () => {
109
- const queryClient = createInfiniteCachingClient();
110
- setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
111
- fetchMock.get("/api/v2/repositoryRoles/" + roleName, role);
112
- const { result, waitFor } = renderHook(() => useRepositoryRole(roleName), {
113
- wrapper: createWrapper(undefined, queryClient),
114
- });
115
- await waitFor(() => !!result.current.data);
116
- expect(result.current.data).toEqual(role);
117
- });
118
- });
119
-
120
- describe("useCreateRepositoryRole tests", () => {
121
- it("should create repositoryRole", async () => {
122
- const queryClient = createInfiniteCachingClient();
123
- setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
124
-
125
- fetchMock.postOnce("/api/v2/repositoryRoles", {
126
- status: 201,
127
- headers: {
128
- Location: "/repositoryRoles/" + roleName,
129
- },
130
- });
131
-
132
- fetchMock.getOnce("/api/v2/repositoryRoles/" + roleName, role);
133
-
134
- const { result, waitForNextUpdate } = renderHook(() => useCreateRepositoryRole(), {
135
- wrapper: createWrapper(undefined, queryClient),
136
- });
137
-
138
- await act(() => {
139
- const { create } = result.current;
140
- create(role);
141
- return waitForNextUpdate();
142
- });
143
-
144
- expect(result.current.repositoryRole).toEqual(role);
145
- });
146
-
147
- it("should fail without location header", async () => {
148
- const queryClient = createInfiniteCachingClient();
149
- setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
150
-
151
- fetchMock.postOnce("/api/v2/repositoryRoles", {
152
- status: 201,
153
- });
154
-
155
- fetchMock.getOnce("/api/v2/repositoryRoles/" + roleName, role);
156
-
157
- const { result, waitForNextUpdate } = renderHook(() => useCreateRepositoryRole(), {
158
- wrapper: createWrapper(undefined, queryClient),
159
- });
160
-
161
- await act(() => {
162
- const { create } = result.current;
163
- create(role);
164
- return waitForNextUpdate();
165
- });
166
-
167
- expect(result.current.error).toBeDefined();
168
- });
169
- });
170
-
171
- describe("useDeleteRepositoryRole tests", () => {
172
- it("should delete repositoryRole", async () => {
173
- const queryClient = createInfiniteCachingClient();
174
- setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
175
-
176
- fetchMock.deleteOnce("/api/v2/repositoryRoles/" + roleName, {
177
- status: 200,
178
- });
179
-
180
- const { result, waitForNextUpdate } = renderHook(() => useDeleteRepositoryRole(), {
181
- wrapper: createWrapper(undefined, queryClient),
182
- });
183
-
184
- await act(() => {
185
- const { remove } = result.current;
186
- remove(role);
187
- return waitForNextUpdate();
188
- });
189
-
190
- expect(result.current.error).toBeFalsy();
191
- expect(result.current.isDeleted).toBe(true);
192
- expect(result.current.isLoading).toBe(false);
193
- expect(queryClient.getQueryData(["repositoryRole", roleName])).toBeUndefined();
194
- });
195
- });
196
-
197
- describe("useUpdateRepositoryRole tests", () => {
198
- it("should update repositoryRole", async () => {
199
- const queryClient = createInfiniteCachingClient();
200
- setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
201
-
202
- const newRole: RepositoryRole = {
203
- ...role,
204
- name: "newname",
205
- };
206
-
207
- fetchMock.putOnce("/api/v2/repositoryRoles/" + roleName, {
208
- status: 200,
209
- });
210
-
211
- const { result, waitForNextUpdate } = renderHook(() => useUpdateRepositoryRole(), {
212
- wrapper: createWrapper(undefined, queryClient),
213
- });
214
-
215
- await act(() => {
216
- const { update } = result.current;
217
- update(newRole);
218
- return waitForNextUpdate();
219
- });
220
-
221
- expect(result.current.error).toBeFalsy();
222
- expect(result.current.isUpdated).toBe(true);
223
- expect(result.current.isLoading).toBe(false);
224
- expect(queryClient.getQueryData(["repositoryRole", roleName])).toBeUndefined();
225
- expect(queryClient.getQueryData(["repositoryRole", "newname"])).toBeUndefined();
226
- expect(queryClient.getQueryData(["repositoryRoles"])).toBeUndefined();
227
- });
228
- });
229
- });