summaryrefslogtreecommitdiff
path: root/cgithub/src/scraper.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cgithub/src/scraper.test.ts')
-rw-r--r--cgithub/src/scraper.test.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/cgithub/src/scraper.test.ts b/cgithub/src/scraper.test.ts
index a4b834e..4a01853 100644
--- a/cgithub/src/scraper.test.ts
+++ b/cgithub/src/scraper.test.ts
@@ -9,6 +9,7 @@ import {
getGitHubReleases,
getGitHubRepo,
getGitHubTree,
+ getGitHubUser,
GitHubHTTPError,
RedirectError,
} from "./scraper.ts";
@@ -264,6 +265,54 @@ describe("GitHub scraper", () => {
});
});
+ describe("user pages", () => {
+ it("should fetch user profile", async () => {
+ const data = await getGitHubUser("torvalds");
+
+ assert.strictEqual(data.login, "torvalds");
+ assert.strictEqual(data.name, "Linus Torvalds");
+ assert.strictEqual(data.company, "Linux Foundation");
+ assert.strictEqual(data.location, "Portland, OR");
+ assert.ok(data.avatarUrl?.startsWith("https://avatars.githubusercontent.com/"));
+ assert.ok(data.followers);
+ assert.ok(data.following !== null);
+
+ assert.ok(data.pinned.length > 0);
+ const linux = data.pinned.find((repo) => repo.name === "linux");
+ assert.ok(linux);
+ assert.strictEqual(linux.owner, "torvalds");
+ assert.strictEqual(linux.description, "Linux kernel source tree");
+ assert.strictEqual(linux.language, "C");
+ assert.ok(linux.stars);
+ assert.ok(linux.forks);
+ });
+
+ it("should fetch user bio and links", async () => {
+ const data = await getGitHubUser("sindresorhus");
+
+ assert.strictEqual(data.login, "sindresorhus");
+ assert.ok(data.bio && data.bio.length > 0);
+ assert.ok(data.links.length > 0);
+ assert.ok(data.links.every((link) => link.href.startsWith("https://")));
+ });
+
+ it("should redirect to GitHub for organizations", async () => {
+ await assert.rejects(getGitHubUser("github"), (err) => {
+ assert(err instanceof RedirectError, "error should be a RedirectError");
+ assert.strictEqual(err.location, "https://github.com/github");
+ return true;
+ });
+ });
+
+ it("should throw for non-existent user", async () => {
+ await assert.rejects(getGitHubUser("nosuchuserzzzz"), (err) => {
+ assert(err instanceof GitHubHTTPError, "error should be an HTTPError");
+ assert.strictEqual(err.status, 404);
+ return true;
+ });
+ });
+ });
+
describe("error handling", () => {
it("should throw for non-existent repository", async () => {
await assert.rejects(getGitHubRepo("nosuchowner", "nosuchrepo"), (err) => {