@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,202 +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 { ApiResult, useIndexJsonResource, useJsonResource } from "./base";
25
- import { useMutation, useQuery, useQueryClient } from "react-query";
26
- import {
27
- GlobalPermissionsCollection,
28
- Group,
29
- Namespace,
30
- Permission,
31
- PermissionCollection,
32
- PermissionCreateEntry,
33
- Repository,
34
- RepositoryVerbs,
35
- User,
36
- } from "@scm-manager/ui-types";
37
- import { apiClient } from "./apiclient";
38
- import { objectLink, requiredLink } from "./links";
39
- import { repoQueryKey } from "./keys";
40
- import { useRepositoryRoles } from "./repository-roles";
41
-
42
- export const useRepositoryVerbs = (): ApiResult<RepositoryVerbs> => {
43
- return useIndexJsonResource<RepositoryVerbs>("repositoryVerbs");
44
- };
45
-
46
- /**
47
- * *IMPORTANT NOTE:* These are actually *REPOSITORY* permissions.
48
- */
49
- export const useAvailablePermissions = () => {
50
- const roles = useRepositoryRoles();
51
- const verbs = useRepositoryVerbs();
52
- let data;
53
- if (roles.data && verbs.data) {
54
- data = {
55
- repositoryVerbs: verbs.data.verbs,
56
- repositoryRoles: roles.data._embedded?.repositoryRoles || [],
57
- };
58
- }
59
-
60
- return {
61
- isLoading: roles.isLoading || verbs.isLoading,
62
- error: roles.error || verbs.error,
63
- data,
64
- };
65
- };
66
-
67
- const isRepository = (namespaceOrRepository: Namespace | Repository): namespaceOrRepository is Repository => {
68
- return (namespaceOrRepository as Repository).name !== undefined;
69
- };
70
-
71
- const createQueryKey = (namespaceOrRepository: Namespace | Repository) => {
72
- if (isRepository(namespaceOrRepository)) {
73
- return repoQueryKey(namespaceOrRepository, "permissions");
74
- } else {
75
- return ["namespace", namespaceOrRepository.namespace, "permissions"];
76
- }
77
- };
78
-
79
- export const usePermissions = (namespaceOrRepository: Namespace | Repository): ApiResult<PermissionCollection> => {
80
- const link = requiredLink(namespaceOrRepository, "permissions");
81
- const queryKey = createQueryKey(namespaceOrRepository);
82
- return useQuery<PermissionCollection, Error>(queryKey, () => apiClient.get(link).then((response) => response.json()));
83
- };
84
-
85
- const createPermission = (link: string) => {
86
- return (permission: PermissionCreateEntry) => {
87
- return apiClient
88
- .post(link, permission, "application/vnd.scmm-repositoryPermission+json")
89
- .then((response) => {
90
- const location = response.headers.get("Location");
91
- if (!location) {
92
- throw new Error("Server does not return required Location header");
93
- }
94
- return apiClient.get(location);
95
- })
96
- .then((response) => response.json());
97
- };
98
- };
99
-
100
- export const useCreatePermission = (namespaceOrRepository: Namespace | Repository) => {
101
- const queryClient = useQueryClient();
102
- const link = requiredLink(namespaceOrRepository, "permissions");
103
- const { isLoading, error, mutate, data } = useMutation<Permission, Error, PermissionCreateEntry>(
104
- createPermission(link),
105
- {
106
- onSuccess: () => {
107
- const queryKey = createQueryKey(namespaceOrRepository);
108
- return queryClient.invalidateQueries(queryKey);
109
- },
110
- }
111
- );
112
- return {
113
- isLoading,
114
- error,
115
- create: (permission: PermissionCreateEntry) => mutate(permission),
116
- permission: data,
117
- };
118
- };
119
-
120
- export const useUpdatePermission = (namespaceOrRepository: Namespace | Repository) => {
121
- const queryClient = useQueryClient();
122
- const { isLoading, error, mutate, data } = useMutation<unknown, Error, Permission>(
123
- (permission) => {
124
- const link = requiredLink(permission, "update");
125
- return apiClient.put(link, permission, "application/vnd.scmm-repositoryPermission+json");
126
- },
127
- {
128
- onSuccess: () => {
129
- const queryKey = createQueryKey(namespaceOrRepository);
130
- return queryClient.invalidateQueries(queryKey);
131
- },
132
- }
133
- );
134
- return {
135
- isLoading,
136
- error,
137
- update: (permission: Permission) => mutate(permission),
138
- isUpdated: !!data,
139
- };
140
- };
141
-
142
- export const useDeletePermission = (namespaceOrRepository: Namespace | Repository) => {
143
- const queryClient = useQueryClient();
144
- const { isLoading, error, mutate, data } = useMutation<unknown, Error, Permission>(
145
- (permission) => {
146
- const link = requiredLink(permission, "delete");
147
- return apiClient.delete(link);
148
- },
149
- {
150
- onSuccess: () => {
151
- const queryKey = createQueryKey(namespaceOrRepository);
152
- return queryClient.invalidateQueries(queryKey);
153
- },
154
- }
155
- );
156
- return {
157
- isLoading,
158
- error,
159
- remove: (permission: Permission) => mutate(permission),
160
- isDeleted: !!data,
161
- };
162
- };
163
-
164
- const userPermissionsKey = (user: User) => ["user", user.name, "permissions"];
165
- const groupPermissionsKey = (group: Group) => ["group", group.name, "permissions"];
166
-
167
- export const useGroupPermissions = (group: Group) =>
168
- useJsonResource<GlobalPermissionsCollection>(group, "permissions", groupPermissionsKey(group));
169
- export const useUserPermissions = (user: User) =>
170
- useJsonResource<GlobalPermissionsCollection>(user, "permissions", userPermissionsKey(user));
171
- export const useAvailableGlobalPermissions = () =>
172
- useIndexJsonResource<Omit<GlobalPermissionsCollection, "_links">>("permissions");
173
-
174
- const useSetEntityPermissions = (permissionCollection?: GlobalPermissionsCollection, key?: string[]) => {
175
- const queryClient = useQueryClient();
176
- const url = permissionCollection ? objectLink(permissionCollection, "overwrite") : null;
177
- const { isLoading, error, mutate, data } = useMutation<unknown, Error, string[]>(
178
- (permissions) =>
179
- apiClient.put(
180
- url!,
181
- {
182
- permissions,
183
- },
184
- "application/vnd.scmm-permissionCollection+json;v=2"
185
- ),
186
- {
187
- onSuccess: () => queryClient.invalidateQueries(key),
188
- }
189
- );
190
- const setPermissions = (permissions: string[]) => mutate(permissions);
191
- return {
192
- isLoading,
193
- error,
194
- setPermissions: url ? setPermissions : undefined,
195
- isUpdated: !!data,
196
- };
197
- };
198
-
199
- export const useSetUserPermissions = (user: User, permissions?: GlobalPermissionsCollection) =>
200
- useSetEntityPermissions(permissions, userPermissionsKey(user));
201
- export const useSetGroupPermissions = (group: Group, permissions?: GlobalPermissionsCollection) =>
202
- useSetEntityPermissions(permissions, groupPermissionsKey(group));
@@ -1,336 +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 { PendingPlugins, Plugin, PluginCollection } from "@scm-manager/ui-types";
26
- import createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
27
- import { setIndexLink } from "./tests/indexLinks";
28
- import fetchMock from "fetch-mock-jest";
29
- import { renderHook } from "@testing-library/react-hooks";
30
- import createWrapper from "./tests/createWrapper";
31
- import {
32
- useAvailablePlugins,
33
- useInstalledPlugins,
34
- useInstallPlugin,
35
- usePendingPlugins,
36
- useUninstallPlugin,
37
- useUpdatePlugins,
38
- } from "./plugins";
39
- import { act } from "react-test-renderer";
40
-
41
- describe("Test plugin hooks", () => {
42
- const availablePlugin: Plugin = {
43
- author: "Douglas Adams",
44
- category: "all",
45
- displayName: "Heart of Gold",
46
- version: "x.y.z",
47
- name: "heart-of-gold-plugin",
48
- pending: false,
49
- dependencies: [],
50
- optionalDependencies: [],
51
- type: "SCM",
52
- _links: {
53
- install: { href: "/plugins/available/heart-of-gold-plugin/install" },
54
- installWithRestart: {
55
- href: "/plugins/available/heart-of-gold-plugin/install?restart=true",
56
- },
57
- },
58
- };
59
-
60
- const installedPlugin: Plugin = {
61
- author: "Douglas Adams",
62
- category: "all",
63
- displayName: "Heart of Gold",
64
- version: "x.y.z",
65
- name: "heart-of-gold-plugin",
66
- pending: false,
67
- markedForUninstall: false,
68
- dependencies: [],
69
- optionalDependencies: [],
70
- type: "SCM",
71
- _links: {
72
- self: {
73
- href: "/plugins/installed/heart-of-gold-plugin",
74
- },
75
- update: {
76
- href: "/plugins/available/heart-of-gold-plugin/install",
77
- },
78
- updateWithRestart: {
79
- href: "/plugins/available/heart-of-gold-plugin/install?restart=true",
80
- },
81
- uninstall: {
82
- href: "/plugins/installed/heart-of-gold-plugin/uninstall",
83
- },
84
- uninstallWithRestart: {
85
- href: "/plugins/installed/heart-of-gold-plugin/uninstall?restart=true",
86
- },
87
- },
88
- };
89
-
90
- const installedCorePlugin: Plugin = {
91
- author: "Douglas Adams",
92
- category: "all",
93
- displayName: "Heart of Gold",
94
- version: "x.y.z",
95
- name: "heart-of-gold-core-plugin",
96
- pending: false,
97
- markedForUninstall: false,
98
- type: "SCM",
99
- dependencies: [],
100
- optionalDependencies: [],
101
- _links: {
102
- self: {
103
- href: "/plugins/installed/heart-of-gold-core-plugin",
104
- },
105
- },
106
- };
107
-
108
- const createPluginCollection = (plugins: Plugin[]): PluginCollection => ({
109
- _links: {
110
- update: {
111
- href: "/plugins/update",
112
- },
113
- },
114
- _embedded: {
115
- plugins,
116
- },
117
- });
118
-
119
- const createPendingPlugins = (
120
- newPlugins: Plugin[] = [],
121
- updatePlugins: Plugin[] = [],
122
- uninstallPlugins: Plugin[] = []
123
- ): PendingPlugins => ({
124
- _links: {},
125
- _embedded: {
126
- new: newPlugins,
127
- update: updatePlugins,
128
- uninstall: uninstallPlugins,
129
- },
130
- });
131
-
132
- afterEach(() => fetchMock.reset());
133
-
134
- describe("useAvailablePlugins tests", () => {
135
- it("should return availablePlugins", async () => {
136
- const availablePlugins = createPluginCollection([availablePlugin]);
137
- const queryClient = createInfiniteCachingClient();
138
- setIndexLink(queryClient, "availablePlugins", "/availablePlugins");
139
- fetchMock.get("/api/v2/availablePlugins", availablePlugins);
140
- const { result, waitFor } = renderHook(() => useAvailablePlugins(), {
141
- wrapper: createWrapper(undefined, queryClient),
142
- });
143
- await waitFor(() => !!result.current.data);
144
- expect(result.current.data).toEqual(availablePlugins);
145
- });
146
- });
147
-
148
- describe("useInstalledPlugins tests", () => {
149
- it("should return installedPlugins", async () => {
150
- const installedPlugins = createPluginCollection([installedPlugin, installedCorePlugin]);
151
- const queryClient = createInfiniteCachingClient();
152
- setIndexLink(queryClient, "installedPlugins", "/installedPlugins");
153
- fetchMock.get("/api/v2/installedPlugins", installedPlugins);
154
- const { result, waitFor } = renderHook(() => useInstalledPlugins(), {
155
- wrapper: createWrapper(undefined, queryClient),
156
- });
157
- await waitFor(() => !!result.current.data);
158
- expect(result.current.data).toEqual(installedPlugins);
159
- });
160
- });
161
-
162
- describe("usePendingPlugins tests", () => {
163
- it("should return pendingPlugins", async () => {
164
- const pendingPlugins = createPendingPlugins([availablePlugin]);
165
- const queryClient = createInfiniteCachingClient();
166
- setIndexLink(queryClient, "pendingPlugins", "/pendingPlugins");
167
- fetchMock.get("/api/v2/pendingPlugins", pendingPlugins);
168
- const { result, waitFor } = renderHook(() => usePendingPlugins(), {
169
- wrapper: createWrapper(undefined, queryClient),
170
- });
171
- await waitFor(() => !!result.current.data);
172
- expect(result.current.data).toEqual(pendingPlugins);
173
- });
174
- });
175
-
176
- describe("useInstallPlugin tests", () => {
177
- it("should use restart parameter", async () => {
178
- const queryClient = createInfiniteCachingClient();
179
- queryClient.setQueryData(["plugins", "available"], createPluginCollection([availablePlugin]));
180
- queryClient.setQueryData(["plugins", "installed"], createPluginCollection([]));
181
- queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
182
- fetchMock.post("/api/v2/plugins/available/heart-of-gold-plugin/install?restart=true", installedPlugin);
183
- fetchMock.get("/api/v2/", "Restarted");
184
- const { result, waitFor, waitForNextUpdate } = renderHook(() => useInstallPlugin(), {
185
- wrapper: createWrapper(undefined, queryClient),
186
- });
187
- await act(() => {
188
- const { install } = result.current;
189
- install(availablePlugin, { restart: true, initialDelay: 5, timeout: 5 });
190
- return waitForNextUpdate();
191
- });
192
- await waitFor(() => result.current.isInstalled);
193
- expect(queryClient.getQueryState(["plugins", "available"])!.isInvalidated).toBe(true);
194
- expect(queryClient.getQueryState(["plugins", "installed"])!.isInvalidated).toBe(true);
195
- expect(queryClient.getQueryState(["plugins", "pending"])!.isInvalidated).toBe(true);
196
- });
197
-
198
- it("should invalidate query keys", async () => {
199
- const queryClient = createInfiniteCachingClient();
200
- queryClient.setQueryData(["plugins", "available"], createPluginCollection([availablePlugin]));
201
- queryClient.setQueryData(["plugins", "installed"], createPluginCollection([]));
202
- queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
203
- fetchMock.post("/api/v2/plugins/available/heart-of-gold-plugin/install", installedPlugin);
204
- const { result, waitForNextUpdate } = renderHook(() => useInstallPlugin(), {
205
- wrapper: createWrapper(undefined, queryClient),
206
- });
207
- await act(() => {
208
- const { install } = result.current;
209
- install(availablePlugin);
210
- return waitForNextUpdate();
211
- });
212
- expect(queryClient.getQueryState(["plugins", "available"])!.isInvalidated).toBe(true);
213
- expect(queryClient.getQueryState(["plugins", "installed"])!.isInvalidated).toBe(true);
214
- expect(queryClient.getQueryState(["plugins", "pending"])!.isInvalidated).toBe(true);
215
- });
216
- });
217
-
218
- describe("useUninstallPlugin tests", () => {
219
- it("should use restart parameter", async () => {
220
- const queryClient = createInfiniteCachingClient();
221
- queryClient.setQueryData(["plugins", "available"], createPluginCollection([]));
222
- queryClient.setQueryData(["plugins", "installed"], createPluginCollection([installedPlugin]));
223
- queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
224
- fetchMock.post("/api/v2/plugins/installed/heart-of-gold-plugin/uninstall?restart=true", availablePlugin);
225
- fetchMock.get("/api/v2/", "Restarted");
226
- const { result, waitForNextUpdate, waitFor } = renderHook(() => useUninstallPlugin(), {
227
- wrapper: createWrapper(undefined, queryClient),
228
- });
229
- await act(() => {
230
- const { uninstall } = result.current;
231
- uninstall(installedPlugin, { restart: true, initialDelay: 5, timeout: 5 });
232
- return waitForNextUpdate();
233
- });
234
- await waitFor(() => result.current.isUninstalled);
235
- expect(queryClient.getQueryState(["plugins", "available"])!.isInvalidated).toBe(true);
236
- expect(queryClient.getQueryState(["plugins", "installed"])!.isInvalidated).toBe(true);
237
- expect(queryClient.getQueryState(["plugins", "pending"])!.isInvalidated).toBe(true);
238
- });
239
-
240
- it("should invalidate query keys", async () => {
241
- const queryClient = createInfiniteCachingClient();
242
- queryClient.setQueryData(["plugins", "available"], createPluginCollection([]));
243
- queryClient.setQueryData(["plugins", "installed"], createPluginCollection([installedPlugin]));
244
- queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
245
- fetchMock.post("/api/v2/plugins/installed/heart-of-gold-plugin/uninstall", availablePlugin);
246
- const { result, waitForNextUpdate } = renderHook(() => useUninstallPlugin(), {
247
- wrapper: createWrapper(undefined, queryClient),
248
- });
249
- await act(() => {
250
- const { uninstall } = result.current;
251
- uninstall(installedPlugin);
252
- return waitForNextUpdate();
253
- });
254
- expect(queryClient.getQueryState(["plugins", "available"])!.isInvalidated).toBe(true);
255
- expect(queryClient.getQueryState(["plugins", "installed"])!.isInvalidated).toBe(true);
256
- expect(queryClient.getQueryState(["plugins", "pending"])!.isInvalidated).toBe(true);
257
- });
258
- });
259
-
260
- describe("useUpdatePlugins tests", () => {
261
- it("should use restart parameter", async () => {
262
- const queryClient = createInfiniteCachingClient();
263
- queryClient.setQueryData(["plugins", "available"], createPluginCollection([]));
264
- queryClient.setQueryData(["plugins", "installed"], createPluginCollection([installedPlugin]));
265
- queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
266
- fetchMock.post("/api/v2/plugins/available/heart-of-gold-plugin/install?restart=true", installedPlugin);
267
- fetchMock.get("/api/v2/", "Restarted");
268
- const { result, waitForNextUpdate, waitFor } = renderHook(() => useUpdatePlugins(), {
269
- wrapper: createWrapper(undefined, queryClient),
270
- });
271
- await act(() => {
272
- const { update } = result.current;
273
- update(installedPlugin, { restart: true, timeout: 5, initialDelay: 5 });
274
- return waitForNextUpdate();
275
- });
276
- await waitFor(() => result.current.isUpdated);
277
- expect(queryClient.getQueryState(["plugins", "available"])!.isInvalidated).toBe(true);
278
- expect(queryClient.getQueryState(["plugins", "installed"])!.isInvalidated).toBe(true);
279
- expect(queryClient.getQueryState(["plugins", "pending"])!.isInvalidated).toBe(true);
280
- });
281
- it("should update collection", async () => {
282
- const queryClient = createInfiniteCachingClient();
283
- queryClient.setQueryData(["plugins", "available"], createPluginCollection([]));
284
- queryClient.setQueryData(["plugins", "installed"], createPluginCollection([installedPlugin]));
285
- queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
286
- fetchMock.post("/api/v2/plugins/update", installedPlugin);
287
- const { result, waitForNextUpdate } = renderHook(() => useUpdatePlugins(), {
288
- wrapper: createWrapper(undefined, queryClient),
289
- });
290
- await act(() => {
291
- const { update } = result.current;
292
- update(createPluginCollection([installedPlugin, installedCorePlugin]));
293
- return waitForNextUpdate();
294
- });
295
- expect(queryClient.getQueryState(["plugins", "available"])!.isInvalidated).toBe(true);
296
- expect(queryClient.getQueryState(["plugins", "installed"])!.isInvalidated).toBe(true);
297
- expect(queryClient.getQueryState(["plugins", "pending"])!.isInvalidated).toBe(true);
298
- });
299
- it("should ignore restart parameter collection", async () => {
300
- const queryClient = createInfiniteCachingClient();
301
- queryClient.setQueryData(["plugins", "available"], createPluginCollection([]));
302
- queryClient.setQueryData(["plugins", "installed"], createPluginCollection([installedPlugin]));
303
- queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
304
- fetchMock.post("/api/v2/plugins/update", installedPlugin);
305
- const { result, waitForNextUpdate } = renderHook(() => useUpdatePlugins(), {
306
- wrapper: createWrapper(undefined, queryClient),
307
- });
308
- await act(() => {
309
- const { update } = result.current;
310
- update(createPluginCollection([installedPlugin, installedCorePlugin]), { restart: true });
311
- return waitForNextUpdate();
312
- });
313
- expect(queryClient.getQueryState(["plugins", "available"])!.isInvalidated).toBe(true);
314
- expect(queryClient.getQueryState(["plugins", "installed"])!.isInvalidated).toBe(true);
315
- expect(queryClient.getQueryState(["plugins", "pending"])!.isInvalidated).toBe(true);
316
- });
317
- it("should invalidate query keys", async () => {
318
- const queryClient = createInfiniteCachingClient();
319
- queryClient.setQueryData(["plugins", "available"], createPluginCollection([]));
320
- queryClient.setQueryData(["plugins", "installed"], createPluginCollection([installedPlugin]));
321
- queryClient.setQueryData(["plugins", "pending"], createPendingPlugins());
322
- fetchMock.post("/api/v2/plugins/available/heart-of-gold-plugin/install", installedPlugin);
323
- const { result, waitForNextUpdate } = renderHook(() => useUpdatePlugins(), {
324
- wrapper: createWrapper(undefined, queryClient),
325
- });
326
- await act(() => {
327
- const { update } = result.current;
328
- update(installedPlugin);
329
- return waitForNextUpdate();
330
- });
331
- expect(queryClient.getQueryState(["plugins", "available"])!.isInvalidated).toBe(true);
332
- expect(queryClient.getQueryState(["plugins", "installed"])!.isInvalidated).toBe(true);
333
- expect(queryClient.getQueryState(["plugins", "pending"])!.isInvalidated).toBe(true);
334
- });
335
- });
336
- });