diff options
| author | Kagami Sascha Rosylight <saschanaz@outlook.com> | 2023-03-03 03:13:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-03 11:13:12 +0900 |
| commit | 61215e50ff9e4c84787c8d99c75fd36dafbd8815 (patch) | |
| tree | 36419e8a3ec97afa0a3a0011d523d80addf8e724 /packages/backend/test/e2e/fetch-resource.ts | |
| parent | fix(server): チャンネルでミュートが正しく機能していない... (diff) | |
| download | sharkey-61215e50ff9e4c84787c8d99c75fd36dafbd8815.tar.gz sharkey-61215e50ff9e4c84787c8d99c75fd36dafbd8815.tar.bz2 sharkey-61215e50ff9e4c84787c8d99c75fd36dafbd8815.zip | |
test(backend): APIテストの復活 (#10163)
* Revert 1c5291f8185651c231903129ee7c1cee263f9f03
* APIテストの復活
* apiテストの移行
* moduleNameMapper修正
* simpleGetでthrowしないように
status確認しているので要らない
* longer timeout
* ローカルでは問題ないのになんで
* case sensitive
* Run Nest instance within the current process
* Skip some setIntervals
* wait for 5 seconds
* kill them all!!
* logHeapUsage: true
* detectOpenHandlesがじゃましているらしい
* maxWorkers=1?
* restore drive api tests
* workerIdleMemoryLimit: 500MB
* 1024MiB
* Wait what
Diffstat (limited to 'packages/backend/test/e2e/fetch-resource.ts')
| -rw-r--r-- | packages/backend/test/e2e/fetch-resource.ts | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/packages/backend/test/e2e/fetch-resource.ts b/packages/backend/test/e2e/fetch-resource.ts new file mode 100644 index 0000000000..6b3c795235 --- /dev/null +++ b/packages/backend/test/e2e/fetch-resource.ts @@ -0,0 +1,193 @@ +process.env.NODE_ENV = 'test'; + +import * as assert from 'assert'; +import { startServer, signup, post, api, simpleGet } from '../utils.js'; +import type { INestApplicationContext } from '@nestjs/common'; + +// Request Accept +const ONLY_AP = 'application/activity+json'; +const PREFER_AP = 'application/activity+json, */*'; +const PREFER_HTML = 'text/html, */*'; +const UNSPECIFIED = '*/*'; + +// Response Content-Type +const AP = 'application/activity+json; charset=utf-8'; +const HTML = 'text/html; charset=utf-8'; + +describe('Fetch resource', () => { + let p: INestApplicationContext; + + let alice: any; + let alicesPost: any; + + beforeAll(async () => { + p = await startServer(); + alice = await signup({ username: 'alice' }); + alicesPost = await post(alice, { + text: 'test', + }); + }, 1000 * 60 * 2); + + afterAll(async () => { + await p.close(); + }); + + describe('Common', () => { + test('meta', async () => { + const res = await api('/meta', { + }); + + assert.strictEqual(res.status, 200); + }); + + test('GET root', async () => { + const res = await simpleGet('/'); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, HTML); + }); + + test('GET docs', async () => { + const res = await simpleGet('/docs/ja-JP/about'); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, HTML); + }); + + test('GET api-doc (廃止)', async () => { + const res = await simpleGet('/api-doc'); + assert.strictEqual(res.status, 404); + }); + + test('GET api.json (廃止)', async () => { + const res = await simpleGet('/api.json'); + assert.strictEqual(res.status, 404); + }); + + test('GET api/foo (存在しない)', async () => { + const res = await simpleGet('/api/foo'); + assert.strictEqual(res.status, 404); + assert.strictEqual(res.body.error.code, 'UNKNOWN_API_ENDPOINT'); + }); + + test('GET favicon.ico', async () => { + const res = await simpleGet('/favicon.ico'); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, 'image/vnd.microsoft.icon'); + }); + + test('GET apple-touch-icon.png', async () => { + const res = await simpleGet('/apple-touch-icon.png'); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, 'image/png'); + }); + + test('GET twemoji svg', async () => { + const res = await simpleGet('/twemoji/2764.svg'); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, 'image/svg+xml'); + }); + + test('GET twemoji svg with hyphen', async () => { + const res = await simpleGet('/twemoji/2764-fe0f-200d-1f525.svg'); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, 'image/svg+xml'); + }); + }); + + describe('/@:username', () => { + test('Only AP => AP', async () => { + const res = await simpleGet(`/@${alice.username}`, ONLY_AP); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, AP); + }); + + test('Prefer AP => AP', async () => { + const res = await simpleGet(`/@${alice.username}`, PREFER_AP); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, AP); + }); + + test('Prefer HTML => HTML', async () => { + const res = await simpleGet(`/@${alice.username}`, PREFER_HTML); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, HTML); + }); + + test('Unspecified => HTML', async () => { + const res = await simpleGet(`/@${alice.username}`, UNSPECIFIED); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, HTML); + }); + }); + + describe('/users/:id', () => { + test('Only AP => AP', async () => { + const res = await simpleGet(`/users/${alice.id}`, ONLY_AP); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, AP); + }); + + test('Prefer AP => AP', async () => { + const res = await simpleGet(`/users/${alice.id}`, PREFER_AP); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, AP); + }); + + test('Prefer HTML => Redirect to /@:username', async () => { + const res = await simpleGet(`/users/${alice.id}`, PREFER_HTML); + assert.strictEqual(res.status, 302); + assert.strictEqual(res.location, `/@${alice.username}`); + }); + + test('Undecided => HTML', async () => { + const res = await simpleGet(`/users/${alice.id}`, UNSPECIFIED); + assert.strictEqual(res.status, 302); + assert.strictEqual(res.location, `/@${alice.username}`); + }); + }); + + describe('/notes/:id', () => { + test('Only AP => AP', async () => { + const res = await simpleGet(`/notes/${alicesPost.id}`, ONLY_AP); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, AP); + }); + + test('Prefer AP => AP', async () => { + const res = await simpleGet(`/notes/${alicesPost.id}`, PREFER_AP); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, AP); + }); + + test('Prefer HTML => HTML', async () => { + const res = await simpleGet(`/notes/${alicesPost.id}`, PREFER_HTML); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, HTML); + }); + + test('Unspecified => HTML', async () => { + const res = await simpleGet(`/notes/${alicesPost.id}`, UNSPECIFIED); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, HTML); + }); + }); + + describe('Feeds', () => { + test('RSS', async () => { + const res = await simpleGet(`/@${alice.username}.rss`, UNSPECIFIED); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, 'application/rss+xml; charset=utf-8'); + }); + + test('ATOM', async () => { + const res = await simpleGet(`/@${alice.username}.atom`, UNSPECIFIED); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, 'application/atom+xml; charset=utf-8'); + }); + + test('JSON', async () => { + const res = await simpleGet(`/@${alice.username}.json`, UNSPECIFIED); + assert.strictEqual(res.status, 200); + assert.strictEqual(res.type, 'application/json; charset=utf-8'); + }); + }); +}); |