mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-24 19:56:43 -06:00
b990ae6b23
* test(backend): add federation test * fix(ci): install pnpm * fix(ci): cd * fix(ci): build entire project * fix(ci): skip frontend build * fix(ci): pull submodule when checkout * chore: show log for debugging * Revert "chore: show log for debugging" This reverts commit a930964b8d6ba550c23bce1e7fb45d92eab49ef9. * fix(ci): build entire project * chore: omit unused globals * refactor: use strictEqual and simplify some asserts * test: follow requests * refactor: add resolveRemoteNote function * refactor: refine resolveRemoteUser function * refactor: cache admin credentials * refactor: simplify assertion with excluded fields * refactor: use assert * test: note * chore: labeler detect federation * test: blocking * test: move * fix: use appropriate TLD * chore: shorter purge interval * fix(ci): change TLD * refactor: delete trivial comment * test(user): isCat * chore: use jest * chore: omit logs * chore: add memo * fix(ci): omit unnecessary build * test: pinning Note * fix: build daemon in container * style: indent * test(streaming): timeline * chore: rename * fix: delete role after test * refactor: resolve users by uri * fix: delete antenna after test * test: api timeline * test: Note deletion * refactor: sleep function * test: notification * style: indent * refactor: type-safe host * docs: update description * refactor: resolve function params * fix(block): wrong test name * fix: invalid type * fix: longer timeout for fire testing * test(timeline): hashtag * test(note): vote delivery * fix: wrong description * fix: hashtag channel param type * refactor: wrap basic cases * test(timeline): add homeTimeline tests * fix(timeline): correct wrong case and description * test(notification): add tests for Note * refactor(user): wrap profile consistency with describe * chore(note): add issue link * test(timeline): add test * test(user): suspension * test: emoji * refactor: fetch admin first * perf: faster tests * test(drive): sensitive flag * test(emoji): add tests * chore: ignore .config/docker.env * chore: hard-coded tester IP address * test(emoji): custom emoji are surrounded by zero width space * refactor: client and username as property * test(notification): mute * fix(notification): correct description * test(block): mention * refactor(emoji): addCustomEmoji function * fix: typo * test(note): add reaction tests * test(timeline): Note deletion * fix: unnecessary ts-expect-error * refactor: unnecessary fetch mocking * chore: add TODO comments * test(user): deletion * chore: enable --frozen-lockfile * fix(ci): copying configs * docs: update CONTRIBUTING.md * docs: fix typo * chore: set default sleep duration * fix(notification): omit flaky tests * fix(notification): correct type * test(notification): add api endpoint tests * chore: remove redundant mute test * refactor: use param client * fix: start timer after trigger * refactor: remove unnecessary any * chore: shorter timeout for checking if fired * fix(block): remove outdated comment * refactor: shorten remote user variable name * refactor(block): use existing function * refactor: file upload * docs: update description * test(user): ffVisibility * fix: `/api/signin` -> `/api/signin-flow` * test: abuse report * refactor: use existing type * refactor: extract duplicate configs to template file * fix: typo * fix: avoid conflict * refactor: change container dependency * perf: start misskey parallelly * fix: remove dependency * chore(backend): add typecheck * test: add check for #14728 * chore: enable eslint check * perf: don't start linked services when test * test(note): remote note deletion for moderation * chore: define config template * chore: write setup script * refactor: omit unnecessary conditional * refactor: clarify scope * refactor: omit type assertion * refactor: omit logs * style * refactor: redundant promise * refactor: unnecessary imports * refactor: use readable error code * refactor: cache set in signin function * refactor: optimize import
317 lines
11 KiB
TypeScript
317 lines
11 KiB
TypeScript
import assert, { rejects, strictEqual } from 'node:assert';
|
|
import * as Misskey from 'misskey-js';
|
|
import { addCustomEmoji, createAccount, createModerator, deepStrictEqualWithExcludedFields, type LoginUser, resolveRemoteNote, resolveRemoteUser, sleep, uploadFile } from './utils.js';
|
|
|
|
describe('Note', () => {
|
|
let alice: LoginUser, bob: LoginUser;
|
|
let bobInA: Misskey.entities.UserDetailedNotMe, aliceInB: Misskey.entities.UserDetailedNotMe;
|
|
|
|
beforeAll(async () => {
|
|
[alice, bob] = await Promise.all([
|
|
createAccount('a.test'),
|
|
createAccount('b.test'),
|
|
]);
|
|
|
|
[bobInA, aliceInB] = await Promise.all([
|
|
resolveRemoteUser('b.test', bob.id, alice),
|
|
resolveRemoteUser('a.test', alice.id, bob),
|
|
]);
|
|
});
|
|
|
|
describe('Note content', () => {
|
|
test('Consistency of Public Note', async () => {
|
|
const image = await uploadFile('a.test', alice);
|
|
const note = (await alice.client.request('notes/create', {
|
|
text: 'I am Alice!',
|
|
fileIds: [image.id],
|
|
poll: {
|
|
choices: ['neko', 'inu'],
|
|
multiple: false,
|
|
expiredAfter: 60 * 60 * 1000,
|
|
},
|
|
})).createdNote;
|
|
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
deepStrictEqualWithExcludedFields(note, resolvedNote, [
|
|
'id',
|
|
'emojis',
|
|
/** Consistency of files is checked at {@link file://./drive.test.ts}, so let's skip. */
|
|
'fileIds',
|
|
'files',
|
|
/** @see https://github.com/misskey-dev/misskey/issues/12409 */
|
|
'reactionAcceptance',
|
|
'userId',
|
|
'user',
|
|
'uri',
|
|
]);
|
|
strictEqual(aliceInB.id, resolvedNote.userId);
|
|
});
|
|
|
|
test('Consistency of reply', async () => {
|
|
const _replyedNote = (await alice.client.request('notes/create', {
|
|
text: 'a',
|
|
})).createdNote;
|
|
const note = (await alice.client.request('notes/create', {
|
|
text: 'b',
|
|
replyId: _replyedNote.id,
|
|
})).createdNote;
|
|
// NOTE: the repliedCount is incremented, so fetch again
|
|
const replyedNote = await alice.client.request('notes/show', { noteId: _replyedNote.id });
|
|
strictEqual(replyedNote.repliesCount, 1);
|
|
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
deepStrictEqualWithExcludedFields(note, resolvedNote, [
|
|
'id',
|
|
'emojis',
|
|
'reactionAcceptance',
|
|
'replyId',
|
|
'reply',
|
|
'userId',
|
|
'user',
|
|
'uri',
|
|
]);
|
|
assert(resolvedNote.replyId != null);
|
|
assert(resolvedNote.reply != null);
|
|
deepStrictEqualWithExcludedFields(replyedNote, resolvedNote.reply, [
|
|
'id',
|
|
// TODO: why clippedCount loses consistency?
|
|
'clippedCount',
|
|
'emojis',
|
|
'userId',
|
|
'user',
|
|
'uri',
|
|
// flaky because this is parallelly incremented, so let's check it below
|
|
'repliesCount',
|
|
]);
|
|
strictEqual(aliceInB.id, resolvedNote.userId);
|
|
|
|
await sleep();
|
|
|
|
const resolvedReplyedNote = await bob.client.request('notes/show', { noteId: resolvedNote.replyId });
|
|
strictEqual(resolvedReplyedNote.repliesCount, 1);
|
|
});
|
|
|
|
test('Consistency of Renote', async () => {
|
|
// NOTE: the renoteCount is not incremented, so no need to fetch again
|
|
const renotedNote = (await alice.client.request('notes/create', {
|
|
text: 'a',
|
|
})).createdNote;
|
|
const note = (await alice.client.request('notes/create', {
|
|
text: 'b',
|
|
renoteId: renotedNote.id,
|
|
})).createdNote;
|
|
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
deepStrictEqualWithExcludedFields(note, resolvedNote, [
|
|
'id',
|
|
'emojis',
|
|
'reactionAcceptance',
|
|
'renoteId',
|
|
'renote',
|
|
'userId',
|
|
'user',
|
|
'uri',
|
|
]);
|
|
assert(resolvedNote.renoteId != null);
|
|
assert(resolvedNote.renote != null);
|
|
deepStrictEqualWithExcludedFields(renotedNote, resolvedNote.renote, [
|
|
'id',
|
|
'emojis',
|
|
'userId',
|
|
'user',
|
|
'uri',
|
|
]);
|
|
strictEqual(aliceInB.id, resolvedNote.userId);
|
|
});
|
|
});
|
|
|
|
describe('Other props', () => {
|
|
test('localOnly', async () => {
|
|
const note = (await alice.client.request('notes/create', { text: 'a', localOnly: true })).createdNote;
|
|
rejects(
|
|
async () => await bob.client.request('ap/show', { uri: `https://a.test/notes/${note.id}` }),
|
|
(err: any) => {
|
|
/**
|
|
* FIXME: this error is not handled
|
|
* @see https://github.com/misskey-dev/misskey/issues/12736
|
|
*/
|
|
strictEqual(err.code, 'INTERNAL_ERROR');
|
|
return true;
|
|
},
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('Deletion', () => {
|
|
describe('Check Delete consistency', () => {
|
|
let carol: LoginUser;
|
|
|
|
beforeAll(async () => {
|
|
carol = await createAccount('a.test');
|
|
|
|
await carol.client.request('following/create', { userId: bobInA.id });
|
|
await sleep();
|
|
});
|
|
|
|
test('Delete is derivered to followers', async () => {
|
|
const note = (await bob.client.request('notes/create', { text: 'I\'m Bob.' })).createdNote;
|
|
const noteInA = await resolveRemoteNote('b.test', note.id, carol);
|
|
await bob.client.request('notes/delete', { noteId: note.id });
|
|
await sleep();
|
|
|
|
await rejects(
|
|
async () => await carol.client.request('notes/show', { noteId: noteInA.id }),
|
|
(err: any) => {
|
|
strictEqual(err.code, 'NO_SUCH_NOTE');
|
|
return true;
|
|
},
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('Deletion of remote user\'s note for moderation', () => {
|
|
let note: Misskey.entities.Note;
|
|
|
|
test('Alice post is deleted in B', async () => {
|
|
note = (await alice.client.request('notes/create', { text: 'Hello' })).createdNote;
|
|
const noteInB = await resolveRemoteNote('a.test', note.id, bob);
|
|
const bMod = await createModerator('b.test');
|
|
await bMod.client.request('notes/delete', { noteId: noteInB.id });
|
|
await rejects(
|
|
async () => await bob.client.request('notes/show', { noteId: noteInB.id }),
|
|
(err: any) => {
|
|
strictEqual(err.code, 'NO_SUCH_NOTE');
|
|
return true;
|
|
},
|
|
);
|
|
});
|
|
|
|
/**
|
|
* FIXME: implement soft deletion as well as user?
|
|
* @see https://github.com/misskey-dev/misskey/issues/11437
|
|
*/
|
|
test.failing('Not found even if resolve again', async () => {
|
|
const noteInB = await resolveRemoteNote('a.test', note.id, bob);
|
|
await rejects(
|
|
async () => await bob.client.request('notes/show', { noteId: noteInB.id }),
|
|
(err: any) => {
|
|
strictEqual(err.code, 'NO_SUCH_NOTE');
|
|
return true;
|
|
},
|
|
);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Reaction', () => {
|
|
describe('Consistency', () => {
|
|
test('Unicode reaction', async () => {
|
|
const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
const reaction = '😅';
|
|
await bob.client.request('notes/reactions/create', { noteId: resolvedNote.id, reaction });
|
|
await sleep();
|
|
|
|
const reactions = await alice.client.request('notes/reactions', { noteId: note.id });
|
|
strictEqual(reactions.length, 1);
|
|
strictEqual(reactions[0].type, reaction);
|
|
strictEqual(reactions[0].user.id, bobInA.id);
|
|
});
|
|
|
|
test('Custom emoji reaction', async () => {
|
|
const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
const emoji = await addCustomEmoji('b.test');
|
|
await bob.client.request('notes/reactions/create', { noteId: resolvedNote.id, reaction: `:${emoji.name}:` });
|
|
await sleep();
|
|
|
|
const reactions = await alice.client.request('notes/reactions', { noteId: note.id });
|
|
strictEqual(reactions.length, 1);
|
|
strictEqual(reactions[0].type, `:${emoji.name}@b.test:`);
|
|
strictEqual(reactions[0].user.id, bobInA.id);
|
|
});
|
|
});
|
|
|
|
describe('Acceptance', () => {
|
|
test('Even if likeOnly, remote users can react with custom emoji, but it is converted to like', async () => {
|
|
const note = (await alice.client.request('notes/create', { text: 'a', reactionAcceptance: 'likeOnly' })).createdNote;
|
|
const noteInB = await resolveRemoteNote('a.test', note.id, bob);
|
|
const emoji = await addCustomEmoji('b.test');
|
|
await bob.client.request('notes/reactions/create', { noteId: noteInB.id, reaction: `:${emoji.name}:` });
|
|
await sleep();
|
|
|
|
const reactions = await alice.client.request('notes/reactions', { noteId: note.id });
|
|
strictEqual(reactions.length, 1);
|
|
strictEqual(reactions[0].type, '❤');
|
|
});
|
|
|
|
/**
|
|
* TODO: this may be unexpected behavior?
|
|
* @see https://github.com/misskey-dev/misskey/issues/12409
|
|
*/
|
|
test('Even if nonSensitiveOnly, remote users can react with sensitive emoji, and it is not converted', async () => {
|
|
const note = (await alice.client.request('notes/create', { text: 'a', reactionAcceptance: 'nonSensitiveOnly' })).createdNote;
|
|
const noteInB = await resolveRemoteNote('a.test', note.id, bob);
|
|
const emoji = await addCustomEmoji('b.test', { isSensitive: true });
|
|
await bob.client.request('notes/reactions/create', { noteId: noteInB.id, reaction: `:${emoji.name}:` });
|
|
await sleep();
|
|
|
|
const reactions = await alice.client.request('notes/reactions', { noteId: note.id });
|
|
strictEqual(reactions.length, 1);
|
|
strictEqual(reactions[0].type, `:${emoji.name}@b.test:`);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Poll', () => {
|
|
describe('Any remote user\'s vote is delivered to the author', () => {
|
|
let carol: LoginUser;
|
|
|
|
beforeAll(async () => {
|
|
carol = await createAccount('a.test');
|
|
});
|
|
|
|
test('Bob creates poll and receives a vote from Carol', async () => {
|
|
const note = (await bob.client.request('notes/create', { poll: { choices: ['inu', 'neko'] } })).createdNote;
|
|
const noteInA = await resolveRemoteNote('b.test', note.id, carol);
|
|
await carol.client.request('notes/polls/vote', { noteId: noteInA.id, choice: 0 });
|
|
await sleep();
|
|
|
|
const noteAfterVote = await bob.client.request('notes/show', { noteId: note.id });
|
|
assert(noteAfterVote.poll != null);
|
|
strictEqual(noteAfterVote.poll.choices[0].votes, 1);
|
|
strictEqual(noteAfterVote.poll.choices[1].votes, 0);
|
|
});
|
|
});
|
|
|
|
describe('Local user\'s vote is delivered to the author\'s remote followers', () => {
|
|
let bobRemoteFollower: LoginUser, localVoter: LoginUser;
|
|
|
|
beforeAll(async () => {
|
|
[
|
|
bobRemoteFollower,
|
|
localVoter,
|
|
] = await Promise.all([
|
|
createAccount('a.test'),
|
|
createAccount('b.test'),
|
|
]);
|
|
|
|
await bobRemoteFollower.client.request('following/create', { userId: bobInA.id });
|
|
await sleep();
|
|
});
|
|
|
|
test('A vote in Bob\'s server is delivered to Bob\'s remote followers', async () => {
|
|
const note = (await bob.client.request('notes/create', { poll: { choices: ['inu', 'neko'] } })).createdNote;
|
|
// NOTE: resolve before voting
|
|
const noteInA = await resolveRemoteNote('b.test', note.id, bobRemoteFollower);
|
|
await localVoter.client.request('notes/polls/vote', { noteId: note.id, choice: 0 });
|
|
await sleep();
|
|
|
|
const noteAfterVote = await bobRemoteFollower.client.request('notes/show', { noteId: noteInA.id });
|
|
assert(noteAfterVote.poll != null);
|
|
strictEqual(noteAfterVote.poll.choices[0].votes, 1);
|
|
strictEqual(noteAfterVote.poll.choices[1].votes, 0);
|
|
});
|
|
});
|
|
});
|
|
});
|