@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,508 +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 { renderHook } from "@testing-library/react-hooks";
27
- import createWrapper from "./tests/createWrapper";
28
- import { setIndexLink } from "./tests/indexLinks";
29
- import createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
30
- import {
31
- useArchiveRepository,
32
- useCreateRepository,
33
- useDeleteRepository,
34
- UseDeleteRepositoryOptions,
35
- useRepositories,
36
- UseRepositoriesRequest,
37
- useRepository,
38
- useRepositoryTypes,
39
- useUnarchiveRepository,
40
- useUpdateRepository
41
- } from "./repositories";
42
- import { Repository } from "@scm-manager/ui-types";
43
- import { QueryClient } from "react-query";
44
- import { act } from "react-test-renderer";
45
-
46
- describe("Test repository hooks", () => {
47
- const heartOfGold: Repository = {
48
- namespace: "spaceships",
49
- name: "heartOfGold",
50
- type: "git",
51
- _links: {
52
- delete: {
53
- href: "/r/spaceships/heartOfGold"
54
- },
55
- update: {
56
- href: "/r/spaceships/heartOfGold"
57
- },
58
- archive: {
59
- href: "/r/spaceships/heartOfGold/archive"
60
- },
61
- unarchive: {
62
- href: "/r/spaceships/heartOfGold/unarchive"
63
- }
64
- }
65
- };
66
-
67
- const repositoryCollection = {
68
- _embedded: {
69
- repositories: [heartOfGold]
70
- },
71
- _links: {}
72
- };
73
-
74
- afterEach(() => {
75
- fetchMock.reset();
76
- });
77
-
78
- describe("useRepositories tests", () => {
79
- const expectCollection = async (queryClient: QueryClient, request?: UseRepositoriesRequest) => {
80
- const { result, waitFor } = renderHook(() => useRepositories(request), {
81
- wrapper: createWrapper(undefined, queryClient)
82
- });
83
- await waitFor(() => {
84
- return !!result.current.data;
85
- });
86
- expect(result.current.data).toEqual(repositoryCollection);
87
- };
88
-
89
- it("should return repositories", async () => {
90
- const queryClient = createInfiniteCachingClient();
91
- setIndexLink(queryClient, "repositories", "/repos");
92
- fetchMock.get("/api/v2/repos", repositoryCollection);
93
-
94
- await expectCollection(queryClient);
95
- });
96
-
97
- it("should return repositories with page", async () => {
98
- const queryClient = createInfiniteCachingClient();
99
- setIndexLink(queryClient, "repositories", "/repos");
100
- fetchMock.get("/api/v2/repos", repositoryCollection, {
101
- query: {
102
- page: "42"
103
- }
104
- });
105
-
106
- await expectCollection(queryClient, {
107
- page: 42
108
- });
109
- });
110
-
111
- it("should use repository from namespace", async () => {
112
- const queryClient = createInfiniteCachingClient();
113
- setIndexLink(queryClient, "repositories", "/repos");
114
- fetchMock.get("/api/v2/spaceships", repositoryCollection);
115
-
116
- await expectCollection(queryClient, {
117
- namespace: {
118
- namespace: "spaceships",
119
- _links: {
120
- repositories: {
121
- href: "/spaceships"
122
- }
123
- }
124
- }
125
- });
126
- });
127
-
128
- it("should append search query", async () => {
129
- const queryClient = createInfiniteCachingClient();
130
- setIndexLink(queryClient, "repositories", "/repos");
131
- fetchMock.get("/api/v2/repos", repositoryCollection, {
132
- query: {
133
- q: "heart"
134
- }
135
- });
136
-
137
- await expectCollection(queryClient, {
138
- search: "heart"
139
- });
140
- });
141
-
142
- it("should update repository cache", async () => {
143
- const queryClient = createInfiniteCachingClient();
144
- setIndexLink(queryClient, "repositories", "/repos");
145
- fetchMock.get("/api/v2/repos", repositoryCollection);
146
-
147
- await expectCollection(queryClient);
148
-
149
- const repository = queryClient.getQueryData(["repository", "spaceships", "heartOfGold"]);
150
- expect(repository).toEqual(heartOfGold);
151
- });
152
-
153
- it("should return nothing if disabled", () => {
154
- const queryClient = createInfiniteCachingClient();
155
- setIndexLink(queryClient, "repositories", "/repos");
156
- const { result } = renderHook(() => useRepositories({ disabled: true }), {
157
- wrapper: createWrapper(undefined, queryClient)
158
- });
159
-
160
- expect(result.current.isLoading).toBe(false);
161
- expect(result.current.data).toBeFalsy();
162
- expect(result.current.error).toBeFalsy();
163
- });
164
- });
165
-
166
- describe("useCreateRepository tests", () => {
167
- it("should create repository", async () => {
168
- const queryClient = createInfiniteCachingClient();
169
- setIndexLink(queryClient, "repositories", "/r");
170
-
171
- fetchMock.postOnce("/api/v2/r", {
172
- status: 201,
173
- headers: {
174
- Location: "/r/spaceships/heartOfGold"
175
- }
176
- });
177
-
178
- fetchMock.getOnce("/api/v2/r/spaceships/heartOfGold", heartOfGold);
179
-
180
- const { result, waitForNextUpdate } = renderHook(() => useCreateRepository(), {
181
- wrapper: createWrapper(undefined, queryClient)
182
- });
183
-
184
- const repository = {
185
- ...heartOfGold
186
- };
187
-
188
- await act(() => {
189
- const { create } = result.current;
190
- create(repository, false);
191
- return waitForNextUpdate();
192
- });
193
-
194
- expect(result.current.repository).toEqual(heartOfGold);
195
- });
196
-
197
- it("should append initialize param", async () => {
198
- const queryClient = createInfiniteCachingClient();
199
- setIndexLink(queryClient, "repositories", "/r");
200
-
201
- fetchMock.postOnce("/api/v2/r?initialize=true", {
202
- status: 201,
203
- headers: {
204
- Location: "/r/spaceships/heartOfGold"
205
- }
206
- });
207
-
208
- fetchMock.getOnce("/api/v2/r/spaceships/heartOfGold", heartOfGold);
209
-
210
- const { result, waitForNextUpdate } = renderHook(() => useCreateRepository(), {
211
- wrapper: createWrapper(undefined, queryClient)
212
- });
213
-
214
- const repository = {
215
- ...heartOfGold
216
- };
217
-
218
- await act(() => {
219
- const { create } = result.current;
220
- create(repository, true);
221
- return waitForNextUpdate();
222
- });
223
-
224
- expect(result.current.repository).toEqual(heartOfGold);
225
- });
226
-
227
- it("should fail without location header", async () => {
228
- const queryClient = createInfiniteCachingClient();
229
- setIndexLink(queryClient, "repositories", "/r");
230
-
231
- fetchMock.postOnce("/api/v2/r", {
232
- status: 201
233
- });
234
-
235
- const { result, waitForNextUpdate } = renderHook(() => useCreateRepository(), {
236
- wrapper: createWrapper(undefined, queryClient)
237
- });
238
-
239
- const repository = {
240
- ...heartOfGold
241
- };
242
-
243
- await act(() => {
244
- const { create } = result.current;
245
- create(repository, false);
246
- return waitForNextUpdate();
247
- });
248
-
249
- expect(result.current.error).toBeDefined();
250
- });
251
- });
252
-
253
- describe("useRepository tests", () => {
254
- it("should return repository", async () => {
255
- const queryClient = createInfiniteCachingClient();
256
- setIndexLink(queryClient, "repositories", "/r");
257
- fetchMock.get("/api/v2/r/spaceships/heartOfGold", heartOfGold);
258
-
259
- const { result, waitFor } = renderHook(() => useRepository("spaceships", "heartOfGold"), {
260
- wrapper: createWrapper(undefined, queryClient)
261
- });
262
- await waitFor(() => {
263
- return !!result.current.data;
264
- });
265
- expect(result.current?.data?.type).toEqual("git");
266
- });
267
- });
268
-
269
- describe("useRepositoryTypes tests", () => {
270
- it("should return repository types", async () => {
271
- const queryClient = createInfiniteCachingClient();
272
- setIndexLink(queryClient, "repositoryTypes", "/rt");
273
- fetchMock.get("/api/v2/rt", {
274
- _embedded: {
275
- repositoryTypes: [
276
- {
277
- name: "git",
278
- displayName: "Git",
279
- _links: {}
280
- }
281
- ]
282
- },
283
- _links: {}
284
- });
285
-
286
- const { result, waitFor } = renderHook(() => useRepositoryTypes(), {
287
- wrapper: createWrapper(undefined, queryClient)
288
- });
289
- await waitFor(() => {
290
- return !!result.current.data;
291
- });
292
- expect(result.current.data).toBeDefined();
293
- if (result.current?.data) {
294
- expect(result.current?.data._embedded?.repositoryTypes[0].name).toEqual("git");
295
- }
296
- });
297
- });
298
-
299
- describe("useDeleteRepository tests", () => {
300
- const queryClient = createInfiniteCachingClient();
301
-
302
- beforeEach(() => {
303
- queryClient.clear();
304
- });
305
-
306
- const deleteRepository = async (options?: UseDeleteRepositoryOptions) => {
307
- fetchMock.deleteOnce("/api/v2/r/spaceships/heartOfGold", {
308
- status: 204
309
- });
310
-
311
- const { result, waitForNextUpdate } = renderHook(() => useDeleteRepository(options), {
312
- wrapper: createWrapper(undefined, queryClient)
313
- });
314
-
315
- await act(() => {
316
- const { remove } = result.current;
317
- remove(heartOfGold);
318
- return waitForNextUpdate();
319
- });
320
-
321
- return result.current;
322
- };
323
-
324
- const shouldRemoveQuery = async (queryKey: string[], data: unknown) => {
325
- queryClient.setQueryData(queryKey, data);
326
- await deleteRepository();
327
-
328
- const queryState = queryClient.getQueryState(queryKey);
329
- expect(queryState).toBeUndefined();
330
- };
331
-
332
- const shouldInvalidateQuery = async (queryKey: string[], data: unknown) => {
333
- queryClient.setQueryData(queryKey, data);
334
- await deleteRepository();
335
-
336
- const queryState = queryClient.getQueryState(queryKey);
337
- expect(queryState!.isInvalidated).toBe(true);
338
- };
339
-
340
- it("should delete repository", async () => {
341
- const { isDeleted } = await deleteRepository();
342
-
343
- expect(isDeleted).toBe(true);
344
- });
345
-
346
- it("should invalidate repository cache", async () => {
347
- await shouldRemoveQuery(["repository", "spaceships", "heartOfGold"], heartOfGold);
348
- });
349
-
350
- it("should invalidate repository collection cache", async () => {
351
- await shouldInvalidateQuery(["repositories"], repositoryCollection);
352
- });
353
-
354
- it("should call onSuccess callback", async () => {
355
- let repo;
356
- await deleteRepository({
357
- onSuccess: repository => {
358
- repo = repository;
359
- }
360
- });
361
- expect(repo).toEqual(heartOfGold);
362
- });
363
- });
364
-
365
- describe("useUpdateRepository tests", () => {
366
- const queryClient = createInfiniteCachingClient();
367
-
368
- beforeEach(() => {
369
- queryClient.clear();
370
- });
371
-
372
- const updateRepository = async () => {
373
- fetchMock.putOnce("/api/v2/r/spaceships/heartOfGold", {
374
- status: 204
375
- });
376
-
377
- const { result, waitForNextUpdate } = renderHook(() => useUpdateRepository(), {
378
- wrapper: createWrapper(undefined, queryClient)
379
- });
380
-
381
- await act(() => {
382
- const { update } = result.current;
383
- update(heartOfGold);
384
- return waitForNextUpdate();
385
- });
386
-
387
- return result.current;
388
- };
389
-
390
- const shouldInvalidateQuery = async (queryKey: string[], data: unknown) => {
391
- queryClient.setQueryData(queryKey, data);
392
- await updateRepository();
393
-
394
- const queryState = queryClient.getQueryState(queryKey);
395
- expect(queryState!.isInvalidated).toBe(true);
396
- };
397
-
398
- it("should update repository", async () => {
399
- const { isUpdated } = await updateRepository();
400
-
401
- expect(isUpdated).toBe(true);
402
- });
403
-
404
- it("should invalidate repository cache", async () => {
405
- await shouldInvalidateQuery(["repository", "spaceships", "heartOfGold"], heartOfGold);
406
- });
407
-
408
- it("should invalidate repository collection cache", async () => {
409
- await shouldInvalidateQuery(["repositories"], repositoryCollection);
410
- });
411
- });
412
-
413
- describe("useArchiveRepository tests", () => {
414
- const queryClient = createInfiniteCachingClient();
415
-
416
- beforeEach(() => {
417
- queryClient.clear();
418
- });
419
-
420
- const archiveRepository = async () => {
421
- fetchMock.postOnce("/api/v2/r/spaceships/heartOfGold/archive", {
422
- status: 204
423
- });
424
-
425
- const { result, waitForNextUpdate } = renderHook(() => useArchiveRepository(), {
426
- wrapper: createWrapper(undefined, queryClient)
427
- });
428
-
429
- await act(() => {
430
- const { archive } = result.current;
431
- archive(heartOfGold);
432
- return waitForNextUpdate();
433
- });
434
-
435
- return result.current;
436
- };
437
-
438
- const shouldInvalidateQuery = async (queryKey: string[], data: unknown) => {
439
- queryClient.setQueryData(queryKey, data);
440
- await archiveRepository();
441
-
442
- const queryState = queryClient.getQueryState(queryKey);
443
- expect(queryState!.isInvalidated).toBe(true);
444
- };
445
-
446
- it("should archive repository", async () => {
447
- const { isArchived } = await archiveRepository();
448
-
449
- expect(isArchived).toBe(true);
450
- });
451
-
452
- it("should invalidate repository cache", async () => {
453
- await shouldInvalidateQuery(["repository", "spaceships", "heartOfGold"], heartOfGold);
454
- });
455
-
456
- it("should invalidate repository collection cache", async () => {
457
- await shouldInvalidateQuery(["repositories"], repositoryCollection);
458
- });
459
- });
460
-
461
- describe("useUnarchiveRepository tests", () => {
462
- const queryClient = createInfiniteCachingClient();
463
-
464
- beforeEach(() => {
465
- queryClient.clear();
466
- });
467
-
468
- const unarchiveRepository = async () => {
469
- fetchMock.postOnce("/api/v2/r/spaceships/heartOfGold/unarchive", {
470
- status: 204
471
- });
472
-
473
- const { result, waitForNextUpdate } = renderHook(() => useUnarchiveRepository(), {
474
- wrapper: createWrapper(undefined, queryClient)
475
- });
476
-
477
- await act(() => {
478
- const { unarchive } = result.current;
479
- unarchive(heartOfGold);
480
- return waitForNextUpdate();
481
- });
482
-
483
- return result.current;
484
- };
485
-
486
- const shouldInvalidateQuery = async (queryKey: string[], data: unknown) => {
487
- queryClient.setQueryData(queryKey, data);
488
- await unarchiveRepository();
489
-
490
- const queryState = queryClient.getQueryState(queryKey);
491
- expect(queryState!.isInvalidated).toBe(true);
492
- };
493
-
494
- it("should unarchive repository", async () => {
495
- const { isUnarchived } = await unarchiveRepository();
496
-
497
- expect(isUnarchived).toBe(true);
498
- });
499
-
500
- it("should invalidate repository cache", async () => {
501
- await shouldInvalidateQuery(["repository", "spaceships", "heartOfGold"], heartOfGold);
502
- });
503
-
504
- it("should invalidate repository collection cache", async () => {
505
- await shouldInvalidateQuery(["repositories"], repositoryCollection);
506
- });
507
- });
508
- });