Skip to content

Commit

Permalink
Merge pull request #1599 from skaut/collector-eslint-v9
Browse files Browse the repository at this point in the history
[collector] Updated eslint to v9
  • Loading branch information
marekdedic authored Sep 2, 2024
2 parents 5db2434 + 0d9ce27 commit 11614db
Show file tree
Hide file tree
Showing 28 changed files with 1,852 additions and 1,306 deletions.
132 changes: 0 additions & 132 deletions packages/collector/.eslintrc.json

This file was deleted.

4 changes: 4 additions & 0 deletions packages/collector/__tests__/getGlobalConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jest.mock("fs");

test("getGlobalConfig loads a file", () => {
mocked(fs).readFileSync.mockReturnValue('{"projects": []}');

expect(getGlobalConfig()).toStrictEqual({
projects: [],
});
Expand All @@ -17,6 +18,7 @@ test("getGlobalConfig reads a file", () => {
mocked(fs).readFileSync.mockReturnValue(
'{"projects": [{"owner": "OWNER1", "repo": "REPO1"}, {"owner": "OWNER2", "repo": "REPO2"}]}',
);

expect(getGlobalConfig()).toStrictEqual({
projects: [
{ owner: "OWNER1", repo: "REPO1" },
Expand All @@ -29,10 +31,12 @@ test("getGlobalConfig fails gracefully on file read error", () => {
mocked(fs).readFileSync.mockImplementation(() => {
throw new Error();
});

expect(() => getGlobalConfig()).toThrow(GlobalConfigError);
});

test("getGlobalConfig fails gracefully on empty file", () => {
mocked(fs).readFileSync.mockReturnValue("");

expect(() => getGlobalConfig()).toThrow(GlobalConfigError);
});
18 changes: 15 additions & 3 deletions packages/collector/__tests__/getProjectInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,69 @@ import { ProjectInfoError } from "../src/exceptions/ProjectInfoError";
import { getProjectInfo } from "../src/getProjectInfo";

const config = {
name: "NAME",
"short-description": "DESC",
description: "DESCRIPTION",
maintainers: [{ name: "MAINTAINER" }],
links: [{ type: "email", uri: "mailto:[email protected]" }],
maintainers: [{ name: "MAINTAINER" }],
name: "NAME",
"short-description": "DESC",
};

test("getProjectInfo gets a value", async () => {
expect.assertions(1);

nock("https://api.github.com")
.get("/repos/OWNER/REPO/contents/.project-info.json")
.reply(200, {
content: Buffer.from(JSON.stringify(config)).toString("base64"),
});

await expect(
getProjectInfo({ owner: "OWNER", repo: "REPO" }),
).resolves.toStrictEqual(config);

nock.cleanAll();
});

test("getProjectInfo fails gracefully on connection issues", async () => {
expect.assertions(1);

nock("https://api.github.com")
.get("/repos/OWNER/REPO/contents/.project-info.json")
.reply(404);

await expect(
getProjectInfo({ owner: "OWNER", repo: "REPO" }),
).rejects.toThrow(ProjectInfoError);

nock.cleanAll();
});

test("getProjectInfo fails gracefully on invalid response", async () => {
expect.assertions(1);

nock("https://api.github.com")
.get("/repos/OWNER/REPO/contents/.project-info.json")
.reply(200, {});

await expect(
getProjectInfo({ owner: "OWNER", repo: "REPO" }),
).rejects.toThrow(ProjectInfoError);

nock.cleanAll();
});

test("getProjectInfo fails gracefully on invalid response 2", async () => {
expect.assertions(1);

nock("https://api.github.com")
.get("/repos/OWNER/REPO/contents/.project-info.json")
.reply(200, {
content: Buffer.from("RANDOM").toString("base64"),
});

await expect(
getProjectInfo({ owner: "OWNER", repo: "REPO" }),
).rejects.toThrow(ProjectInfoError);

nock.cleanAll();
});
42 changes: 24 additions & 18 deletions packages/collector/__tests__/getProjectIssues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@ describe("Working issue listing", () => {
.query((actualQueryObject) => actualQueryObject.labels === "help-wanted")
.reply(200, [
{
number: 1,
title: "CORRECT",
body: "BODY_C",
html_url: "https://example.test",
number: 1,
title: "CORRECT",
},
]);
nock("https://api.github.com")
.get("/repos/OWNER/REPO/issues")
.query((actualQueryObject) => actualQueryObject.labels === "help wanted")
.reply(200, [
{
number: 2,
title: "INCORRECT",
body: "BODY_I",
html_url: "https://example.test",
number: 2,
title: "INCORRECT",
},
]);
nock("https://api.github.com")
.get("/repos/OWNER/REPO/issues")
.query((actualQueryObject) => !("labels" in actualQueryObject))
.reply(200, [
{
number: 1,
title: "CORRECT",
body: "BODY_C",
html_url: "https://example.test",
number: 1,
title: "CORRECT",
},
{
number: 2,
title: "INCORRECT",
body: "BODY_I",
html_url: "https://example.test",
number: 2,
title: "INCORRECT",
},
{
number: 3,
title: "NONE",
body: "BODY_N",
html_url: "https://example.test",
number: 3,
title: "NONE",
},
]);
});
Expand All @@ -62,10 +62,10 @@ describe("Working issue listing", () => {
getProjectIssues({ owner: "OWNER", repo: "REPO" }, true, "help-wanted"),
).resolves.toStrictEqual([
{
number: 1,
title: "CORRECT",
description: "BODY_C",
link: "https://example.test",
number: 1,
title: "CORRECT",
},
]);
});
Expand All @@ -76,10 +76,10 @@ describe("Working issue listing", () => {
getProjectIssues({ owner: "OWNER", repo: "REPO" }, true, undefined),
).resolves.toStrictEqual([
{
number: 2,
title: "INCORRECT",
description: "BODY_I",
link: "https://example.test",
number: 2,
title: "INCORRECT",
},
]);
});
Expand All @@ -89,40 +89,46 @@ describe("Working issue listing", () => {
await expect(
getProjectIssues({ owner: "OWNER", repo: "REPO" }, false, "help-wanted"),
).resolves.toStrictEqual([
{ number: 1, title: "CORRECT", description: "BODY_C", link: undefined },
{ description: "BODY_C", link: undefined, number: 1, title: "CORRECT" },
]);
});
});

test("getProjectIssues auto-populates body", async () => {
expect.assertions(1);

nock("https://api.github.com")
.get("/repos/OWNER/REPO/issues")
.query((actualQueryObject) => actualQueryObject.labels === "help-wanted")
.reply(200, [
{ number: 1, title: "CORRECT", html_url: "https://example.test" },
{ html_url: "https://example.test", number: 1, title: "CORRECT" },
]);

await expect(
getProjectIssues({ owner: "OWNER", repo: "REPO" }, true, "help-wanted"),
).resolves.toStrictEqual([
{
number: 1,
title: "CORRECT",
description: "",
link: "https://example.test",
number: 1,
title: "CORRECT",
},
]);

nock.cleanAll();
});

test("getProjectIssues fails gracefully on connection issues", async () => {
expect.assertions(1);

nock("https://api.github.com")
.get("/repos/OWNER/REPO/issues")
.query(true)
.reply(404);

await expect(async () =>
getProjectIssues({ owner: "OWNER", repo: "REPO" }, true, "help-wanted"),
).rejects.toThrow(IssueListError);

nock.cleanAll();
});
Loading

0 comments on commit 11614db

Please sign in to comment.