Skip to content

Commit 2263e67

Browse files
author
Renato Ribeiro
committed
add getPost by id and number
1 parent 88d0566 commit 2263e67

10 files changed

Lines changed: 63665 additions & 93 deletions

File tree

.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: 23 additions & 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("getPost", () => {
@@ -16,4 +16,26 @@ describe("getPost", () => {
1616
expect(result.post?.totalReactions).toBeGreaterThan(0);
1717
expect(result.post?.reactions.THUMBS_UP).toBeGreaterThan(0);
1818
});
19+
20+
test("get post by id", async () => {
21+
const result = await blog.getPost({ id: "MDU6SXNzdWU5MzYwOTEyMDc=" });
22+
23+
expect(result.post?.title).toBe("First post");
24+
expect(result.post?.frontmatter).toStrictEqual({ meta: "data" });
25+
expect(result.post?.body).toBe("\r\nHi");
26+
expect(result.post?.totalComments).toBeGreaterThan(0);
27+
expect(result.post?.totalReactions).toBeGreaterThan(0);
28+
expect(result.post?.reactions.THUMBS_UP).toBeGreaterThan(0);
29+
});
30+
31+
test("get post by number", async () => {
32+
const result = await blog.getPost({ number: 1 });
33+
34+
expect(result.post?.title).toBe("First post");
35+
expect(result.post?.frontmatter).toStrictEqual({ meta: "data" });
36+
expect(result.post?.body).toBe("\r\nHi");
37+
expect(result.post?.totalComments).toBeGreaterThan(0);
38+
expect(result.post?.totalReactions).toBeGreaterThan(0);
39+
expect(result.post?.reactions.THUMBS_UP).toBeGreaterThan(0);
40+
});
1941
});

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", () => {

0 commit comments

Comments
 (0)