Skip to content

Commit 6815c96

Browse files
authored
created new tests for api article body (#54885)
1 parent d0fd4a7 commit 6815c96

File tree

4 files changed

+152
-4
lines changed

4 files changed

+152
-4
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: Api Article Body Test Page
3+
shortTitle: About GitHub and Git
4+
intro: 'You can use Github and Git to collaborate on work.'
5+
versions:
6+
fpt: '*'
7+
ghes: '*'
8+
ghec: '*'
9+
type: overview
10+
topics:
11+
- Git
12+
- Fundamentals
13+
- GitHub
14+
- Collaboration
15+
- Community
16+
redirect_from:
17+
- /get-started/quickstart/about-github-and-git
18+
---
19+
20+
## About GitHub
21+
22+
GitHub is a cloud-based platform where you can store, share, and work together with others to write code.
23+
24+
Storing your code in a "repository" on GitHub allows you to:
25+
26+
* **Showcase or share** your work.
27+
* **Track and manage** changes to your code over time.
28+
* Let others **review** your code, and make suggestions to improve it.
29+
* **Collaborate** on a shared project, without worrying that your changes will impact the work of your collaborators before you're ready to integrate them.
30+
31+
Collaborative working, one of GitHub’s fundamental features, is made possible by the open-source software, Git, upon which GitHub is built.
32+
33+
## About Git
34+
35+
Git is a version control system that intelligently tracks changes in files. Git is particularly useful when you and a group of people are all making changes to the same files at the same time.
36+
37+
Typically, to do this in a Git-based workflow, you would:
38+
39+
* **Create a branch** off from the main copy of files that you (and your collaborators) are working on.
40+
* **Make edits** to the files independently and safely on your own personal branch.
41+
* Let Git intelligently **merge** your specific changes back into the main copy of files, so that your changes don't impact other people's updates.
42+
* Let Git **keep track** of your and other people's changes, so you all stay working on the most up-to-date version of the project.
43+
44+
45+
46+
### How do Git and GitHub work together?
47+
48+
When you upload files to GitHub , you'll store them in a "Git repository." This means that when you make changes (or "commits") to your files in GitHub, Git will automatically start to track and manage your changes.
49+
50+
There are plenty of Git-related actions that you can complete on GitHub directly in your browser, such as creating a Git repository, creating branches, and uploading and editing files.
51+
52+
However, most people work on their files locally (on their own computer), then continually sync these local changes—and all the related Git data—with the central "remote" repository on GitHub. There are plenty of tools that you can use to do this, such as GitHub Desktop.
53+
54+
Once you start to collaborate with others and all need to work on the same repository at the same time, you’ll continually:
55+
56+
* **Pull** all the latest changes made by your collaborators from the remote repository on GitHub.
57+
* **Push** back your own changes to the same remote repository on GitHub.
58+
59+
Git figures out how to intelligently merge this flow of changes, and GitHub helps you manage the flow through features such as "pull requests."
60+
61+
## Where do I start?
62+
63+
If you're new to GitHub, and unfamiliar with Git, we recommend working through the articles in the Start Your Journey category. The articles focus on tasks you can complete directly in your browser on GitHub and will help you to:
64+
65+
* **Create an account** on GitHub.
66+
* **Learn the "GitHub Flow"**, and the key principles of collaborative working (branches, commits, pull requests, merges).
67+
* **Personalise your profile** to share your interests and skills.
68+
* **Explore GitHub** to find inspiration for your own projects and connect with others.
69+
* Learn how to **download** interesting code for your own use.
70+
* Learn how to **upload** something you're working on to a GitHub repository.

src/fixtures/fixtures/content/get-started/start-your-journey/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ children:
99
- /hello-world
1010
- /link-rewriting
1111
- /dynamic-title
12+
- /api-article-body-test-page
1213
redirect_from:
1314
- /get-started/quickstart
1415
---
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { beforeAll, describe, expect, test } from 'vitest'
2+
3+
import { get } from '#src/tests/helpers/e2etest.js'
4+
5+
const makeURL = (pathname: string) => `/api/article/body?${new URLSearchParams({ pathname })}`
6+
7+
describe('article body api', () => {
8+
beforeAll(() => {
9+
// If you didn't set the `ROOT` variable, the tests will fail rather
10+
// cryptically. So as a warning for engineers running these tests,
11+
// alert in case it was accidentally forgotten.
12+
if (!process.env.ROOT) {
13+
console.warn(
14+
'WARNING: The articlebody tests require the ROOT environment variable to be set to the fixture root',
15+
)
16+
}
17+
// Ditto for fixture-based translations to work
18+
if (!process.env.TRANSLATIONS_FIXTURE_ROOT) {
19+
console.warn(
20+
'WARNING: The articlebody tests require the TRANSLATIONS_FIXTURE_ROOT environment variable to be set',
21+
)
22+
}
23+
})
24+
25+
test('happy path', async () => {
26+
const res = await get(makeURL('/en/get-started/start-your-journey/api-article-body-test-page'))
27+
expect(res.statusCode).toBe(200)
28+
expect(res.headers['content-type']).toContain('text/markdown')
29+
expect(res.body).toContain('## About GitHub')
30+
expect(res.body).toContain('## About Git')
31+
expect(res.body).toMatch(/^#+\s+\w+/m) // Check for any markdown heading pattern
32+
33+
expect(res.headers['set-cookie']).toBeUndefined()
34+
expect(res.headers['cache-control']).toContain('public')
35+
expect(res.headers['cache-control']).toMatch(/max-age=[1-9]/)
36+
expect(res.headers['surrogate-control']).toContain('public')
37+
expect(res.headers['surrogate-control']).toMatch(/max-age=[1-9]/)
38+
})
39+
40+
test('a pathname that does not exist', async () => {
41+
const res = await get(makeURL('/en/never/heard/of'))
42+
expect(res.statusCode).toBe(404)
43+
const { error } = JSON.parse(res.body)
44+
expect(error).toBe("No page found for '/en/never/heard/of'")
45+
})
46+
47+
test("no 'pathname' query string at all", async () => {
48+
const res = await get('/api/article/body')
49+
expect(res.statusCode).toBe(400)
50+
const { error } = JSON.parse(res.body)
51+
expect(error).toBe("No 'pathname' query")
52+
})
53+
54+
test('has proper markdown structure with frontmatter removed', async () => {
55+
const res = await get(makeURL('/en/get-started/start-your-journey/api-article-body-test-page'))
56+
57+
expect(res.statusCode).toBe(200)
58+
// Should not contain frontmatter
59+
expect(res.body).not.toMatch(/^---/)
60+
// Should have at least one heading
61+
expect(res.body).toMatch(/^#{1,6}\s+\w+/m)
62+
})
63+
64+
test("empty 'pathname' query string", async () => {
65+
const res = await get('/api/article/body?pathname=%20')
66+
expect(res.statusCode).toBe(400)
67+
const { error } = JSON.parse(res.body)
68+
expect(error).toBe("'pathname' query empty")
69+
})
70+
71+
test('repeated pathname query string key', async () => {
72+
const res = await get('/api/article/body?pathname=a&pathname=b')
73+
expect(res.statusCode).toBe(400)
74+
const { error } = JSON.parse(res.body)
75+
expect(error).toBe("Multiple 'pathname' keys")
76+
})
77+
})

src/shielding/tests/shielding.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,24 @@ describe('index.md and .md suffixes', () => {
7272
})
7373

7474
// TODO-ARTICLEAPI: unskip tests or replace when ready to ship article API
75-
test.skip('any URL that ends with /.md redirects', async () => {
75+
test('any URL that ends with /.md redirects', async () => {
7676
// With language prefix
7777
{
7878
const res = await get('/en/get-started/hello.md')
7979
expect(res.statusCode).toBe(302)
80-
expect(res.headers.location).toBe('/en/get-started/hello')
80+
expect(res.headers.location).toBe('/api/article/body?pathname=/en/get-started/hello')
8181
}
8282
// Without language prefix
8383
{
8484
const res = await get('/get-started/hello.md')
8585
expect(res.statusCode).toBe(302)
86-
expect(res.headers.location).toBe('/get-started/hello')
86+
expect(res.headers.location).toBe('/api/article/body?pathname=/get-started/hello')
8787
}
8888
// With query string
8989
{
9090
const res = await get('/get-started/hello.md?foo=bar')
9191
expect(res.statusCode).toBe(302)
92-
expect(res.headers.location).toBe('/get-started/hello?foo=bar')
92+
expect(res.headers.location).toBe('/api/article/body?pathname=/get-started/hello')
9393
}
9494
})
9595
})

0 commit comments

Comments
 (0)