@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/urls.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 queryString from "query-string";
|
|
26
|
-
|
|
27
|
-
//@ts-ignore
|
|
28
|
-
export const contextPath = window.ctxPath || "";
|
|
29
|
-
|
|
30
|
-
export function withContextPath(path: string) {
|
|
31
|
-
return contextPath + path;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function withEndingSlash(url: string) {
|
|
35
|
-
if (url.endsWith("/")) {
|
|
36
|
-
return url;
|
|
37
|
-
}
|
|
38
|
-
return url + "/";
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function withStartingSlash(url: string) {
|
|
42
|
-
if (url.startsWith("/")) {
|
|
43
|
-
return url;
|
|
44
|
-
}
|
|
45
|
-
return "/" + url;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function concat(base: string, ...parts: string[]) {
|
|
49
|
-
let url = base;
|
|
50
|
-
for (const p of parts) {
|
|
51
|
-
url = withEndingSlash(url) + p;
|
|
52
|
-
}
|
|
53
|
-
return url;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function getNamespaceAndPageFromMatch(match: any) {
|
|
57
|
-
const namespaceFromMatch: string = match.params.namespace;
|
|
58
|
-
const pageFromMatch: string = match.params.page;
|
|
59
|
-
|
|
60
|
-
if (!namespaceFromMatch && !pageFromMatch) {
|
|
61
|
-
return { namespace: undefined, page: 1 };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!pageFromMatch) {
|
|
65
|
-
if (namespaceFromMatch.match(/^\d{1,3}$/)) {
|
|
66
|
-
return { namespace: undefined, page: parsePageNumber(namespaceFromMatch) };
|
|
67
|
-
} else {
|
|
68
|
-
return { namespace: namespaceFromMatch, page: 1 };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return { namespace: namespaceFromMatch, page: parsePageNumber(pageFromMatch) };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function getPageFromMatch(match: any) {
|
|
76
|
-
return parsePageNumber(match.params.page);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function parsePageNumber(pageAsString: string) {
|
|
80
|
-
const page = parseInt(pageAsString, 10);
|
|
81
|
-
if (isNaN(page) || !page) {
|
|
82
|
-
return 1;
|
|
83
|
-
}
|
|
84
|
-
return page;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function getQueryStringFromLocation(location: { search?: string }): string | undefined {
|
|
88
|
-
if (location.search) {
|
|
89
|
-
const query = queryString.parse(location.search).q;
|
|
90
|
-
if (query && !Array.isArray(query)) {
|
|
91
|
-
return query;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function stripEndingSlash(url: string) {
|
|
97
|
-
if (url.endsWith("/")) {
|
|
98
|
-
return url.substring(0, url.length - 1);
|
|
99
|
-
}
|
|
100
|
-
return url;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function matchedUrlFromMatch(match: any) {
|
|
104
|
-
return stripEndingSlash(match.url);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function matchedUrl(props: any) {
|
|
108
|
-
const match = props.match;
|
|
109
|
-
return matchedUrlFromMatch(match);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function escapeUrlForRoute(url: string) {
|
|
113
|
-
return url.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function unescapeUrlForRoute(url: string) {
|
|
117
|
-
return url.replace(/\\/g, "");
|
|
118
|
-
}
|
|
@@ -1,91 +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 { Link, PluginCenterAuthenticationInfo } from "@scm-manager/ui-types";
|
|
27
|
-
import { useMutation, useQuery, useQueryClient } from "react-query";
|
|
28
|
-
import { apiClient } from "./apiclient";
|
|
29
|
-
import { useLocation } from "react-router-dom";
|
|
30
|
-
|
|
31
|
-
const appendQueryParam = (link: Link, name: string, value: string) => {
|
|
32
|
-
let href = link.href;
|
|
33
|
-
if (href.includes("?")) {
|
|
34
|
-
href += "&";
|
|
35
|
-
} else {
|
|
36
|
-
href += "?";
|
|
37
|
-
}
|
|
38
|
-
link.href = href + name + "=" + value;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const usePluginCenterAuthInfo = (): ApiResult<PluginCenterAuthenticationInfo> => {
|
|
42
|
-
const link = useIndexLink("pluginCenterAuth");
|
|
43
|
-
const location = useLocation();
|
|
44
|
-
return useQuery<PluginCenterAuthenticationInfo, Error>(
|
|
45
|
-
["pluginCenterAuth"],
|
|
46
|
-
() => {
|
|
47
|
-
if (!link) {
|
|
48
|
-
throw new Error("no such plugin center auth link");
|
|
49
|
-
}
|
|
50
|
-
return apiClient
|
|
51
|
-
.get(link)
|
|
52
|
-
.then(response => response.json())
|
|
53
|
-
.then((result: PluginCenterAuthenticationInfo) => {
|
|
54
|
-
if (result._links?.login) {
|
|
55
|
-
appendQueryParam(result._links.login as Link, "source", location.pathname);
|
|
56
|
-
}
|
|
57
|
-
if (result._links?.reconnect) {
|
|
58
|
-
appendQueryParam(result._links.reconnect as Link, "source", location.pathname);
|
|
59
|
-
}
|
|
60
|
-
return result;
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
enabled: !!link
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const usePluginCenterLogout = (authenticationInfo: PluginCenterAuthenticationInfo) => {
|
|
70
|
-
const queryClient = useQueryClient();
|
|
71
|
-
const { mutate, isLoading, error } = useMutation<unknown, Error>(
|
|
72
|
-
() => {
|
|
73
|
-
if (!authenticationInfo._links.logout) {
|
|
74
|
-
throw new Error("authenticationInfo has no logout link");
|
|
75
|
-
}
|
|
76
|
-
const logout = authenticationInfo._links.logout as Link;
|
|
77
|
-
return apiClient.delete(logout.href);
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
onSuccess: () => queryClient.invalidateQueries("pluginCenterAuth")
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
logout: () => {
|
|
86
|
-
mutate();
|
|
87
|
-
},
|
|
88
|
-
isLoading,
|
|
89
|
-
error
|
|
90
|
-
};
|
|
91
|
-
};
|
package/src/userSuggestions.ts
DELETED
|
@@ -1,32 +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 { Link } from "@scm-manager/ui-types";
|
|
25
|
-
import { useIndexLinks } from "./base";
|
|
26
|
-
import { useSuggestions } from "./suggestions";
|
|
27
|
-
|
|
28
|
-
export const useUserSuggestions = () => {
|
|
29
|
-
const indexLinks = useIndexLinks();
|
|
30
|
-
const autocompleteLink = (indexLinks.autocomplete as Link[]).find((i) => i.name === "users");
|
|
31
|
-
return useSuggestions(autocompleteLink?.href);
|
|
32
|
-
};
|
package/src/users.test.ts
DELETED
|
@@ -1,310 +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 { User, UserCollection } 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
|
-
useConvertToExternal,
|
|
34
|
-
useConvertToInternal,
|
|
35
|
-
useCreateUser,
|
|
36
|
-
useDeleteUser,
|
|
37
|
-
useUpdateUser,
|
|
38
|
-
useUser,
|
|
39
|
-
useUsers,
|
|
40
|
-
} from "./users";
|
|
41
|
-
|
|
42
|
-
describe("Test user hooks", () => {
|
|
43
|
-
const yoda: User = {
|
|
44
|
-
active: false,
|
|
45
|
-
displayName: "",
|
|
46
|
-
external: false,
|
|
47
|
-
password: "",
|
|
48
|
-
name: "yoda",
|
|
49
|
-
_links: {
|
|
50
|
-
delete: {
|
|
51
|
-
href: "/users/yoda",
|
|
52
|
-
},
|
|
53
|
-
update: {
|
|
54
|
-
href: "/users/yoda",
|
|
55
|
-
},
|
|
56
|
-
convertToInternal: {
|
|
57
|
-
href: "/users/yoda/convertToInternal",
|
|
58
|
-
},
|
|
59
|
-
convertToExternal: {
|
|
60
|
-
href: "/users/yoda/convertToExternal",
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
_embedded: {
|
|
64
|
-
members: [],
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const userCollection: UserCollection = {
|
|
69
|
-
_links: {},
|
|
70
|
-
page: 0,
|
|
71
|
-
pageTotal: 0,
|
|
72
|
-
_embedded: {
|
|
73
|
-
users: [yoda],
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
afterEach(() => {
|
|
78
|
-
fetchMock.reset();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("useUsers tests", () => {
|
|
82
|
-
it("should return users", async () => {
|
|
83
|
-
const queryClient = createInfiniteCachingClient();
|
|
84
|
-
setIndexLink(queryClient, "users", "/users");
|
|
85
|
-
fetchMock.get("/api/v2/users", userCollection);
|
|
86
|
-
const { result, waitFor } = renderHook(() => useUsers(), {
|
|
87
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
88
|
-
});
|
|
89
|
-
await waitFor(() => !!result.current.data);
|
|
90
|
-
expect(result.current.data).toEqual(userCollection);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("should return paged users", async () => {
|
|
94
|
-
const queryClient = createInfiniteCachingClient();
|
|
95
|
-
setIndexLink(queryClient, "users", "/users");
|
|
96
|
-
fetchMock.get("/api/v2/users", userCollection, {
|
|
97
|
-
query: {
|
|
98
|
-
page: "42",
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
const { result, waitFor } = renderHook(() => useUsers({ page: 42 }), {
|
|
102
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
103
|
-
});
|
|
104
|
-
await waitFor(() => !!result.current.data);
|
|
105
|
-
expect(result.current.data).toEqual(userCollection);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should return searched users", async () => {
|
|
109
|
-
const queryClient = createInfiniteCachingClient();
|
|
110
|
-
setIndexLink(queryClient, "users", "/users");
|
|
111
|
-
fetchMock.get("/api/v2/users", userCollection, {
|
|
112
|
-
query: {
|
|
113
|
-
q: "yoda",
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
const { result, waitFor } = renderHook(() => useUsers({ search: "yoda" }), {
|
|
117
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
118
|
-
});
|
|
119
|
-
await waitFor(() => !!result.current.data);
|
|
120
|
-
expect(result.current.data).toEqual(userCollection);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should update user cache", async () => {
|
|
124
|
-
const queryClient = createInfiniteCachingClient();
|
|
125
|
-
setIndexLink(queryClient, "users", "/users");
|
|
126
|
-
fetchMock.get("/api/v2/users", userCollection);
|
|
127
|
-
const { result, waitFor } = renderHook(() => useUsers(), {
|
|
128
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
129
|
-
});
|
|
130
|
-
await waitFor(() => !!result.current.data);
|
|
131
|
-
expect(queryClient.getQueryData(["user", "yoda"])).toEqual(yoda);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("useUser tests", () => {
|
|
136
|
-
it("should return user", async () => {
|
|
137
|
-
const queryClient = createInfiniteCachingClient();
|
|
138
|
-
setIndexLink(queryClient, "users", "/users");
|
|
139
|
-
fetchMock.get("/api/v2/users/yoda", yoda);
|
|
140
|
-
const { result, waitFor } = renderHook(() => useUser("yoda"), {
|
|
141
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
142
|
-
});
|
|
143
|
-
await waitFor(() => !!result.current.data);
|
|
144
|
-
expect(result.current.data).toEqual(yoda);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe("useCreateUser tests", () => {
|
|
149
|
-
it("should create user", async () => {
|
|
150
|
-
const queryClient = createInfiniteCachingClient();
|
|
151
|
-
setIndexLink(queryClient, "users", "/users");
|
|
152
|
-
|
|
153
|
-
fetchMock.postOnce("/api/v2/users", {
|
|
154
|
-
status: 201,
|
|
155
|
-
headers: {
|
|
156
|
-
Location: "/users/yoda",
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
fetchMock.getOnce("/api/v2/users/yoda", yoda);
|
|
161
|
-
|
|
162
|
-
const { result, waitForNextUpdate } = renderHook(() => useCreateUser(), {
|
|
163
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
await act(() => {
|
|
167
|
-
const { create } = result.current;
|
|
168
|
-
create(yoda);
|
|
169
|
-
return waitForNextUpdate();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
expect(result.current.user).toEqual(yoda);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("should fail without location header", async () => {
|
|
176
|
-
const queryClient = createInfiniteCachingClient();
|
|
177
|
-
setIndexLink(queryClient, "users", "/users");
|
|
178
|
-
|
|
179
|
-
fetchMock.postOnce("/api/v2/users", {
|
|
180
|
-
status: 201,
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
fetchMock.getOnce("/api/v2/users/yoda", yoda);
|
|
184
|
-
|
|
185
|
-
const { result, waitForNextUpdate } = renderHook(() => useCreateUser(), {
|
|
186
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
await act(() => {
|
|
190
|
-
const { create } = result.current;
|
|
191
|
-
create(yoda);
|
|
192
|
-
return waitForNextUpdate();
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
expect(result.current.error).toBeDefined();
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
describe("useDeleteUser tests", () => {
|
|
200
|
-
it("should delete user", async () => {
|
|
201
|
-
const queryClient = createInfiniteCachingClient();
|
|
202
|
-
setIndexLink(queryClient, "users", "/users");
|
|
203
|
-
|
|
204
|
-
fetchMock.deleteOnce("/api/v2/users/yoda", {
|
|
205
|
-
status: 200,
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
const { result, waitForNextUpdate } = renderHook(() => useDeleteUser(), {
|
|
209
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
await act(() => {
|
|
213
|
-
const { remove } = result.current;
|
|
214
|
-
remove(yoda);
|
|
215
|
-
return waitForNextUpdate();
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
expect(result.current.error).toBeFalsy();
|
|
219
|
-
expect(result.current.isDeleted).toBe(true);
|
|
220
|
-
expect(result.current.isLoading).toBe(false);
|
|
221
|
-
expect(queryClient.getQueryData(["user", "yoda"])).toBeUndefined();
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
describe("useUpdateUser tests", () => {
|
|
226
|
-
it("should update user", async () => {
|
|
227
|
-
const queryClient = createInfiniteCachingClient();
|
|
228
|
-
setIndexLink(queryClient, "users", "/users");
|
|
229
|
-
|
|
230
|
-
const newJedis = {
|
|
231
|
-
...yoda,
|
|
232
|
-
description: "may the 4th be with you",
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
fetchMock.putOnce("/api/v2/users/yoda", {
|
|
236
|
-
status: 200,
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
fetchMock.getOnce("/api/v2/users/yoda", newJedis);
|
|
240
|
-
|
|
241
|
-
const { result, waitForNextUpdate } = renderHook(() => useUpdateUser(), {
|
|
242
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
await act(() => {
|
|
246
|
-
const { update } = result.current;
|
|
247
|
-
update(newJedis);
|
|
248
|
-
return waitForNextUpdate();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
expect(result.current.error).toBeFalsy();
|
|
252
|
-
expect(result.current.isUpdated).toBe(true);
|
|
253
|
-
expect(result.current.isLoading).toBe(false);
|
|
254
|
-
expect(queryClient.getQueryData(["user", "yoda"])).toBeUndefined();
|
|
255
|
-
expect(queryClient.getQueryData(["users"])).toBeUndefined();
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
describe("useConvertToInternal tests", () => {
|
|
260
|
-
it("should convert user", async () => {
|
|
261
|
-
const queryClient = createInfiniteCachingClient();
|
|
262
|
-
|
|
263
|
-
fetchMock.putOnce("/api/v2/users/yoda/convertToInternal", {
|
|
264
|
-
status: 200,
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
const { result, waitForNextUpdate } = renderHook(() => useConvertToInternal(), {
|
|
268
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
await act(() => {
|
|
272
|
-
const { convertToInternal } = result.current;
|
|
273
|
-
convertToInternal(yoda, "thisisaverystrongpassword");
|
|
274
|
-
return waitForNextUpdate();
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
expect(result.current.error).toBeFalsy();
|
|
278
|
-
expect(result.current.isConverted).toBe(true);
|
|
279
|
-
expect(result.current.isLoading).toBe(false);
|
|
280
|
-
expect(queryClient.getQueryData(["user", "yoda"])).toBeUndefined();
|
|
281
|
-
expect(queryClient.getQueryData(["users"])).toBeUndefined();
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
describe("useConvertToExternal tests", () => {
|
|
286
|
-
it("should convert user", async () => {
|
|
287
|
-
const queryClient = createInfiniteCachingClient();
|
|
288
|
-
|
|
289
|
-
fetchMock.putOnce("/api/v2/users/yoda/convertToExternal", {
|
|
290
|
-
status: 200,
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
const { result, waitForNextUpdate } = renderHook(() => useConvertToExternal(), {
|
|
294
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
await act(() => {
|
|
298
|
-
const { convertToExternal } = result.current;
|
|
299
|
-
convertToExternal(yoda);
|
|
300
|
-
return waitForNextUpdate();
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
expect(result.current.error).toBeFalsy();
|
|
304
|
-
expect(result.current.isConverted).toBe(true);
|
|
305
|
-
expect(result.current.isLoading).toBe(false);
|
|
306
|
-
expect(queryClient.getQueryData(["user", "yoda"])).toBeUndefined();
|
|
307
|
-
expect(queryClient.getQueryData(["users"])).toBeUndefined();
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
});
|