Skip to content

Commit

Permalink
Fix tags handling #1220 (#1239)
Browse files Browse the repository at this point in the history
  • Loading branch information
kandeshvari authored and Andres Martinez Gotor committed Oct 22, 2019
1 parent 7a48d52 commit 17190f8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
16 changes: 16 additions & 0 deletions dashboard/src/actions/charts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ describe("getChartVersion", () => {
expect(axiosGetMock.mock.calls[0][0]).toBe("api/chartsvc/v1/charts/foo/versions/1.0.0");
});

it("gets a chart version with tag", async () => {
response = { id: "foo" };
const expectedActions = [
{ type: getType(actions.charts.requestCharts) },
{
type: getType(actions.charts.selectChartVersion),
payload: { chartVersion: response, schema: { data: response }, values: { data: response } },
},
];
await store.dispatch(actions.charts.getChartVersion("foo", "1.0.0-alpha+1.2.3-beta2"));
expect(store.getActions()).toEqual(expectedActions);
expect(axiosGetMock.mock.calls[0][0]).toBe(
"api/chartsvc/v1/charts/foo/versions/1.0.0-alpha%2B1.2.3-beta2",
);
});

it("gets a chart version with values and schema", async () => {
// Call to get the chart version
axiosGetMock.mockImplementationOnce(() => {
Expand Down
6 changes: 3 additions & 3 deletions dashboard/src/actions/repos.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import thunk from "redux-thunk";
import { getType } from "typesafe-actions";
import actions from ".";
import { AppRepository } from "../shared/AppRepository";
import { axios } from "../shared/AxiosInstance";
import Chart from "../shared/Chart";
import Secret from "../shared/Secret";
import { IAppRepository, NotFoundError } from "../shared/types";

Expand All @@ -13,7 +13,6 @@ const mockStore = configureMockStore([thunk]);

let store: any;
const appRepo = { spec: { resyncRequests: 10000 } };
axios.get = jest.fn();

beforeEach(() => {
store = mockStore({ config: { namespace: "my-namespace" } });
Expand Down Expand Up @@ -361,6 +360,7 @@ spec:

describe("checkChart", () => {
it("dispatches requestRepo and receivedRepo if no error", async () => {
Chart.fetchChartVersions = jest.fn();
const expectedActions = [
{
type: getType(repoActions.requestRepo),
Expand All @@ -376,7 +376,7 @@ describe("checkChart", () => {
});

it("dispatches requestRepo and errorChart if error fetching", async () => {
axios.get = jest.fn(() => {
Chart.fetchChartVersions = jest.fn(() => {
throw new Error();
});

Expand Down
5 changes: 2 additions & 3 deletions dashboard/src/actions/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import * as yaml from "js-yaml";
import { ThunkAction } from "redux-thunk";
import { ActionType, createAction } from "typesafe-actions";
import { AppRepository } from "../shared/AppRepository";
import { axios } from "../shared/AxiosInstance";
import Chart from "../shared/Chart";
import Secret from "../shared/Secret";
import * as url from "../shared/url";
import { errorChart } from "./charts";

import { IAppRepository, IOwnerReference, IStoreState, NotFoundError } from "../shared/types";
Expand Down Expand Up @@ -214,7 +213,7 @@ export function checkChart(
dispatch(requestRepo());
const appRepository = await AppRepository.get(repo, namespace);
try {
await axios.get(url.api.charts.listVersions(`${repo}/${chartName}`));
await Chart.fetchChartVersions(`${repo}/${chartName}`);
dispatch(receiveRepo(appRepository));
return true;
} catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions dashboard/src/shared/Chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export default class Chart {
}

public static async listWithFilters(name: string, version: string, appVersion: string) {
const url = `${
Chart.APIEndpoint
}/charts?name=${name}&version=${version}&appversion=${appVersion}`;
const url = `${Chart.APIEndpoint}/charts?name=${name}&version=${encodeURIComponent(
version,
)}&appversion=${appVersion}`;
const { data } = await axiosWithAuth.get<{ data: IChart[] }>(url);
return data.data;
}
Expand Down
8 changes: 4 additions & 4 deletions dashboard/src/shared/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export const api = {
base: "api/chartsvc/v1",
get: (id: string) => `${api.charts.base}/charts/${id}`,
getReadme: (id: string, version: string) =>
`${api.charts.base}/assets/${id}/versions/${version}/README.md`,
`${api.charts.base}/assets/${id}/versions/${encodeURIComponent(version)}/README.md`,
getValues: (id: string, version: string) =>
`${api.charts.base}/assets/${id}/versions/${version}/values.yaml`,
`${api.charts.base}/assets/${id}/versions/${encodeURIComponent(version)}/values.yaml`,
getSchema: (id: string, version: string) =>
`${api.charts.base}/assets/${id}/versions/${version}/values.schema.json`,
`${api.charts.base}/assets/${id}/versions/${encodeURIComponent(version)}/values.schema.json`,
getVersion: (id: string, version: string) =>
`${api.charts.base}/charts/${id}/versions/${version}`,
`${api.charts.base}/charts/${id}/versions/${encodeURIComponent(version)}`,
list: (repo?: string) => `${api.charts.base}/charts${repo ? `/${repo}` : ""}`,
listVersions: (id: string) => `${api.charts.get(id)}/versions`,
},
Expand Down

0 comments on commit 17190f8

Please sign in to comment.