chore(backend, misskey-js): add type for signup (#11043)
* chore(backend, misskey-js): add type for signup * rerun
This commit is contained in:
parent
a2c0573f84
commit
7bb8c71543
21 changed files with 354 additions and 280 deletions
|
@ -4,6 +4,7 @@ import * as assert from 'assert';
|
|||
import { startServer, channel, clip, cookie, galleryPost, signup, page, play, post, simpleGet, uploadFile } from '../utils.js';
|
||||
import type { SimpleGetResponse } from '../utils.js';
|
||||
import type { INestApplicationContext } from '@nestjs/common';
|
||||
import type * as misskey from 'misskey-js';
|
||||
|
||||
// Request Accept
|
||||
const ONLY_AP = 'application/activity+json';
|
||||
|
@ -19,7 +20,7 @@ const JSON_UTF8 = 'application/json; charset=utf-8';
|
|||
describe('Webリソース', () => {
|
||||
let app: INestApplicationContext;
|
||||
|
||||
let alice: any;
|
||||
let alice: misskey.entities.MeSignup;
|
||||
let aliceUploadedFile: any;
|
||||
let alicesPost: any;
|
||||
let alicePage: any;
|
||||
|
@ -28,8 +29,8 @@ describe('Webリソース', () => {
|
|||
let aliceGalleryPost: any;
|
||||
let aliceChannel: any;
|
||||
|
||||
type Request = {
|
||||
path: string,
|
||||
type Request = {
|
||||
path: string,
|
||||
accept?: string,
|
||||
cookie?: string,
|
||||
};
|
||||
|
@ -46,7 +47,7 @@ describe('Webリソース', () => {
|
|||
const notOk = async (param: Request & {
|
||||
status?: number,
|
||||
code?: string,
|
||||
}): Promise<SimpleGetResponse> => {
|
||||
}): Promise<SimpleGetResponse> => {
|
||||
const { path, accept, cookie, status, code } = param;
|
||||
const res = await simpleGet(path, accept, cookie);
|
||||
assert.notStrictEqual(res.status, 200);
|
||||
|
@ -58,8 +59,8 @@ describe('Webリソース', () => {
|
|||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
const notFound = async (param: Request): Promise<SimpleGetResponse> => {
|
||||
|
||||
const notFound = async (param: Request): Promise<SimpleGetResponse> => {
|
||||
return await notOk({
|
||||
...param,
|
||||
status: 404,
|
||||
|
@ -94,23 +95,23 @@ describe('Webリソース', () => {
|
|||
{ path: '/', type: HTML },
|
||||
{ path: '/docs/ja-JP/about', type: HTML }, // "指定されたURLに該当するページはありませんでした。"
|
||||
// fastify-static gives charset=UTF-8 instead of utf-8 and that's okay
|
||||
{ path: '/api-doc', type: 'text/html; charset=UTF-8' },
|
||||
{ path: '/api.json', type: JSON_UTF8 },
|
||||
{ path: '/api-console', type: HTML },
|
||||
{ path: '/_info_card_', type: HTML },
|
||||
{ path: '/bios', type: HTML },
|
||||
{ path: '/cli', type: HTML },
|
||||
{ path: '/flush', type: HTML },
|
||||
{ path: '/api-doc', type: 'text/html; charset=UTF-8' },
|
||||
{ path: '/api.json', type: JSON_UTF8 },
|
||||
{ path: '/api-console', type: HTML },
|
||||
{ path: '/_info_card_', type: HTML },
|
||||
{ path: '/bios', type: HTML },
|
||||
{ path: '/cli', type: HTML },
|
||||
{ path: '/flush', type: HTML },
|
||||
{ path: '/robots.txt', type: 'text/plain; charset=UTF-8' },
|
||||
{ path: '/favicon.ico', type: 'image/vnd.microsoft.icon' },
|
||||
{ path: '/favicon.ico', type: 'image/vnd.microsoft.icon' },
|
||||
{ path: '/opensearch.xml', type: 'application/opensearchdescription+xml' },
|
||||
{ path: '/apple-touch-icon.png', type: 'image/png' },
|
||||
{ path: '/twemoji/2764.svg', type: 'image/svg+xml' },
|
||||
{ path: '/twemoji/2764-fe0f-200d-1f525.svg', type: 'image/svg+xml' },
|
||||
{ path: '/twemoji-badge/2764.png', type: 'image/png' },
|
||||
{ path: '/apple-touch-icon.png', type: 'image/png' },
|
||||
{ path: '/twemoji/2764.svg', type: 'image/svg+xml' },
|
||||
{ path: '/twemoji/2764-fe0f-200d-1f525.svg', type: 'image/svg+xml' },
|
||||
{ path: '/twemoji-badge/2764.png', type: 'image/png' },
|
||||
{ path: '/twemoji-badge/2764-fe0f-200d-1f525.png', type: 'image/png' },
|
||||
{ path: '/fluent-emoji/2764.png', type: 'image/png' },
|
||||
{ path: '/fluent-emoji/2764-fe0f-200d-1f525.png', type: 'image/png' },
|
||||
{ path: '/fluent-emoji/2764.png', type: 'image/png' },
|
||||
{ path: '/fluent-emoji/2764-fe0f-200d-1f525.png', type: 'image/png' },
|
||||
])('$path', (p) => {
|
||||
test('がGETできる。', async () => await ok({ ...p }));
|
||||
|
||||
|
@ -120,58 +121,58 @@ describe('Webリソース', () => {
|
|||
});
|
||||
|
||||
describe.each([
|
||||
{ path: '/twemoji/2764.png' },
|
||||
{ path: '/twemoji/2764-fe0f-200d-1f525.png' },
|
||||
{ path: '/twemoji-badge/2764.svg' },
|
||||
{ path: '/twemoji/2764.png' },
|
||||
{ path: '/twemoji/2764-fe0f-200d-1f525.png' },
|
||||
{ path: '/twemoji-badge/2764.svg' },
|
||||
{ path: '/twemoji-badge/2764-fe0f-200d-1f525.svg' },
|
||||
{ path: '/fluent-emoji/2764.svg' },
|
||||
{ path: '/fluent-emoji/2764-fe0f-200d-1f525.svg' },
|
||||
{ path: '/fluent-emoji/2764.svg' },
|
||||
{ path: '/fluent-emoji/2764-fe0f-200d-1f525.svg' },
|
||||
])('$path', ({ path }) => {
|
||||
test('はGETできない。', async () => await notFound({ path }));
|
||||
});
|
||||
|
||||
describe.each([
|
||||
{ ext: 'rss', type: 'application/rss+xml; charset=utf-8' },
|
||||
{ ext: 'atom', type: 'application/atom+xml; charset=utf-8' },
|
||||
{ ext: 'json', type: 'application/json; charset=utf-8' },
|
||||
{ ext: 'rss', type: 'application/rss+xml; charset=utf-8' },
|
||||
{ ext: 'atom', type: 'application/atom+xml; charset=utf-8' },
|
||||
{ ext: 'json', type: 'application/json; charset=utf-8' },
|
||||
])('/@:username.$ext', ({ ext, type }) => {
|
||||
const path = (username: string): string => `/@${username}.${ext}`;
|
||||
|
||||
test('がGETできる。', async () => await ok({
|
||||
test('がGETできる。', async () => await ok({
|
||||
path: path(alice.username),
|
||||
type,
|
||||
}));
|
||||
|
||||
test('は存在しないユーザーはGETできない。', async () => await notOk({
|
||||
test('は存在しないユーザーはGETできない。', async () => await notOk({
|
||||
path: path('nonexisting'),
|
||||
status: 404,
|
||||
status: 404,
|
||||
}));
|
||||
});
|
||||
|
||||
describe.each([{ path: '/api/foo' }])('$path', ({ path }) => {
|
||||
test('はGETできない。', async () => await notOk({
|
||||
test('はGETできない。', async () => await notOk({
|
||||
path,
|
||||
status: 404,
|
||||
status: 404,
|
||||
code: 'UNKNOWN_API_ENDPOINT',
|
||||
}));
|
||||
});
|
||||
|
||||
describe.each([{ path: '/queue' }])('$path', ({ path }) => {
|
||||
test('はadminでなければGETできない。', async () => await notOk({
|
||||
test('はadminでなければGETできない。', async () => await notOk({
|
||||
path,
|
||||
status: 500, // FIXME? 403ではない。
|
||||
}));
|
||||
|
||||
test('はadminならGETできる。', async () => await ok({
|
||||
|
||||
test('はadminならGETできる。', async () => await ok({
|
||||
path,
|
||||
cookie: cookie(alice),
|
||||
}));
|
||||
}));
|
||||
});
|
||||
|
||||
describe.each([{ path: '/streaming' }])('$path', ({ path }) => {
|
||||
test('はGETできない。', async () => await notOk({
|
||||
test('はGETできない。', async () => await notOk({
|
||||
path,
|
||||
status: 503,
|
||||
status: 503,
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -183,21 +184,21 @@ describe('Webリソース', () => {
|
|||
{ accept: UNSPECIFIED },
|
||||
])('(Acceptヘッダ: $accept)', ({ accept }) => {
|
||||
test('はHTMLとしてGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(alice.username),
|
||||
accept,
|
||||
const res = await ok({
|
||||
path: path(alice.username),
|
||||
accept,
|
||||
type: HTML,
|
||||
});
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-username'), alice.username);
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-id'), alice.id);
|
||||
|
||||
|
||||
// TODO ogタグの検証
|
||||
// TODO profile.noCrawleの検証
|
||||
// TODO twitter:creatorの検証
|
||||
// TODO <link rel="me" ...>の検証
|
||||
});
|
||||
test('はHTMLとしてGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
test('はHTMLとしてGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
type: HTML,
|
||||
}));
|
||||
});
|
||||
|
@ -207,22 +208,22 @@ describe('Webリソース', () => {
|
|||
{ accept: PREFER_AP },
|
||||
])('(Acceptヘッダ: $accept)', ({ accept }) => {
|
||||
test('はActivityPubとしてGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(alice.username),
|
||||
accept,
|
||||
const res = await ok({
|
||||
path: path(alice.username),
|
||||
accept,
|
||||
type: AP,
|
||||
});
|
||||
assert.strictEqual(res.body.type, 'Person');
|
||||
});
|
||||
|
||||
test('は存在しないIDのときActivityPubとしてGETできない。', async () => await notFound({
|
||||
path: path('xxxxxxxxxx'),
|
||||
test('は存在しないIDのときActivityPubとしてGETできない。', async () => await notFound({
|
||||
path: path('xxxxxxxxxx'),
|
||||
accept,
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe.each([
|
||||
describe.each([
|
||||
// 実際のハンドルはフロントエンド(index.vue)で行われる
|
||||
{ sub: 'home' },
|
||||
{ sub: 'notes' },
|
||||
|
@ -236,32 +237,32 @@ describe('Webリソース', () => {
|
|||
const path = (username: string): string => `/@${username}/${sub}`;
|
||||
|
||||
test('はHTMLとしてGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(alice.username),
|
||||
const res = await ok({
|
||||
path: path(alice.username),
|
||||
});
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-username'), alice.username);
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-id'), alice.id);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('/@:user/pages/:page', () => {
|
||||
const path = (username: string, pagename: string): string => `/@${username}/pages/${pagename}`;
|
||||
|
||||
test('はHTMLとしてGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(alice.username, alicePage.name),
|
||||
const res = await ok({
|
||||
path: path(alice.username, alicePage.name),
|
||||
});
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-username'), alice.username);
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-id'), alice.id);
|
||||
assert.strictEqual(metaTag(res, 'misskey:page-id'), alicePage.id);
|
||||
|
||||
|
||||
// TODO ogタグの検証
|
||||
// TODO profile.noCrawleの検証
|
||||
// TODO twitter:creatorの検証
|
||||
});
|
||||
|
||||
test('はGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path(alice.username, 'xxxxxxxxxx'),
|
||||
|
||||
test('はGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path(alice.username, 'xxxxxxxxxx'),
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -278,7 +279,7 @@ describe('Webリソース', () => {
|
|||
assert.strictEqual(res.location, `/@${alice.username}`);
|
||||
});
|
||||
|
||||
test('は存在しないユーザーはGETできない。', async () => await notFound({
|
||||
test('は存在しないユーザーはGETできない。', async () => await notFound({
|
||||
path: path('xxxxxxxx'),
|
||||
}));
|
||||
});
|
||||
|
@ -288,24 +289,24 @@ describe('Webリソース', () => {
|
|||
{ accept: PREFER_AP },
|
||||
])('(Acceptヘッダ: $accept)', ({ accept }) => {
|
||||
test('はActivityPubとしてGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(alice.id),
|
||||
accept,
|
||||
const res = await ok({
|
||||
path: path(alice.id),
|
||||
accept,
|
||||
type: AP,
|
||||
});
|
||||
assert.strictEqual(res.body.type, 'Person');
|
||||
});
|
||||
|
||||
test('は存在しないIDのときActivityPubとしてGETできない。', async () => await notOk({
|
||||
test('は存在しないIDのときActivityPubとしてGETできない。', async () => await notOk({
|
||||
path: path('xxxxxxxx'),
|
||||
accept,
|
||||
status: 404,
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('/users/inbox', () => {
|
||||
test('がGETできる。(POST専用だけど4xx/5xxにならずHTMLが返ってくる)', async () => await ok({
|
||||
test('がGETできる。(POST専用だけど4xx/5xxにならずHTMLが返ってくる)', async () => await ok({
|
||||
path: '/inbox',
|
||||
}));
|
||||
|
||||
|
@ -315,7 +316,7 @@ describe('Webリソース', () => {
|
|||
describe('/users/:id/inbox', () => {
|
||||
const path = (id: string): string => `/users/${id}/inbox`;
|
||||
|
||||
test('がGETできる。(POST専用だけど4xx/5xxにならずHTMLが返ってくる)', async () => await ok({
|
||||
test('がGETできる。(POST専用だけど4xx/5xxにならずHTMLが返ってくる)', async () => await ok({
|
||||
path: path(alice.id),
|
||||
}));
|
||||
|
||||
|
@ -326,14 +327,14 @@ describe('Webリソース', () => {
|
|||
const path = (id: string): string => `/users/${id}/outbox`;
|
||||
|
||||
test('がGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(alice.id),
|
||||
const res = await ok({
|
||||
path: path(alice.id),
|
||||
type: AP,
|
||||
});
|
||||
assert.strictEqual(res.body.type, 'OrderedCollection');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('/notes/:id', () => {
|
||||
const path = (noteId: string): string => `/notes/${noteId}`;
|
||||
|
||||
|
@ -342,22 +343,22 @@ describe('Webリソース', () => {
|
|||
{ accept: UNSPECIFIED },
|
||||
])('(Acceptヘッダ: $accept)', ({ accept }) => {
|
||||
test('はHTMLとしてGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(alicesPost.id),
|
||||
accept,
|
||||
const res = await ok({
|
||||
path: path(alicesPost.id),
|
||||
accept,
|
||||
type: HTML,
|
||||
});
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-username'), alice.username);
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-id'), alice.id);
|
||||
assert.strictEqual(metaTag(res, 'misskey:note-id'), alicesPost.id);
|
||||
|
||||
assert.strictEqual(metaTag(res, 'misskey:note-id'), alicesPost.id);
|
||||
|
||||
// TODO ogタグの検証
|
||||
// TODO profile.noCrawleの検証
|
||||
// TODO twitter:creatorの検証
|
||||
});
|
||||
|
||||
test('はHTMLとしてGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
test('はHTMLとしてGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -366,48 +367,48 @@ describe('Webリソース', () => {
|
|||
{ accept: PREFER_AP },
|
||||
])('(Acceptヘッダ: $accept)', ({ accept }) => {
|
||||
test('はActivityPubとしてGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(alicesPost.id),
|
||||
const res = await ok({
|
||||
path: path(alicesPost.id),
|
||||
accept,
|
||||
type: AP,
|
||||
});
|
||||
assert.strictEqual(res.body.type, 'Note');
|
||||
});
|
||||
|
||||
test('は存在しないIDのときActivityPubとしてGETできない。', async () => await notFound({
|
||||
path: path('xxxxxxxxxx'),
|
||||
test('は存在しないIDのときActivityPubとしてGETできない。', async () => await notFound({
|
||||
path: path('xxxxxxxxxx'),
|
||||
accept,
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('/play/:id', () => {
|
||||
const path = (playid: string): string => `/play/${playid}`;
|
||||
|
||||
test('がGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(alicePlay.id),
|
||||
const res = await ok({
|
||||
path: path(alicePlay.id),
|
||||
});
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-username'), alice.username);
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-id'), alice.id);
|
||||
assert.strictEqual(metaTag(res, 'misskey:flash-id'), alicePlay.id);
|
||||
|
||||
|
||||
// TODO ogタグの検証
|
||||
// TODO profile.noCrawleの検証
|
||||
// TODO twitter:creatorの検証
|
||||
});
|
||||
|
||||
test('がGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
test('がGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
describe('/clips/:clip', () => {
|
||||
const path = (clip: string): string => `/clips/${clip}`;
|
||||
|
||||
test('がGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(aliceClip.id),
|
||||
const res = await ok({
|
||||
path: path(aliceClip.id),
|
||||
});
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-username'), alice.username);
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-id'), alice.id);
|
||||
|
@ -416,9 +417,9 @@ describe('Webリソース', () => {
|
|||
// TODO ogタグの検証
|
||||
// TODO profile.noCrawleの検証
|
||||
});
|
||||
|
||||
test('がGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
|
||||
test('がGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -426,8 +427,8 @@ describe('Webリソース', () => {
|
|||
const path = (post: string): string => `/gallery/${post}`;
|
||||
|
||||
test('がGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(aliceGalleryPost.id),
|
||||
const res = await ok({
|
||||
path: path(aliceGalleryPost.id),
|
||||
});
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-username'), alice.username);
|
||||
assert.strictEqual(metaTag(res, 'misskey:user-id'), alice.id);
|
||||
|
@ -436,26 +437,26 @@ describe('Webリソース', () => {
|
|||
// TODO profile.noCrawleの検証
|
||||
// TODO twitter:creatorの検証
|
||||
});
|
||||
|
||||
test('がGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
|
||||
test('がGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
describe('/channels/:channel', () => {
|
||||
const path = (channel: string): string => `/channels/${channel}`;
|
||||
|
||||
test('はGETできる。', async () => {
|
||||
const res = await ok({
|
||||
path: path(aliceChannel.id),
|
||||
path: path(aliceChannel.id),
|
||||
});
|
||||
|
||||
// FIXME: misskey関連のmetaタグの設定がない
|
||||
// TODO ogタグの検証
|
||||
});
|
||||
|
||||
test('がGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
|
||||
test('がGETできる。(存在しないIDでも。)', async () => await ok({
|
||||
path: path('xxxxxxxxxx'),
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue