Skip to content

Commit

Permalink
Bump axios from 0.27.2 to 1.1.3 in /dashboard (#5475)
Browse files Browse the repository at this point in the history
Bumps [axios](https://github.com/axios/axios) from 0.27.2 to 1.1.3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/axios/axios/releases">axios's
releases</a>.</em></p>
<blockquote>
<h2>v1.1.3</h2>
<h3>Added</h3>
<p>Added custom params serializer support <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5113">#5113</a></p>
<h3>Fixed</h3>
<p>Fixed top-level export to keep them in-line with static properties <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5109">#5109</a>
Stopped including null values to query string. <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5108">#5108</a>
Restored proxy config backwards compatibility with 0.x <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5097">#5097</a>
Added back AxiosHeaders in AxiosHeaderValue <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5103">#5103</a>
Pin CDN install instructions to a specific version <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5060">#5060</a>
Handling of array values fixed for AxiosHeaders <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5085">#5085</a></p>
<h3>Chores</h3>
<p>docs: match badge style, add link to them <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5046">#5046</a>
chore: fixing comments typo <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5054">#5054</a>
chore: update issue template <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5061">#5061</a>
chore: added progress capturing section to the docs; <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5084">#5084</a></p>
<h3>Contributors to this release</h3>
<ul>
<li><a href="https://github.com/jasonsaayman">Jason Saayman</a></li>
<li><a href="https://github.com/scarf005">scarf</a></li>
<li><a href="https://github.com/phryneas">Lenz Weber-Tronic</a></li>
<li><a href="https://github.com/itsarvindh">Arvindh</a></li>
<li><a href="https://github.com/FelixLgr">Félix Legrelle</a></li>
<li><a href="https://github.com/ppati000">Patrick Petrovic</a></li>
<li><a href="https://github.com/DigitalBrainJS">Dmitriy
Mozgovoy</a></li>
<li><a href="https://github.com/littledian">littledian</a></li>
<li><a
href="https://github.com/ChronosMasterOfAllTime">ChronosMasterOfAllTime</a></li>
<li><a href="https://github.com/salmannotkhan">Salman Shaikh</a></li>
</ul>
<h2>v1.1.2</h2>
<h3>Fixed</h3>
<ul>
<li>Fixed broken exports for UMD builds.</li>
</ul>
<h3>Contributors to this release</h3>
<ul>
<li><a href="https://github.com/jasonsaayman">Jason Saayman</a></li>
</ul>
<h2>v1.1.1</h2>
<h3>Fixed</h3>
<ul>
<li>Fixed broken exports for common js. This fix breaks a prior fix, I
will fix both issues ASAP but the commonJS use is more impactful.</li>
</ul>
<h3>Contributors to this release</h3>
<ul>
<li><a href="https://github.com/jasonsaayman">Jason Saayman</a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/axios/axios/blob/v1.x/CHANGELOG.md">axios's
changelog</a>.</em></p>
<blockquote>
<h2>[1.1.3] - 2022-10-15</h2>
<h3>Added</h3>
<p>Added custom params serializer support <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5113">#5113</a></p>
<h3>Fixed</h3>
<p>Fixed top-level export to keep them in-line with static properties <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5109">#5109</a>
Stopped including null values to query string. <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5108">#5108</a>
Restored proxy config backwards compatibility with 0.x <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5097">#5097</a>
Added back AxiosHeaders in AxiosHeaderValue <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5103">#5103</a>
Pin CDN install instructions to a specific version <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5060">#5060</a>
Handling of array values fixed for AxiosHeaders <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5085">#5085</a></p>
<h3>Chores</h3>
<p>docs: match badge style, add link to them <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5046">#5046</a>
chore: fixing comments typo <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5054">#5054</a>
chore: update issue template <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5061">#5061</a>
chore: added progress capturing section to the docs; <a
href="https://github-redirect.dependabot.com/axios/axios/pull/5084">#5084</a></p>
<h3>Contributors to this release</h3>
<ul>
<li><a href="https://github.com/jasonsaayman">Jason Saayman</a></li>
<li><a href="https://github.com/scarf005">scarf</a></li>
<li><a href="https://github.com/phryneas">Lenz Weber-Tronic</a></li>
<li><a href="https://github.com/itsarvindh">Arvindh</a></li>
<li><a href="https://github.com/FelixLgr">Félix Legrelle</a></li>
<li><a href="https://github.com/ppati000">Patrick Petrovic</a></li>
<li><a href="https://github.com/DigitalBrainJS">Dmitriy
Mozgovoy</a></li>
<li><a href="https://github.com/littledian">littledian</a></li>
<li><a
href="https://github.com/ChronosMasterOfAllTime">ChronosMasterOfAllTime</a></li>
<li><a href="https://github.com/salmannotkhan">Salman Shaikh</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/axios/axios/commit/9bd53214f6339c3064d4faee91c223b35846f2dd"><code>9bd5321</code></a>
chore: release 1.1.3</li>
<li><a
href="https://github.com/axios/axios/commit/b0ebf9fcacbab3e5a020a1a4d5d3837342d7dcd7"><code>b0ebf9f</code></a>
Fix: Don't add null values to query string. (<a
href="https://github-redirect.dependabot.com/axios/axios/issues/5108">#5108</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/ef1c48a476f1712c6ae281407b301a75b83b6482"><code>ef1c48a</code></a>
fix: eep top-level export same with static properties (<a
href="https://github-redirect.dependabot.com/axios/axios/issues/5109">#5109</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/9d4b016ddedf835bfd838b63e50af14d84e2813e"><code>9d4b016</code></a>
feat: added custom params serializer support; (<a
href="https://github-redirect.dependabot.com/axios/axios/issues/5113">#5113</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/ed19414b33a1c12022479ef5a9980121bb8e8afb"><code>ed19414</code></a>
fix: added <code>AxiosHeaders</code> in <code>AxiosHeaderValue</code>
(<a
href="https://github-redirect.dependabot.com/axios/axios/issues/5103">#5103</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/717f476b0f19e51a1794b6a3409ceaa1fe9b456e"><code>717f476</code></a>
fix: restore proxy config backwards compatibility with 0.x (<a
href="https://github-redirect.dependabot.com/axios/axios/issues/5097">#5097</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/83454a55f6274ee4d7b5cce6c608a62c5aa6b0cb"><code>83454a5</code></a>
chore: added progress capturing section to the docs; (<a
href="https://github-redirect.dependabot.com/axios/axios/issues/5084">#5084</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/e7b3f553e9c208a4af46e9f59599c1fd72d16c2f"><code>e7b3f55</code></a>
chore: update issue template (<a
href="https://github-redirect.dependabot.com/axios/axios/issues/5061">#5061</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/eedd9aafa505f7da5f99bb1eb983c3ff3f5929f8"><code>eedd9aa</code></a>
chore: fixing comments typo (<a
href="https://github-redirect.dependabot.com/axios/axios/issues/5054">#5054</a>)</li>
<li><a
href="https://github.com/axios/axios/commit/110ae9ae613068f4292be9fbd2bf0abf28a6377a"><code>110ae9a</code></a>
fix: handling of array values for AxiosHeaders (<a
href="https://github-redirect.dependabot.com/axios/axios/issues/5085">#5085</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/axios/axios/compare/v0.27.2...v1.1.3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=axios&package-manager=npm_and_yarn&previous-version=0.27.2&new-version=1.1.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Antonio Gamez Diaz <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Antonio Gamez Diaz <[email protected]>
  • Loading branch information
dependabot[bot] and antgamdia authored Oct 24, 2022
1 parent c127354 commit 4ad748a
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 116 deletions.
7 changes: 3 additions & 4 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@tanstack/match-sorter-utils": "^8.5.14",
"@tanstack/react-table": "^8.5.15",
"ajv": "^8.11.0",
"axios": "^0.27.2",
"axios": "^1.1.3",
"connected-react-router": "^6.9.3",
"fast-json-patch": "^3.1.1",
"google-protobuf": "^3.21.2",
Expand Down Expand Up @@ -81,7 +81,6 @@
"@types/js-yaml": "^4.0.5",
"@types/jsonwebtoken": "^8.5.9",
"@types/lodash": "^4.14.186",
"@types/moxios": "^0.4.15",
"@types/qs": "^6.9.7",
"@types/react-copy-to-clipboard": "^5.0.4",
"@types/react-dom": "^18.0.6",
Expand All @@ -92,6 +91,7 @@
"@types/redux-mock-store": "^1.0.3",
"@types/swagger-ui-react": "^4.11.0",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.7",
"axios-mock-adapter": "^1.21.2",
"cross-env": "^7.0.3",
"enzyme": "^3.11.0",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -102,7 +102,6 @@
"jest-plugin-context": "^2.9.0",
"mock-socket": "^9.1.5",
"monaco-editor-webpack-plugin": "^7.0.1",
"moxios": "^0.4.0",
"node-polyfill-webpack-plugin": "^2.0.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.16",
Expand Down Expand Up @@ -134,7 +133,7 @@
"!src/**/*.d.ts"
],
"transformIgnorePatterns": [
"node_modules/(?!@cds|@clr|@lit|bail|ccount|cds|character-entities|comma-separated-tokens|decode-named-character-reference|escape-string-regexp|hast-util-whitespace|is-plain-obj|lit|lodash-es|markdown-table|mdast-util-definitions|mdast-util-find-and-replace|mdast-util-from-markdown|mdast-util-gfm-autolink-literal|mdast-util-gfm|mdast-util-to-hast|mdast-util-to-markdown|mdast-util-to-string|micromark-core-commonmark|monaco-editor|react-monaco-editor|micromark|parse-entities|property-information|ramda|react-markdown|react-syntax-highlighter|remark-breaks|remark-gfm|remark-parse|remark-rehype|space-separated-tokens|swagger-client|swagger-ui-react|trim-lines|trough|unified|unist-builder|unist-util-generated|unist-util-is|unist-util-position|unist-util-stringify-position|unist-util-visit-parents|unist-util-visit|util-find-and-replace|vfile-message|vfile|.*css)"
"node_modules/(?!@cds|@clr|@lit|axios|bail|ccount|cds|character-entities|comma-separated-tokens|decode-named-character-reference|escape-string-regexp|hast-util-whitespace|is-plain-obj|lit|lodash-es|markdown-table|mdast-util-definitions|mdast-util-find-and-replace|mdast-util-from-markdown|mdast-util-gfm-autolink-literal|mdast-util-gfm|mdast-util-to-hast|mdast-util-to-markdown|mdast-util-to-string|micromark-core-commonmark|monaco-editor|react-monaco-editor|micromark|parse-entities|property-information|ramda|react-markdown|react-syntax-highlighter|remark-breaks|remark-gfm|remark-parse|remark-rehype|space-separated-tokens|swagger-client|swagger-ui-react|trim-lines|trough|unified|unist-builder|unist-util-generated|unist-util-is|unist-util-position|unist-util-stringify-position|unist-util-visit-parents|unist-util-visit|util-find-and-replace|vfile-message|vfile|.*css)"
]
},
"browserslist": {
Expand Down
68 changes: 21 additions & 47 deletions dashboard/src/shared/AxiosInstance.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2022 the Kubeapps contributors.
// SPDX-License-Identifier: Apache-2.0

import * as moxios from "moxios";
import MockAdapter from "axios-mock-adapter";
import { IAuthState } from "reducers/auth";
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
Expand All @@ -24,6 +24,7 @@ describe("createAxiosInterceptorWithAuth", () => {
const authToken = "search-google-in-google";

let store: any;
let axiosMock: MockAdapter;

beforeAll(() => {
const state: IAuthState = {
Expand Down Expand Up @@ -53,21 +54,20 @@ describe("createAxiosInterceptorWithAuth", () => {
});

beforeEach(() => {
// Import as "any" to avoid typescript syntax error
moxios.install(axios as any);
axiosMock = new MockAdapter(axios);
});

afterEach(() => {
moxios.uninstall(axios as any);
axiosMock.restore();
store.clearActions();
});

it("includes the auth token if provided", async () => {
moxios.stubRequest(testPath, {});
axiosMock.onGet(testPath).reply(200, {});

await axios.get(testPath);
const request = moxios.requests.mostRecent();
expect(request.headers.Authorization).toBe(`Bearer ${authToken}`);
const request = axiosMock.history.get[0];
expect(request?.headers?.Authorization).toBe(`Bearer ${authToken}`);
});

const testCases = [
Expand All @@ -81,35 +81,23 @@ describe("createAxiosInterceptorWithAuth", () => {

testCases.forEach(t => {
it(`returns a custom message if ${t.code} returned`, async () => {
moxios.stubRequest(testPath, {
response: { message: `Will raise ${t.errorClass.name}` },
status: t.code,
});
axiosMock.onGet(testPath).reply(t.code, { message: `Will raise ${t.errorClass.name}` });
await expect(axios.get(testPath)).rejects.toThrow(`Will raise ${t.errorClass.name}`);
});

it(`returns the custom error ${t.errorClass.name} if ${t.code} returned`, async () => {
moxios.stubRequest(testPath, {
response: {},
status: t.code,
});
axiosMock.onGet(testPath).reply(t.code, {});
await expect(axios.get(testPath)).rejects.toThrowError(t.errorClass);
});
});

it("returns the generic error message otherwise", async () => {
moxios.stubRequest(testPath, {
response: {},
status: 555,
});
axiosMock.onGet(testPath).reply(555, {});
await expect(axios.get(testPath)).rejects.toThrow("Request failed with status code 555");
});

it("returns the response message", async () => {
moxios.stubRequest(testPath, {
response: { message: "this is an error!" },
status: 555,
});
axiosMock.onGet(testPath).reply(555, { message: "this is an error!" });
await expect(axios.get(testPath)).rejects.toThrow("this is an error!");
});

Expand All @@ -126,11 +114,7 @@ describe("createAxiosInterceptorWithAuth", () => {
type: "SET_AUTHENTICATION_SESSION_EXPIRED",
},
];

moxios.stubRequest(testPath, {
response: { message: "Boom!" },
status: 401,
});
axiosMock.onGet(testPath).reply(401, { message: "Boom!" });
await expect(axios.get(testPath)).rejects.toThrow("Boom!");
expect(store.getActions()).toEqual(expectedActions);
expect(Auth.unsetAuthCookie).toHaveBeenCalled();
Expand All @@ -141,7 +125,7 @@ describe("createAxiosInterceptorWithAuth", () => {
Auth.unsetAuthCookie = jest.fn();
const expectedActions = [
{
payload: "not ajson paylod",
payload: "not a json payload",
type: "AUTHENTICATION_ERROR",
},
{
Expand All @@ -150,11 +134,8 @@ describe("createAxiosInterceptorWithAuth", () => {
},
];

moxios.stubRequest(testPath, {
responseText: "not ajson paylod",
status: 401,
});
await expect(axios.get(testPath)).rejects.toThrow("not ajson paylod");
axiosMock.onGet(testPath).reply(401, { message: "not a json payload" });
await expect(axios.get(testPath)).rejects.toThrow("not a json payload");
expect(store.getActions()).toEqual(expectedActions);
expect(Auth.unsetAuthCookie).toHaveBeenCalled();
});
Expand All @@ -179,13 +160,9 @@ describe("createAxiosInterceptorWithAuth", () => {
type: "CLEAR_CLUSTERS",
},
];

moxios.stubRequest(testPath, {
response: {
message:
'{"metadata":{},"status":"Failure","message":"selfsubjectaccessreviews.authorization.k8s.io is forbidden: User "system:anonymous" cannot create resource "selfsubjectaccessreviews" in API group "authorization.k8s.io" at the cluster scope","reason":"Forbidden","details":{"group":"authorization.k8s.io","kind":"selfsubjectaccessreviews"},"code":403} {"namespaces":null}',
},
status: 403,
axiosMock.onGet(testPath).reply(403, {
message:
'{"metadata":{},"status":"Failure","message":"selfsubjectaccessreviews.authorization.k8s.io is forbidden: User "system:anonymous" cannot create resource "selfsubjectaccessreviews" in API group "authorization.k8s.io" at the cluster scope","reason":"Forbidden","details":{"group":"authorization.k8s.io","kind":"selfsubjectaccessreviews"},"code":403} {"namespaces":null}',
});
await expect(axios.get(testPath)).rejects.toThrow(
'{"metadata":{},"status":"Failure","message":"selfsubjectaccessreviews.authorization.k8s.io is forbidden: User "system:anonymous" cannot create resource "selfsubjectaccessreviews" in API group "authorization.k8s.io" at the cluster scope","reason":"Forbidden","details":{"group":"authorization.k8s.io","kind":"selfsubjectaccessreviews"},"code":403} {"namespaces":null}',
Expand All @@ -195,12 +172,9 @@ describe("createAxiosInterceptorWithAuth", () => {
});

it("parses a forbidden response", async () => {
moxios.stubRequest(testPath, {
response: {
message:
'[{"apiGroup": "v1", "resource": "secrets", "namespace": "default", "verbs": ["list", "get"]}]',
},
status: 403,
axiosMock.onGet(testPath).reply(403, {
message:
'[{"apiGroup": "v1", "resource": "secrets", "namespace": "default", "verbs": ["list", "get"]}]',
});
await expect(axios.get(testPath)).rejects.toThrow(
'Forbidden error, missing permissions: apiGroup: "v1", resource: "secrets", action: "list, get", namespace: default',
Expand Down
19 changes: 10 additions & 9 deletions dashboard/src/shared/Config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
// SPDX-License-Identifier: Apache-2.0

import axios from "axios";
import * as moxios from "moxios";
import MockAdapter from "axios-mock-adapter";
import Config, { IConfig, SupportedThemes } from "./Config";

describe("Config", () => {
let defaultJSON: IConfig;
let initialEnv: any;
let axiosMock: MockAdapter;

beforeEach(() => {
initialEnv = { ...process.env };
// Import as "any" to avoid typescript syntax error
moxios.install(axios as any);
axiosMock = new MockAdapter(axios);

defaultJSON = require("../../public/config.json");
moxios.stubRequest("config.json", { status: 200, response: { ...defaultJSON } });
axiosMock.onGet("config.json").reply(200, { ...defaultJSON });
});

afterEach(() => {
process.env = initialEnv;
moxios.uninstall(axios as any);
axiosMock.restore();
jest.restoreAllMocks();
});

Expand All @@ -31,19 +32,19 @@ describe("Config", () => {
describe("Themes", () => {
let defaultJSON: IConfig;
let initialEnv: any;
let axiosMock: MockAdapter;

const matchMedia = window.matchMedia;
beforeEach(() => {
initialEnv = { ...process.env };
// Import as "any" to avoid typescript syntax error
moxios.install(axios as any);
axiosMock = new MockAdapter(axios);
defaultJSON = require("../../public/config.json");
moxios.stubRequest("config.json", { status: 200, response: { ...defaultJSON } });
axiosMock.onGet("config.json").reply(200, { ...defaultJSON });
});

afterEach(() => {
process.env = initialEnv;
moxios.uninstall(axios as any);
axiosMock.restore();
window.matchMedia = matchMedia;
jest.restoreAllMocks();
});
Expand Down
40 changes: 18 additions & 22 deletions dashboard/src/shared/Kube.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// Copyright 2018-2022 the Kubeapps contributors.
// SPDX-License-Identifier: Apache-2.0

import MockAdapter from "axios-mock-adapter";
import { CanIRequest, CanIResponse } from "gen/kubeappsapis/plugins/resources/v1alpha1/resources";
import * as moxios from "moxios";
import { axiosWithAuth } from "./AxiosInstance";
import { Kube } from "./Kube";
import KubeappsGrpcClient from "./KubeappsGrpcClient";

const clusterName = "cluster-name";

describe("App", () => {
describe("Kube", () => {
let axiosMock: MockAdapter;

beforeEach(() => {
// Import as "any" to avoid typescript syntax error
moxios.install(axiosWithAuth as any);
axiosMock = new MockAdapter(axiosWithAuth);
});
afterEach(() => {
moxios.uninstall(axiosWithAuth as any);
axiosMock.restore();
});

describe("getAPIGroups", () => {
Expand All @@ -34,17 +35,12 @@ describe("App", () => {
},
},
];
beforeEach(() => {
moxios.stubRequest(/.*/, {
// Sample response to /apis
response: { kind: "APIGroupList", apiVersion: "v1", groups },
status: 200,
});
});

it("should request API groups", async () => {
axiosMock.onGet().reply(200, { kind: "APIGroupList", apiVersion: "v1", groups });
expect(await Kube.getAPIGroups(clusterName)).toEqual(groups);
expect(moxios.requests.mostRecent().url).toBe(`api/clusters/${clusterName}/apis`);
const request = axiosMock.history.get[0];
expect(request?.url).toBe(`api/clusters/${clusterName}/apis`);
});
});

Expand Down Expand Up @@ -141,14 +137,14 @@ describe("App", () => {
].forEach(t => {
it(t.description, async () => {
// eslint-disable-next-line redos/no-vulnerable
moxios.stubRequest(/.*api\/v1/, t.apiV1Response);
axiosMock.onGet(/.*api\/v1/).reply(t.apiV1Response.status, t.apiV1Response.response);
const groups: any[] = [];
t.groups.forEach((g: any) => {
groups.push(g.input);
t.groups.forEach((group: any) => {
groups.push(group.input);
// eslint-disable-next-line redos/no-vulnerable
moxios.stubOnce("GET", /.*apis\/.*/, g.apiResponse);
axiosMock.onGet(/.*apis\/.*/).replyOnce(200, group.apiResponse.response);
});
expect(await Kube.getResourceKinds("cluster", groups)).toEqual(t.result);
expect(await Kube.getResourceKinds(clusterName, groups)).toEqual(t.result);
});
});
});
Expand All @@ -170,13 +166,13 @@ describe("App", () => {
jest.spyOn(client, "CanI").mockImplementation(mockClientCanI);
jest.spyOn(Kube, "resourcesServiceClient").mockImplementation(() => client);

const allowed = await Kube.canI("cluster", "v1", "namespaces", "create", "");
const allowed = await Kube.canI(clusterName, "v1", "namespaces", "create", "");
expect(allowed).toBe(true);

expect(Kube.resourcesServiceClient).toHaveBeenCalledWith();
expect(mockClientCanI).toHaveBeenCalledWith({
context: {
cluster: "cluster",
cluster: clusterName,
namespace: "",
},
group: "v1",
Expand All @@ -199,13 +195,13 @@ describe("App", () => {
jest.spyOn(client, "CanI").mockImplementation(mockClientCanI);
jest.spyOn(Kube, "resourcesServiceClient").mockImplementation(() => client);

const allowed = await Kube.canI("cluster", "v1", "secrets", "list", "");
const allowed = await Kube.canI(clusterName, "v1", "secrets", "list", "");
expect(allowed).toBe(false);

expect(Kube.resourcesServiceClient).toHaveBeenCalled();
expect(mockClientCanI).toHaveBeenCalledWith({
context: {
cluster: "cluster",
cluster: clusterName,
namespace: "",
},
group: "v1",
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/shared/Kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Kube {
const { data: resourceList } = await axiosWithAuth.get<any>(
url.api.k8s.groupVersion(cluster, groupVersion),
);
resourceList.resources?.forEach((r: any) => addResource(r, groupVersion));
resourceList?.resources?.forEach((r: any) => addResource(r, groupVersion));
}),
);
return result;
Expand Down
14 changes: 0 additions & 14 deletions dashboard/src/shared/PackagesService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
PackageAppVersion,
} from "gen/kubeappsapis/core/packages/v1alpha1/packages";
import { Plugin } from "gen/kubeappsapis/core/plugins/v1alpha1/plugins";
import * as moxios from "moxios";
import { axiosWithAuth } from "./AxiosInstance";
import { KubeappsGrpcClient } from "./KubeappsGrpcClient";
import PackagesService from "./PackagesService";

Expand All @@ -19,18 +17,6 @@ const namespace = "namespace-name";
const defaultPageToken = "defaultPageToken";
const defaultSize = 0;
describe("App", () => {
beforeEach(() => {
// Import as "any" to avoid typescript syntax error
moxios.install(axiosWithAuth as any);
moxios.stubRequest(/.*/, {
response: { data: "ok" },
status: 200,
});
});
afterEach(() => {
moxios.uninstall(axiosWithAuth as any);
jest.restoreAllMocks();
});
describe("getAvailablePackageSummaries", () => {
[
{
Expand Down
Loading

0 comments on commit 4ad748a

Please sign in to comment.