mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-05 22:56:00 +02:00
* wip * update fake-timers and migrate * fix * remove jest-mock * fix * fix * fix * fix * attempt to fix unit tests * attempt to fix e2e tests * fix federation test [ci skip] * attempt to fix e2e tests * fix typecheck * fix unit tests * fix * attempt to fix e2e * fix * Revert "attempt to fix e2e" This reverts commitb7b7b05d85. * attempt to fix e2e * revert attempt to fix e2e * update deps * update vitest * migrate * attempt to fix e2e * update * fix * remove vite swc plugin as oxc parser can handle decorators * attempt to fix drive/files/create test * Revert "attempt to fix drive/files/create test" This reverts commit4715153375. * fix: エンドポイントにまつわるテストをunitからe2eに移動 * attempt to fix e2e * remove swc * attempt to fix e2e * Revert "attempt to fix e2e" This reverts commit9fb86a4076. * add logs for debug * attempt to fix e2e * Partially revert "attempt to fix e2e" This reverts commitfb0008c85a. * attempt to fix test * fix: attempt to fix test * Revert "fix: attempt to fix test" This reverts commited2f5c40e8. * Revert "attempt to fix test" This reverts commitd7329c46f1. * attempt to fix e2e * fix: surpass eventemitter warning by increasing defaultMaxListeners * attempt to fix e2e * fix * fix e2e not ending properly * exp: add hanging-process reporter for investigation * Revert "exp: add hanging-process reporter for investigation" This reverts commit26851f8282. * update changelog
226 lines
7.6 KiB
TypeScript
226 lines
7.6 KiB
TypeScript
import { describe, test, beforeAll } from 'vitest';
|
|
import { deepStrictEqual, rejects, strictEqual } from 'node:assert';
|
|
import * as Misskey from 'misskey-js';
|
|
import { assertNotificationReceived, createAccount, type LoginUser, resolveRemoteNote, resolveRemoteUser, sleep } from './utils.js';
|
|
|
|
describe('Block', () => {
|
|
describe('Check follow', () => {
|
|
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),
|
|
]);
|
|
});
|
|
|
|
test('Cannot follow if blocked', async () => {
|
|
await alice.client.request('blocking/create', { userId: bobInA.id });
|
|
await sleep();
|
|
await rejects(
|
|
async () => await bob.client.request('following/create', { userId: aliceInB.id }),
|
|
(err: any) => {
|
|
strictEqual(err.code, 'BLOCKED');
|
|
return true;
|
|
},
|
|
);
|
|
|
|
const following = await bob.client.request('users/following', { userId: bob.id });
|
|
strictEqual(following.length, 0);
|
|
const followers = await alice.client.request('users/followers', { userId: alice.id });
|
|
strictEqual(followers.length, 0);
|
|
});
|
|
|
|
// FIXME: this is invalid case
|
|
test('Cannot follow even if unblocked', async () => {
|
|
// unblock here
|
|
await alice.client.request('blocking/delete', { userId: bobInA.id });
|
|
await sleep();
|
|
|
|
// TODO: why still being blocked?
|
|
await rejects(
|
|
async () => await bob.client.request('following/create', { userId: aliceInB.id }),
|
|
(err: any) => {
|
|
strictEqual(err.code, 'BLOCKED');
|
|
return true;
|
|
},
|
|
);
|
|
});
|
|
|
|
test.skip('Can follow if unblocked', async () => {
|
|
await alice.client.request('blocking/delete', { userId: bobInA.id });
|
|
await sleep();
|
|
|
|
await bob.client.request('following/create', { userId: aliceInB.id });
|
|
await sleep();
|
|
|
|
const following = await bob.client.request('users/following', { userId: bob.id });
|
|
strictEqual(following.length, 1);
|
|
const followers = await alice.client.request('users/followers', { userId: alice.id });
|
|
strictEqual(followers.length, 1);
|
|
});
|
|
|
|
test.skip('Remove follower when block them', async () => {
|
|
test('before block', async () => {
|
|
const following = await bob.client.request('users/following', { userId: bob.id });
|
|
strictEqual(following.length, 1);
|
|
const followers = await alice.client.request('users/followers', { userId: alice.id });
|
|
strictEqual(followers.length, 1);
|
|
});
|
|
|
|
await alice.client.request('blocking/create', { userId: bobInA.id });
|
|
await sleep();
|
|
|
|
test('after block', async () => {
|
|
const following = await bob.client.request('users/following', { userId: bob.id });
|
|
strictEqual(following.length, 0);
|
|
const followers = await alice.client.request('users/followers', { userId: alice.id });
|
|
strictEqual(followers.length, 0);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Check reply', () => {
|
|
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),
|
|
]);
|
|
});
|
|
|
|
test('Cannot reply if blocked', async () => {
|
|
await alice.client.request('blocking/create', { userId: bobInA.id });
|
|
await sleep();
|
|
|
|
const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
await rejects(
|
|
async () => await bob.client.request('notes/create', { text: 'b', replyId: resolvedNote.id }),
|
|
(err: any) => {
|
|
strictEqual(err.code, 'YOU_HAVE_BEEN_BLOCKED');
|
|
return true;
|
|
},
|
|
);
|
|
});
|
|
|
|
test('Can reply if unblocked', async () => {
|
|
await alice.client.request('blocking/delete', { userId: bobInA.id });
|
|
await sleep();
|
|
|
|
const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
const reply = (await bob.client.request('notes/create', { text: 'b', replyId: resolvedNote.id })).createdNote;
|
|
|
|
await resolveRemoteNote('b.test', reply.id, alice);
|
|
});
|
|
});
|
|
|
|
describe('Check reaction', () => {
|
|
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),
|
|
]);
|
|
});
|
|
|
|
test('Cannot reaction if blocked', async () => {
|
|
await alice.client.request('blocking/create', { userId: bobInA.id });
|
|
await sleep();
|
|
|
|
const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
await rejects(
|
|
async () => await bob.client.request('notes/reactions/create', { noteId: resolvedNote.id, reaction: '😅' }),
|
|
(err: any) => {
|
|
strictEqual(err.code, 'YOU_HAVE_BEEN_BLOCKED');
|
|
return true;
|
|
},
|
|
);
|
|
});
|
|
|
|
// FIXME: this is invalid case
|
|
test('Cannot reaction even if unblocked', async () => {
|
|
// unblock here
|
|
await alice.client.request('blocking/delete', { userId: bobInA.id });
|
|
await sleep();
|
|
|
|
const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
|
|
// TODO: why still being blocked?
|
|
await rejects(
|
|
async () => await bob.client.request('notes/reactions/create', { noteId: resolvedNote.id, reaction: '😅' }),
|
|
(err: any) => {
|
|
strictEqual(err.code, 'YOU_HAVE_BEEN_BLOCKED');
|
|
return true;
|
|
},
|
|
);
|
|
});
|
|
|
|
test.skip('Can reaction if unblocked', async () => {
|
|
await alice.client.request('blocking/delete', { userId: bobInA.id });
|
|
await sleep();
|
|
|
|
const note = (await alice.client.request('notes/create', { text: 'a' })).createdNote;
|
|
const resolvedNote = await resolveRemoteNote('a.test', note.id, bob);
|
|
await bob.client.request('notes/reactions/create', { noteId: resolvedNote.id, reaction: '😅' });
|
|
|
|
const _note = await alice.client.request('notes/show', { noteId: note.id });
|
|
deepStrictEqual(_note.reactions, { '😅': 1 });
|
|
});
|
|
});
|
|
|
|
describe('Check mention', () => {
|
|
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),
|
|
]);
|
|
});
|
|
|
|
/** NOTE: You should mute the target to stop receiving notifications */
|
|
test('Can mention and notified even if blocked', async () => {
|
|
await alice.client.request('blocking/create', { userId: bobInA.id });
|
|
await sleep();
|
|
|
|
const text = `@${alice.username}@a.test plz unblock me!`;
|
|
await assertNotificationReceived(
|
|
'a.test', alice,
|
|
async () => await bob.client.request('notes/create', { text }),
|
|
notification => notification.type === 'mention' && notification.userId === bobInA.id && notification.note.text === text,
|
|
true,
|
|
);
|
|
});
|
|
});
|
|
});
|