Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(backend): kill many any in backend test (partial) #14054

Merged
merged 46 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
37f6fda
kill any on utils:api
KisaragiEffective Jun 20, 2024
ee465c8
kill any on timeline test
KisaragiEffective Jun 20, 2024
1c5e041
use optional chain to kill TS2532 on timeline test
KisaragiEffective Jun 20, 2024
30abfac
kill `as any` for ApMfmService
KisaragiEffective Jun 20, 2024
dc54f93
kill argument any for api-visibility
KisaragiEffective Jun 20, 2024
7dfd8f0
kill argument any across a few tests
KisaragiEffective Jun 20, 2024
3b2bf5e
do not return value that has yielded from `await`-ing `Promise<void>`
KisaragiEffective Jun 20, 2024
997b588
force cast
KisaragiEffective Jun 20, 2024
b99b7b5
runtime non-null assertion to coerce
KisaragiEffective Jun 20, 2024
a6db224
rewrite `assert.notEqual(expr, null)` to `assert.ok(expr)`
KisaragiEffective Jun 20, 2024
c884abb
change return type of `failedApiCall` to `void`
KisaragiEffective Jun 20, 2024
9e7f22f
split bindings for exports.ts
KisaragiEffective Jun 20, 2024
70ccbaa
runtime non-null assertion
KisaragiEffective Jun 20, 2024
e90854b
runtime non-null assertion
KisaragiEffective Jun 20, 2024
48cf32c
何故かうまく行かないので、とりあえずXORしてみる
KisaragiEffective Jun 20, 2024
b3464e0
Revert "何故かうまく行かないので、とりあえずXORしてみる"
KisaragiEffective Jun 20, 2024
03780bc
Merge branch 'develop' into refactor/kill-any/backend-test
KisaragiEffective Jun 22, 2024
58ead0a
Merge branch 'develop' into refactor/kill-any/backend-test
KisaragiEffective Jul 9, 2024
67718a5
castAsErrorで安全ではないキャストを隠蔽
KisaragiEffective Jul 9, 2024
7f145fd
型アサーションの追加
KisaragiEffective Jul 9, 2024
54ee883
Merge remote-tracking branch 'kisaragi/refactor/kill-any/backend-test…
KisaragiEffective Jul 9, 2024
0be833b
型アサーションの追加
KisaragiEffective Jul 9, 2024
6823408
型アサーションの追加
KisaragiEffective Jul 9, 2024
79be8d6
voidで値を返さない
KisaragiEffective Jul 9, 2024
c81ce80
castAsError
KisaragiEffective Jul 9, 2024
e4bb517
assert.ok => kill nullability
KisaragiEffective Jul 9, 2024
fb69649
もはや明示的な型の指定は必要ない
KisaragiEffective Jul 9, 2024
a28ca99
castAsError
KisaragiEffective Jul 9, 2024
8c777fe
castAsError
KisaragiEffective Jul 9, 2024
48c541d
型アサーションの追加
KisaragiEffective Jul 9, 2024
6871868
nullableを一旦抑止
KisaragiEffective Jul 9, 2024
65919a4
変数を分離して型エラーを排除
KisaragiEffective Jul 9, 2024
7f1fb71
不要なプロパティを削除する処理を隠蔽してanyを排除
KisaragiEffective Jul 9, 2024
fe95c05
Repository type
KisaragiEffective Jul 9, 2024
0e6f9ae
simple type
KisaragiEffective Jul 9, 2024
b5a0c5b
assert.ok => kill nullability
KisaragiEffective Jul 9, 2024
71b5e10
revert `as any` drop
KisaragiEffective Jul 9, 2024
1f189a4
test: fix invalid assertion
KisaragiEffective Jul 10, 2024
f9f9de5
Merge branch 'develop' into refactor/kill-any/backend-test
KisaragiEffective Jul 10, 2024
385ca7d
test: 52d8a54fc72b886fecb30a736b3ccf5057ea2a0c により型が合うようになった部分の`as an…
KisaragiEffective Jul 10, 2024
1cd4e98
format
KisaragiEffective Jul 10, 2024
80f1ad5
test: apply https://github.com/misskey-dev/misskey/pull/14054#discuss…
KisaragiEffective Jul 10, 2024
0de43cf
Merge remote-tracking branch 'kisaragi/refactor/kill-any/backend-test…
KisaragiEffective Jul 10, 2024
9090bff
test: use non-null assertion to suppress too many error
KisaragiEffective Jul 10, 2024
2aea350
Update packages/backend/test/utils.ts
KisaragiEffective Jul 10, 2024
91ee525
Merge branch 'develop' into refactor/kill-any/backend-test
KisaragiEffective Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/backend/src/core/activitypub/ApMfmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ApMfmService {
}

@bindThis
public getNoteHtml(note: MiNote, apAppend?: string) {
public getNoteHtml(note: Pick<MiNote, 'text' | 'mentionedRemoteUsers'>, apAppend?: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここをPickに変更した意図はどういったものですか?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit/ApMfmService{ text: string, mentionedRemoteUsers: any[] }を与えてその関数を呼び出していたためです: https://github.com/misskey-dev/misskey/pull/14054/files#diff-facbd928b8ce2116bfa431068a5c38d5ea30a3aaf4aa9a22a0eb366cf7caf442L26-L29

let noMisskeyContent = false;
const srcMfm = (note.text ?? '') + (apAppend ?? '');

Expand Down
30 changes: 16 additions & 14 deletions packages/backend/test/e2e/2fa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('2要素認証', () => {
username,
}, alice);
assert.strictEqual(usersShowResponse.status, 200);
assert.strictEqual(usersShowResponse.body.twoFactorEnabled, true);
assert.strictEqual((usersShowResponse.body as unknown as { twoFactorEnabled: boolean }).twoFactorEnabled, true);

const signinResponse = await api('signin', {
...signinParam(),
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('2要素認証', () => {
keyName,
credentialId,
creationOptions: registerKeyResponse.body,
}) as any, alice);
} as any) as any, alice);
assert.strictEqual(keyDoneResponse.status, 200);
assert.strictEqual(keyDoneResponse.body.id, credentialId.toString('base64url'));
assert.strictEqual(keyDoneResponse.body.name, keyName);
Expand All @@ -257,22 +257,22 @@ describe('2要素認証', () => {
username,
});
assert.strictEqual(usersShowResponse.status, 200);
assert.strictEqual(usersShowResponse.body.securityKeys, true);
assert.strictEqual((usersShowResponse.body as unknown as { securityKeys: boolean }).securityKeys, true);

const signinResponse = await api('signin', {
...signinParam(),
});
assert.strictEqual(signinResponse.status, 200);
assert.strictEqual(signinResponse.body.i, undefined);
assert.notEqual(signinResponse.body.challenge, undefined);
assert.notEqual(signinResponse.body.allowCredentials, undefined);
assert.strictEqual(signinResponse.body.allowCredentials[0].id, credentialId.toString('base64url'));
assert.notEqual((signinResponse.body as unknown as { challenge: unknown | undefined }).challenge, undefined);
assert.notEqual((signinResponse.body as unknown as { allowCredentials: unknown | undefined }).allowCredentials, undefined);
assert.strictEqual((signinResponse.body as unknown as { allowCredentials: {id: string}[] }).allowCredentials[0].id, credentialId.toString('base64url'));

const signinResponse2 = await api('signin', signinWithSecurityKeyParam({
keyName,
credentialId,
requestOptions: signinResponse.body,
}));
} as any));
assert.strictEqual(signinResponse2.status, 200);
assert.notEqual(signinResponse2.body.i, undefined);

Expand Down Expand Up @@ -307,7 +307,7 @@ describe('2要素認証', () => {
keyName,
credentialId,
creationOptions: registerKeyResponse.body,
}) as any, alice);
} as any) as any, alice);
assert.strictEqual(keyDoneResponse.status, 200);

const passwordLessResponse = await api('i/2fa/password-less', {
Expand All @@ -319,7 +319,7 @@ describe('2要素認証', () => {
username,
});
assert.strictEqual(usersShowResponse.status, 200);
assert.strictEqual(usersShowResponse.body.usePasswordLessLogin, true);
assert.strictEqual((usersShowResponse.body as unknown as { usePasswordLessLogin: boolean }).usePasswordLessLogin, true);

const signinResponse = await api('signin', {
...signinParam(),
Expand All @@ -333,7 +333,7 @@ describe('2要素認証', () => {
keyName,
credentialId,
requestOptions: signinResponse.body,
}),
} as any),
password: '',
});
assert.strictEqual(signinResponse2.status, 200);
Expand Down Expand Up @@ -370,7 +370,7 @@ describe('2要素認証', () => {
keyName,
credentialId,
creationOptions: registerKeyResponse.body,
}) as any, alice);
} as any) as any, alice);
assert.strictEqual(keyDoneResponse.status, 200);

const renamedKey = 'other-key';
Expand All @@ -383,6 +383,7 @@ describe('2要素認証', () => {
const iResponse = await api('i', {
}, alice);
assert.strictEqual(iResponse.status, 200);
assert.ok(iResponse.body.securityKeysList);
const securityKeys = iResponse.body.securityKeysList.filter((s: { id: string; }) => s.id === credentialId.toString('base64url'));
assert.strictEqual(securityKeys.length, 1);
assert.strictEqual(securityKeys[0].name, renamedKey);
Expand Down Expand Up @@ -419,13 +420,14 @@ describe('2要素認証', () => {
keyName,
credentialId,
creationOptions: registerKeyResponse.body,
}) as any, alice);
} as any) as any, alice);
assert.strictEqual(keyDoneResponse.status, 200);

// テストの実行順によっては複数残ってるので全部消す
const iResponse = await api('i', {
}, alice);
assert.strictEqual(iResponse.status, 200);
assert.ok(iResponse.body.securityKeysList);
for (const key of iResponse.body.securityKeysList) {
const removeKeyResponse = await api('i/2fa/remove-key', {
token: otpToken(registerResponse.body.secret),
Expand All @@ -439,7 +441,7 @@ describe('2要素認証', () => {
username,
});
assert.strictEqual(usersShowResponse.status, 200);
assert.strictEqual(usersShowResponse.body.securityKeys, false);
assert.strictEqual((usersShowResponse.body as unknown as { securityKeys: boolean }).securityKeys, false);
KisaragiEffective marked this conversation as resolved.
Show resolved Hide resolved

const signinResponse = await api('signin', {
...signinParam(),
Expand Down Expand Up @@ -470,7 +472,7 @@ describe('2要素認証', () => {
username,
});
assert.strictEqual(usersShowResponse.status, 200);
assert.strictEqual(usersShowResponse.body.twoFactorEnabled, true);
assert.strictEqual((usersShowResponse.body as unknown as { twoFactorEnabled: boolean }).twoFactorEnabled, true);

const unregisterResponse = await api('i/2fa/unregister', {
token: otpToken(registerResponse.body.secret),
Expand Down
16 changes: 8 additions & 8 deletions packages/backend/test/e2e/api-visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,21 @@ describe('API visibility', () => {
test('[HTL] public-post が 自分が見れる', async () => {
const res = await api('notes/timeline', { limit: 100 }, alice);
assert.strictEqual(res.status, 200);
const notes = res.body.filter((n: any) => n.id === pub.id);
const notes = res.body.filter(n => n.id === pub.id);
assert.strictEqual(notes[0].text, 'x');
});

test('[HTL] public-post が 非フォロワーから見れない', async () => {
const res = await api('notes/timeline', { limit: 100 }, other);
assert.strictEqual(res.status, 200);
const notes = res.body.filter((n: any) => n.id === pub.id);
const notes = res.body.filter(n => n.id === pub.id);
assert.strictEqual(notes.length, 0);
});

test('[HTL] followers-post が フォロワーから見れる', async () => {
const res = await api('notes/timeline', { limit: 100 }, follower);
assert.strictEqual(res.status, 200);
const notes = res.body.filter((n: any) => n.id === fol.id);
const notes = res.body.filter(n => n.id === fol.id);
assert.strictEqual(notes[0].text, 'x');
});
//#endregion
Expand All @@ -433,21 +433,21 @@ describe('API visibility', () => {
test('[replies] followers-reply が フォロワーから見れる', async () => {
const res = await api('notes/replies', { noteId: tgt.id, limit: 100 }, follower);
assert.strictEqual(res.status, 200);
const notes = res.body.filter((n: any) => n.id === folR.id);
const notes = res.body.filter(n => n.id === folR.id);
assert.strictEqual(notes[0].text, 'x');
});

test('[replies] followers-reply が 非フォロワー (リプライ先ではない) から見れない', async () => {
const res = await api('notes/replies', { noteId: tgt.id, limit: 100 }, other);
assert.strictEqual(res.status, 200);
const notes = res.body.filter((n: any) => n.id === folR.id);
const notes = res.body.filter(n => n.id === folR.id);
assert.strictEqual(notes.length, 0);
});

test('[replies] followers-reply が 非フォロワー (リプライ先である) から見れる', async () => {
const res = await api('notes/replies', { noteId: tgt.id, limit: 100 }, target);
assert.strictEqual(res.status, 200);
const notes = res.body.filter((n: any) => n.id === folR.id);
const notes = res.body.filter(n => n.id === folR.id);
assert.strictEqual(notes[0].text, 'x');
});
//#endregion
Expand All @@ -456,14 +456,14 @@ describe('API visibility', () => {
test('[mentions] followers-reply が 非フォロワー (リプライ先である) から見れる', async () => {
const res = await api('notes/mentions', { limit: 100 }, target);
assert.strictEqual(res.status, 200);
const notes = res.body.filter((n: any) => n.id === folR.id);
const notes = res.body.filter(n => n.id === folR.id);
assert.strictEqual(notes[0].text, 'x');
});

test('[mentions] followers-mention が 非フォロワー (メンション先である) から見れる', async () => {
const res = await api('notes/mentions', { limit: 100 }, target);
assert.strictEqual(res.status, 200);
const notes = res.body.filter((n: any) => n.id === folM.id);
const notes = res.body.filter(n => n.id === folM.id);
assert.strictEqual(notes[0].text, '@target x');
});
//#endregion
Expand Down
12 changes: 7 additions & 5 deletions packages/backend/test/e2e/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { api, post, signup } from '../utils.js';
import { api, castAsError, post, signup } from '../utils.js';
import type * as misskey from 'misskey-js';

describe('Block', () => {
Expand All @@ -33,7 +33,7 @@ describe('Block', () => {
const res = await api('following/create', { userId: alice.id }, bob);

assert.strictEqual(res.status, 400);
assert.strictEqual(res.body.error.id, 'c4ab57cc-4e41-45e9-bfd9-584f61e35ce0');
assert.strictEqual(castAsError(res.body).error.id, 'c4ab57cc-4e41-45e9-bfd9-584f61e35ce0');
});

test('ブロックされているユーザーにリアクションできない', async () => {
Expand All @@ -42,7 +42,8 @@ describe('Block', () => {
const res = await api('notes/reactions/create', { noteId: note.id, reaction: '👍' }, bob);

assert.strictEqual(res.status, 400);
assert.strictEqual(res.body.error.id, '20ef5475-9f38-4e4c-bd33-de6d979498ec');
assert.ok(res.body);
assert.strictEqual(castAsError(res.body).error.id, '20ef5475-9f38-4e4c-bd33-de6d979498ec');
});

test('ブロックされているユーザーに返信できない', async () => {
Expand All @@ -51,7 +52,8 @@ describe('Block', () => {
const res = await api('notes/create', { replyId: note.id, text: 'yo' }, bob);

assert.strictEqual(res.status, 400);
assert.strictEqual(res.body.error.id, 'b390d7e1-8a5e-46ed-b625-06271cafd3d3');
assert.ok(res.body);
assert.strictEqual(castAsError(res.body).error.id, 'b390d7e1-8a5e-46ed-b625-06271cafd3d3');
});

test('ブロックされているユーザーのノートをRenoteできない', async () => {
Expand All @@ -60,7 +62,7 @@ describe('Block', () => {
const res = await api('notes/create', { renoteId: note.id, text: 'yo' }, bob);

assert.strictEqual(res.status, 400);
assert.strictEqual(res.body.error.id, 'b390d7e1-8a5e-46ed-b625-06271cafd3d3');
assert.strictEqual(castAsError(res.body).error.id, 'b390d7e1-8a5e-46ed-b625-06271cafd3d3');
});

// TODO: ユーザーリストに入れられないテスト
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/test/e2e/clips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ describe('クリップ', () => {
};

const deleteClip = async (parameters: Misskey.entities.ClipsDeleteRequest, request: Partial<ApiRequest<'clips/delete'>> = {}): Promise<void> => {
return await successfulApiCall({
await successfulApiCall({
endpoint: 'clips/delete',
parameters,
user: alice,
...request,
}, {
status: 204,
}) as any as void;
});
};

const show = async (parameters: Misskey.entities.ClipsShowRequest, request: Partial<ApiRequest<'clips/show'>> = {}): Promise<Misskey.entities.Clip> => {
Expand Down Expand Up @@ -454,25 +454,25 @@ describe('クリップ', () => {
let aliceClip: Misskey.entities.Clip;

const favorite = async (parameters: Misskey.entities.ClipsFavoriteRequest, request: Partial<ApiRequest<'clips/favorite'>> = {}): Promise<void> => {
return successfulApiCall({
await successfulApiCall({
endpoint: 'clips/favorite',
parameters,
user: alice,
...request,
}, {
status: 204,
}) as any as void;
});
};

const unfavorite = async (parameters: Misskey.entities.ClipsUnfavoriteRequest, request: Partial<ApiRequest<'clips/unfavorite'>> = {}): Promise<void> => {
return successfulApiCall({
await successfulApiCall({
endpoint: 'clips/unfavorite',
parameters,
user: alice,
...request,
}, {
status: 204,
}) as any as void;
});
};

const myFavorites = async (request: Partial<ApiRequest<'clips/my-favorites'>> = {}): Promise<Misskey.entities.Clip[]> => {
Expand Down
17 changes: 9 additions & 8 deletions packages/backend/test/e2e/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as assert from 'assert';
// https://github.com/node-fetch/node-fetch/pull/1664
import { Blob } from 'node-fetch';
import { MiUser } from '@/models/_.js';
import { api, initTestDb, post, signup, simpleGet, uploadFile } from '../utils.js';
import { api, castAsError, initTestDb, post, signup, simpleGet, uploadFile } from '../utils.js';
import type * as misskey from 'misskey-js';

describe('Endpoints', () => {
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('Endpoints', () => {

assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.id, alice.id);
assert.strictEqual((res.body as unknown as { id: string }).id, alice.id);
});

test('ユーザーが存在しなかったら怒る', async () => {
Expand Down Expand Up @@ -285,7 +285,8 @@ describe('Endpoints', () => {
}, alice);

assert.strictEqual(res.status, 400);
assert.strictEqual(res.body.error.code, 'CANNOT_REACT_TO_RENOTE');
assert.ok(res.body);
assert.strictEqual(castAsError(res.body).error.code, 'CANNOT_REACT_TO_RENOTE');
});

test('引用にリアクションできる', async () => {
Expand Down Expand Up @@ -1063,7 +1064,7 @@ describe('Endpoints', () => {
userId: bob.id,
}, alice);
assert.strictEqual(res1.status, 204);
assert.strictEqual(res2.body?.memo, memo);
assert.strictEqual((res2.body as unknown as { memo: string })?.memo, memo);
});

test('自分に関するメモを更新できる', async () => {
Expand All @@ -1078,7 +1079,7 @@ describe('Endpoints', () => {
userId: alice.id,
}, alice);
assert.strictEqual(res1.status, 204);
assert.strictEqual(res2.body?.memo, memo);
assert.strictEqual((res2.body as unknown as { memo: string })?.memo, memo);
});

test('メモを削除できる', async () => {
Expand All @@ -1099,7 +1100,7 @@ describe('Endpoints', () => {
}, alice);

// memoには常に文字列かnullが入っている(5cac151)
assert.strictEqual(res.body.memo, null);
assert.strictEqual((res.body as unknown as { memo: string | null }).memo, null);
});

test('メモは個人ごとに独立して保存される', async () => {
Expand All @@ -1126,8 +1127,8 @@ describe('Endpoints', () => {
}, carol),
]);

assert.strictEqual(resAlice.body.memo, memoAliceToBob);
assert.strictEqual(resCarol.body.memo, memoCarolToBob);
assert.strictEqual((resAlice.body as unknown as { memo: string }).memo, memoAliceToBob);
assert.strictEqual((resCarol.body as unknown as { memo: string }).memo, memoCarolToBob);
});
});
});
Loading
Loading