Skip to content

Commit 2008483

Browse files
committed
add getPost by id and number & bump 0.6.1
1 parent 88d0566 commit 2008483

File tree

12 files changed

+63679
-101
lines changed

12 files changed

+63679
-101
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
GITHUB_TOKEN=<your_github_token>
12
GITHUB_INTROSPECTION_TOKEN=<your_github_token>
3+
GITHUB_E2E_TESTS_TOKEN=<your_github_token>

codegen.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
documents: "./src/**/*.ts"
2-
schema:
3-
https://api.github.com/graphql:
4-
headers:
5-
Authorization: Bearer ${GITHUB_INTROSPECTION_TOKEN}
6-
User-Agent: node.js
2+
schema: "./src/__generated__/schema.graphql"
73
generates:
84
./src/__generated__/index.ts:
95
config:

e2e/getComments.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { GithubBlog } from "../src/github-blog";
22

33
const blog = new GithubBlog({
44
repo: "renatorib/github-blog-tests",
5-
token: process.env.GITHUB_E2E_TESTS_TOKEN!,
5+
token: process.env.GITHUB_E2E_TESTS_TOKEN || process.env.GITHUB_TOKEN!,
66
});
77

88
describe("getComments", () => {

e2e/getLabels.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { GithubBlog } from "../src/github-blog";
22

33
const blog = new GithubBlog({
44
repo: "renatorib/github-blog-tests",
5-
token: process.env.GITHUB_E2E_TESTS_TOKEN!,
5+
token: process.env.GITHUB_E2E_TESTS_TOKEN || process.env.GITHUB_TOKEN!,
66
});
77

88
describe("getLabels", () => {

e2e/getPinnedPosts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { GithubBlog } from "../src/github-blog";
22

33
const blog = new GithubBlog({
44
repo: "renatorib/github-blog-tests",
5-
token: process.env.GITHUB_E2E_TESTS_TOKEN!,
5+
token: process.env.GITHUB_E2E_TESTS_TOKEN || process.env.GITHUB_TOKEN!,
66
});
77

88
describe("getPinnedPosts", () => {

e2e/getPost.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,36 @@ import { GithubBlog } from "../src/github-blog";
22

33
const blog = new GithubBlog({
44
repo: "renatorib/github-blog-tests",
5-
token: process.env.GITHUB_E2E_TESTS_TOKEN!,
5+
token: process.env.GITHUB_E2E_TESTS_TOKEN || process.env.GITHUB_TOKEN!,
66
});
77

88
describe("getPost", () => {
99
test("get post by slug", async () => {
1010
const result = await blog.getPost({ query: { slug: "first-post" } });
1111

12+
expect(result.post?.number).toBe(1);
13+
expect(result.post?.title).toBe("First post");
14+
expect(result.post?.frontmatter).toStrictEqual({ meta: "data" });
15+
expect(result.post?.body).toBe("\r\nHi");
16+
expect(result.post?.totalComments).toBeGreaterThan(0);
17+
expect(result.post?.totalReactions).toBeGreaterThan(0);
18+
expect(result.post?.reactions.THUMBS_UP).toBeGreaterThan(0);
19+
});
20+
21+
test("get post by id", async () => {
22+
const result = await blog.getPost({ id: "MDU6SXNzdWU5MzYwOTEyMDc=" });
23+
24+
expect(result.post?.title).toBe("First post");
25+
expect(result.post?.frontmatter).toStrictEqual({ meta: "data" });
26+
expect(result.post?.body).toBe("\r\nHi");
27+
expect(result.post?.totalComments).toBeGreaterThan(0);
28+
expect(result.post?.totalReactions).toBeGreaterThan(0);
29+
expect(result.post?.reactions.THUMBS_UP).toBeGreaterThan(0);
30+
});
31+
32+
test("get post by number", async () => {
33+
const result = await blog.getPost({ number: 1 });
34+
1235
expect(result.post?.title).toBe("First post");
1336
expect(result.post?.frontmatter).toStrictEqual({ meta: "data" });
1437
expect(result.post?.body).toBe("\r\nHi");

e2e/getPosts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { GithubBlog } from "../src/github-blog";
22

33
const blog = new GithubBlog({
44
repo: "renatorib/github-blog-tests",
5-
token: process.env.GITHUB_E2E_TESTS_TOKEN!,
5+
token: process.env.GITHUB_E2E_TESTS_TOKEN || process.env.GITHUB_TOKEN!,
66
});
77

88
describe("getPosts", () => {

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"packageManager": "yarn@1.22.19",
32
"name": "@rena.to/github-blog",
4-
"version": "0.4.2",
3+
"version": "0.6.1",
54
"description": "Turn your github issues in CMS for your blog",
65
"main": "dist/index.js",
76
"repository": "https://github.com/renatorib/github-blog",
@@ -13,7 +12,7 @@
1312
"dev": "yarn codegen --watch",
1413
"build": "rm -rf ./dist && yarn tsc --project tsconfig.build.json",
1514
"test": "yarn codegen && yarn jest",
16-
"prepublishOnly": "yarn test",
15+
"prepublishOnly": "yarn test && yarn build",
1716
"debug": "node -r dotenv-flow/config src/tmp/debug.js",
1817
"docs": "typedoc src --readme none --githubPages false",
1918
"prepare": "simple-git-hooks"
@@ -62,5 +61,6 @@
6261
"typedoc": "^0.22.4",
6362
"typedoc-plugin-markdown": "^3.11.2",
6463
"typescript": "^5.1.3"
65-
}
64+
},
65+
"packageManager": "yarn@1.22.19"
6666
}

0 commit comments

Comments
 (0)