Skip to content

Commit

Permalink
Update jest (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor committed Jun 26, 2020
1 parent f49b3ef commit 92fcce0
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 193 deletions.
6 changes: 3 additions & 3 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"redux-devtools-extension": "^2.13.5",
"redux-thunk": "^2.2.0",
"semver": "^5.6.0",
"ts-jest": "^22.0.1",
"typesafe-actions": "^2.0.4",
"yaml": "1.7.2"
},
Expand Down Expand Up @@ -105,7 +104,7 @@
"devDependencies": {
"@types/enzyme": "^3.1.6",
"@types/enzyme-adapter-react-16": "^1.0.1",
"@types/jest": "^22.0.0",
"@types/jest": "^26.0.3",
"@types/node": "^14.0.14",
"@types/react-dom": "^16.9.4",
"@types/react-modal": "^3.1.1",
Expand All @@ -115,7 +114,7 @@
"@types/redux-mock-store": "^1.0.0",
"enzyme": "^3.6.0",
"husky": "^1.1.0",
"jest-enzyme": "^6.0.4",
"jest-enzyme": "^7.1.2",
"jest-plugin-context": "^2.9.0",
"lint-staged": "^10.2.11",
"mock-socket": "^8.0.2",
Expand All @@ -132,6 +131,7 @@
"tslint": "^5.9.1",
"tslint-config-prettier": "^1.6.0",
"tslint-react": "^3.4.0",
"ts-jest": "^22.0.1",
"typescript": "^3.7.2"
},
"jest": {
Expand Down
12 changes: 6 additions & 6 deletions dashboard/src/actions/apps.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ describe("fetches applications", () => {
},
},
];
Chart.listWithFilters = jest.fn(() => chartUpdatesResponse);
App.listApps = jest.fn(() => appsResponse);
Chart.listWithFilters = jest.fn().mockReturnValue(chartUpdatesResponse);
App.listApps = jest.fn().mockReturnValue(appsResponse);
const expectedActions = [
{ type: getType(actions.apps.listApps), payload: false },
{ type: getType(actions.apps.receiveAppList), payload: appsResponse },
Expand Down Expand Up @@ -110,8 +110,8 @@ describe("fetches applications", () => {
},
},
];
Chart.listWithFilters = jest.fn(() => chartUpdatesResponse);
App.listApps = jest.fn(() => appsResponse);
Chart.listWithFilters = jest.fn().mockReturnValue(chartUpdatesResponse);
App.listApps = jest.fn().mockReturnValue(appsResponse);
const expectedActions = [
{ type: getType(actions.apps.listApps), payload: false },
{ type: getType(actions.apps.receiveAppList), payload: appsResponse },
Expand Down Expand Up @@ -146,8 +146,8 @@ describe("fetches applications", () => {
relationships: { latestChartVersion: { data: { version: "1.0" } } },
},
];
Chart.listWithFilters = jest.fn(() => chartUpdatesResponse);
App.listApps = jest.fn(() => appsResponse);
Chart.listWithFilters = jest.fn().mockReturnValue(chartUpdatesResponse);
App.listApps = jest.fn().mockReturnValue(appsResponse);
const expectedActions = [
{ type: getType(actions.apps.listApps), payload: false },
{ type: getType(actions.apps.receiveAppList), payload: appsResponse },
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/actions/auth.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ beforeEach(() => {
};

Auth.validateToken = jest.fn();
Auth.isAuthenticatedWithCookie = jest.fn(() => "token");
Auth.isAuthenticatedWithCookie = jest.fn().mockReturnValue("token");
Auth.setAuthToken = jest.fn();
Auth.unsetAuthToken = jest.fn();

Expand Down Expand Up @@ -102,7 +102,7 @@ describe("authenticate", () => {

describe("OIDC authentication", () => {
it("dispatches authenticating and auth ok if valid", () => {
Auth.isAuthenticatedWithCookie = jest.fn(() => true);
Auth.isAuthenticatedWithCookie = jest.fn().mockReturnValue(true);
const expectedActions = [
{
type: getType(actions.auth.authenticating),
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/actions/config.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let store: any;
const testConfig = "have you tried to turn it off and on again";

beforeEach(() => {
Config.getConfig = jest.fn(() => testConfig);
Config.getConfig = jest.fn().mockReturnValue(testConfig);

store = mockStore();
});
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/actions/namespace.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe("createNamespace", () => {
describe("getNamespace", () => {
it("dispatches requested namespace", async () => {
const ns = { metadata: { name: "default" } };
Namespace.get = jest.fn(() => ns);
Namespace.get = jest.fn().mockReturnValue(ns);
const expectedActions = [
{
type: getType(requestNamespace),
Expand Down
46 changes: 21 additions & 25 deletions dashboard/src/actions/operators.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ afterEach(jest.resetAllMocks);

describe("checkOLMInstalled", () => {
it("dispatches OLM_INSTALLED when succeded", async () => {
Operators.isOLMInstalled = jest.fn(() => true);
Operators.isOLMInstalled = jest.fn().mockReturnValue(true);
const expectedActions = [
{
type: getType(operatorActions.checkingOLM),
Expand Down Expand Up @@ -51,10 +51,9 @@ describe("checkOLMInstalled", () => {

describe("getOperators", () => {
it("returns an ordered list of operators based on the name", async () => {
Operators.getOperators = jest.fn(() => [
{ metadata: { name: "foo" } },
{ metadata: { name: "bar" } },
]);
Operators.getOperators = jest
.fn()
.mockResolvedValue([{ metadata: { name: "foo" } }, { metadata: { name: "bar" } }]);
const sortedOperators = [{ metadata: { name: "bar" } }, { metadata: { name: "foo" } }];
const expectedActions = [
{
Expand Down Expand Up @@ -90,7 +89,7 @@ describe("getOperators", () => {
describe("getOperator", () => {
it("returns an an operator", async () => {
const op = { metadata: { name: "foo" } };
Operators.getOperator = jest.fn(() => op);
Operators.getOperator = jest.fn().mockReturnValue(op);
const expectedActions = [
{
type: getType(operatorActions.requestOperator),
Expand Down Expand Up @@ -124,10 +123,9 @@ describe("getOperator", () => {

describe("getCSVs", () => {
it("returns an ordered list of csvs based on the name", async () => {
Operators.getCSVs = jest.fn(() => [
{ metadata: { name: "foo" } },
{ metadata: { name: "bar" } },
]);
Operators.getCSVs = jest
.fn()
.mockResolvedValue([{ metadata: { name: "foo" } }, { metadata: { name: "bar" } }]);
const sortedCSVs = [{ metadata: { name: "bar" } }, { metadata: { name: "foo" } }];
const expectedActions = [
{
Expand Down Expand Up @@ -163,7 +161,7 @@ describe("getCSVs", () => {
describe("getCSV", () => {
it("returns an an ClusterServiceVersion", async () => {
const csv = { metadata: { name: "foo" } };
Operators.getCSV = jest.fn(() => csv);
Operators.getCSV = jest.fn().mockReturnValue(csv);
const expectedActions = [
{
type: getType(operatorActions.requestCSV),
Expand Down Expand Up @@ -198,7 +196,7 @@ describe("getCSV", () => {
describe("createResource", () => {
it("creates a resource", async () => {
const resource = {} as IResource;
Operators.createResource = jest.fn(() => resource);
Operators.createResource = jest.fn().mockReturnValue(resource);
const expectedActions = [
{
type: getType(operatorActions.creatingResource),
Expand Down Expand Up @@ -233,7 +231,7 @@ describe("createResource", () => {
describe("updateResource", () => {
it("updates a resource", async () => {
const resource = {} as IResource;
Operators.updateResource = jest.fn(() => resource);
Operators.updateResource = jest.fn().mockReturnValue(resource);
const expectedActions = [
{
type: getType(operatorActions.updatingResource),
Expand Down Expand Up @@ -274,11 +272,9 @@ describe("getResources", () => {
},
};
const resource = { metadata: { name: "resource" } };
Operators.getCSVs = jest.fn(() => [csv]);
Operators.listResources = jest.fn(() => {
return {
items: [resource],
};
Operators.getCSVs = jest.fn().mockReturnValue([csv]);
Operators.listResources = jest.fn().mockReturnValue({
items: [resource],
});
const expectedActions = [
{
Expand Down Expand Up @@ -308,7 +304,7 @@ describe("getResources", () => {
customresourcedefinitions: { owned: [{ name: "foo.kubeapps.com", version: "v1alpha1" }] },
},
};
Operators.getCSVs = jest.fn(() => [csv]);
Operators.getCSVs = jest.fn().mockReturnValue([csv]);
Operators.listResources = jest.fn(() => {
throw new Error("Boom!");
});
Expand Down Expand Up @@ -346,8 +342,8 @@ describe("getResources", () => {
},
};
const resource = { metadata: { name: "resource" } };
Operators.getCSV = jest.fn(() => csv);
Operators.getResource = jest.fn(() => resource);
Operators.getCSV = jest.fn().mockReturnValue(csv);
Operators.getResource = jest.fn().mockReturnValue(resource);
const expectedActions = [
{
type: getType(operatorActions.requestCustomResource),
Expand Down Expand Up @@ -381,7 +377,7 @@ describe("getResources", () => {
customresourcedefinitions: { owned: [{ name: "foo.kubeapps.com", version: "v1alpha1" }] },
},
};
Operators.getCSV = jest.fn(() => csv);
Operators.getCSV = jest.fn().mockReturnValue(csv);
Operators.getResource = jest.fn(() => {
throw new Error("Boom!");
});
Expand All @@ -406,7 +402,7 @@ describe("getResources", () => {
});

it("dispatches an error if the given csv is not found", async () => {
Operators.getCSV = jest.fn(() => undefined);
Operators.getCSV = jest.fn().mockReturnValue(undefined);
const expectedActions = [
{
type: getType(operatorActions.requestCustomResource),
Expand All @@ -433,7 +429,7 @@ describe("getResources", () => {
customresourcedefinitions: { owned: [{ name: "foo.kubeapps.com", version: "v1alpha1" }] },
},
};
Operators.getCSV = jest.fn(() => csv);
Operators.getCSV = jest.fn().mockReturnValue(csv);
const expectedActions = [
{
type: getType(operatorActions.requestCustomResource),
Expand Down Expand Up @@ -495,7 +491,7 @@ describe("deleteResource", () => {
describe("createOperator", () => {
it("creates an Operator", async () => {
const resource = {} as IResource;
Operators.createOperator = jest.fn(() => resource);
Operators.createOperator = jest.fn().mockReturnValue(resource);
const expectedActions = [
{
type: getType(operatorActions.creatingOperator),
Expand Down
42 changes: 19 additions & 23 deletions dashboard/src/actions/repos.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ beforeEach(() => {
return { appRepository: { metadata: { name: "repo-abc" } } };
});
Secret.create = jest.fn();
Secret.list = jest.fn(() => {
return { items: [] };
Secret.list = jest.fn().mockReturnValue({
items: [],
});
});

Expand Down Expand Up @@ -249,8 +249,8 @@ describe("fetchRepos", () => {
],
},
};
Secret.list = jest.fn(() => {
return { items: [appRepoSecret, otherSecret] };
Secret.list = jest.fn().mockReturnValue({
items: [appRepoSecret, otherSecret],
});
const expectedActions = [
{
Expand Down Expand Up @@ -523,12 +523,10 @@ describe("updateRepo", () => {
spec: { auth: { header: { secretKeyRef: { name: "apprepo-repo-abc" } } } },
};
const secret = { metadata: { name: "apprepo-repo-abc" } };
AppRepository.update = jest.fn(() => {
return { appRepository: r };
});
Secret.get = jest.fn(() => {
return secret;
AppRepository.update = jest.fn().mockReturnValue({
appRepository: r,
});
Secret.get = jest.fn().mockReturnValue(secret);
const expectedActions = [
{
type: getType(repoActions.requestRepoUpdate),
Expand Down Expand Up @@ -572,12 +570,10 @@ describe("updateRepo", () => {
spec: { auth: { customCA: { secretKeyRef: { name: "apprepo-repo-abc" } } } },
};
const secret = { metadata: { name: "apprepo-repo-abc" } };
AppRepository.update = jest.fn(() => {
return { appRepository: r };
});
Secret.get = jest.fn(() => {
return secret;
AppRepository.update = jest.fn().mockReturnValue({
appRepository: r,
});
Secret.get = jest.fn().mockReturnValue(secret);
const expectedActions = [
{
type: getType(repoActions.requestRepoUpdate),
Expand Down Expand Up @@ -685,8 +681,9 @@ describe("checkChart", () => {

describe("validateRepo", () => {
it("dispatches repoValidating and repoValidated if no error", async () => {
AppRepository.validate = jest.fn(() => {
return { code: 200, message: "OK" };
AppRepository.validate = jest.fn().mockReturnValue({
code: 200,
message: "OK",
});
const expectedActions = [
{
Expand Down Expand Up @@ -723,8 +720,9 @@ describe("validateRepo", () => {
});

it("dispatches checkRepo and errorRepos when the validation cannot be parsed", async () => {
AppRepository.validate = jest.fn(() => {
return { code: 409, message: "forbidden" };
AppRepository.validate = jest.fn().mockReturnValue({
code: 409,
message: "forbidden",
});
const expectedActions = [
{
Expand Down Expand Up @@ -752,10 +750,8 @@ describe("fetchImagePullSecrets", () => {
const secret2 = {
type: "Opaque",
};
Secret.list = jest.fn(() => {
return {
items: [secret1, secret2],
};
Secret.list = jest.fn().mockReturnValue({
items: [secret1, secret2],
});
const expectedActions = [
{
Expand Down Expand Up @@ -798,7 +794,7 @@ describe("createDockerRegistrySecret", () => {
const secret = {
type: "kubernetes.io/dockerconfigjson",
};
Secret.createPullSecret = jest.fn(() => secret);
Secret.createPullSecret = jest.fn().mockReturnValue(secret);
const expectedActions = [
{
type: getType(repoActions.createImagePullSecret),
Expand Down

0 comments on commit 92fcce0

Please sign in to comment.