update test
This commit is contained in:
parent
399e527cc2
commit
f50364b100
|
@ -9,8 +9,8 @@
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import { setTimeout } from 'node:timers/promises';
|
import { setTimeout } from 'node:timers/promises';
|
||||||
import { Redis } from 'ioredis';
|
import { Redis } from 'ioredis';
|
||||||
import { SignupResponse, Role, Note } from 'misskey-js/entities.js';
|
import { SignupResponse, Note, UserList } from 'misskey-js/entities.js';
|
||||||
import { api, post, randomString, sendEnvUpdateRequest, signup, uploadUrl, role } from '../utils.js';
|
import { api, post, randomString, sendEnvUpdateRequest, signup, uploadUrl } from '../utils.js';
|
||||||
import { loadConfig } from '@/config.js';
|
import { loadConfig } from '@/config.js';
|
||||||
|
|
||||||
function genHost() {
|
function genHost() {
|
||||||
|
@ -667,12 +667,12 @@ describe('Timelines', () => {
|
||||||
carolNote = await post(carol, { text: 'kon\'nichiwa' });
|
carolNote = await post(carol, { text: 'kon\'nichiwa' });
|
||||||
|
|
||||||
await waitForPushToTl();
|
await waitForPushToTl();
|
||||||
|
|
||||||
|
await api('admin/suspend-user', { userId: carol.id }, root);
|
||||||
|
await setTimeout(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('凍結後に凍結されたユーザーのノートは見えなくなる', async () => {
|
test('凍結後に凍結されたユーザーのノートは見えなくなる', async () => {
|
||||||
await api('admin/suspend-user', { userId: carol.id }, root);
|
|
||||||
await setTimeout(100);
|
|
||||||
|
|
||||||
const res = await api('notes/timeline', { limit: 100 }, alice);
|
const res = await api('notes/timeline', { limit: 100 }, alice);
|
||||||
assert.strictEqual(res.body.length, 2);
|
assert.strictEqual(res.body.length, 2);
|
||||||
assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true);
|
assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true);
|
||||||
|
@ -709,12 +709,12 @@ describe('Timelines', () => {
|
||||||
carolNote = await post(carol, { text: 'kon\'nichiwa' });
|
carolNote = await post(carol, { text: 'kon\'nichiwa' });
|
||||||
|
|
||||||
await waitForPushToTl();
|
await waitForPushToTl();
|
||||||
|
|
||||||
|
await api('admin/suspend-user', { userId: carol.id }, root);
|
||||||
|
await setTimeout(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('凍結後に凍結されたユーザーのノートは見えなくなる', async () => {
|
test('凍結後に凍結されたユーザーのノートは見えなくなる', async () => {
|
||||||
await api('admin/suspend-user', { userId: carol.id }, root);
|
|
||||||
await setTimeout(100);
|
|
||||||
|
|
||||||
const res = await api('notes/timeline', { limit: 100 }, alice);
|
const res = await api('notes/timeline', { limit: 100 }, alice);
|
||||||
assert.strictEqual(res.body.length, 2);
|
assert.strictEqual(res.body.length, 2);
|
||||||
assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true);
|
assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true);
|
||||||
|
@ -1253,14 +1253,14 @@ describe('Timelines', () => {
|
||||||
await api('following/create', { userId: elle.id }, alice);
|
await api('following/create', { userId: elle.id }, alice);
|
||||||
|
|
||||||
await waitForPushToTl();
|
await waitForPushToTl();
|
||||||
});
|
|
||||||
|
|
||||||
test('凍結後に凍結されたユーザーのノートは見えなくなる', async () => {
|
|
||||||
await api('admin/suspend-user', { userId: carol.id }, root);
|
await api('admin/suspend-user', { userId: carol.id }, root);
|
||||||
await api('admin/suspend-user', { userId: dave.id }, root);
|
await api('admin/suspend-user', { userId: dave.id }, root);
|
||||||
await api('admin/suspend-user', { userId: elle.id }, root);
|
await api('admin/suspend-user', { userId: elle.id }, root);
|
||||||
await setTimeout(250);
|
await setTimeout(250);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('凍結後に凍結されたユーザーのノートは見えなくなる', async () => {
|
||||||
const res = await api('notes/hybrid-timeline', { limit: 100 }, alice);
|
const res = await api('notes/hybrid-timeline', { limit: 100 }, alice);
|
||||||
|
|
||||||
assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true);
|
assert.strictEqual(res.body.some(note => note.id === aliceNote.id), true);
|
||||||
|
@ -1531,27 +1531,48 @@ describe('Timelines', () => {
|
||||||
assert.strictEqual(res.body.some(note => note.id === bobNote.id), false);
|
assert.strictEqual(res.body.some(note => note.id === bobNote.id), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('凍結: 凍結後に凍結されたユーザーのノートは見えなくなる', async () => {
|
|
||||||
const [alice, bob, carol] = await Promise.all([signup(), signup(), signup()]);
|
|
||||||
|
|
||||||
const list = await api('users/lists/create', { name: 'list' }, alice).then(res => res.body);
|
describe('凍結', () => {
|
||||||
|
let alice: SignupResponse, bob: SignupResponse, carol: SignupResponse;
|
||||||
|
let aliceNote: Note, bobNote: Note, carolNote: Note;
|
||||||
|
let list: UserList;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
[alice, bob, carol] = await Promise.all([signup(), signup(), signup()]);
|
||||||
|
|
||||||
|
list = await api('users/lists/create', { name: 'list' }, alice).then(res => res.body);
|
||||||
await api('users/lists/push', { listId: list.id, userId: bob.id }, alice);
|
await api('users/lists/push', { listId: list.id, userId: bob.id }, alice);
|
||||||
await api('users/lists/push', { listId: list.id, userId: carol.id }, alice);
|
await api('users/lists/push', { listId: list.id, userId: carol.id }, alice);
|
||||||
const aliceNote = await post(alice, { text: 'hi' });
|
|
||||||
const bobNote = await post(bob, { text: 'yo' });
|
aliceNote = await post(alice, { text: 'hi' });
|
||||||
const carolNote = await post(carol, { text: 'kon\'nichiwa' });
|
bobNote = await post(bob, { text: 'yo' });
|
||||||
|
carolNote = await post(carol, { text: 'kon\'nichiwa' });
|
||||||
|
|
||||||
await waitForPushToTl();
|
await waitForPushToTl();
|
||||||
|
|
||||||
await api('admin/suspend-user', { userId: carol.id }, root);
|
await api('admin/suspend-user', { userId: carol.id }, root);
|
||||||
|
await setTimeout(100);
|
||||||
|
});
|
||||||
|
|
||||||
await setTimeout(250);
|
test('凍結後に凍結されたユーザーのノートは見えなくなる', async () => {
|
||||||
|
|
||||||
const res = await api('notes/user-list-timeline', { listId: list.id }, alice);
|
const res = await api('notes/user-list-timeline', { listId: list.id }, alice);
|
||||||
assert.strictEqual(res.body.length, 1);
|
|
||||||
|
assert.strictEqual(res.body.some(note => note.id === aliceNote.id), false);
|
||||||
assert.strictEqual(res.body.some(note => note.id === bobNote.id), true);
|
assert.strictEqual(res.body.some(note => note.id === bobNote.id), true);
|
||||||
assert.strictEqual(res.body.some(note => note.id === carolNote.id), false);
|
assert.strictEqual(res.body.some(note => note.id === carolNote.id), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('凍結解除後に凍結されていたユーザーのノートは見えるようになる', async () => {
|
||||||
|
await api('admin/unsuspend-user', { userId: carol.id }, root);
|
||||||
|
await setTimeout(100);
|
||||||
|
|
||||||
|
const res = await api('notes/user-list-timeline', { listId: list.id }, alice);
|
||||||
|
|
||||||
|
assert.strictEqual(res.body.some(note => note.id === aliceNote.id), false);
|
||||||
|
assert.strictEqual(res.body.some(note => note.id === bobNote.id), true);
|
||||||
|
assert.strictEqual(res.body.some(note => note.id === carolNote.id), true);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('User TL', () => {
|
describe('User TL', () => {
|
||||||
|
|
|
@ -25,6 +25,11 @@ import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
|
||||||
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
||||||
import { secureRndstr } from '@/misc/secure-rndstr.js';
|
import { secureRndstr } from '@/misc/secure-rndstr.js';
|
||||||
|
import { randomString } from '../utils.js';
|
||||||
|
|
||||||
|
function genHost() {
|
||||||
|
return randomString() + '.example.com';
|
||||||
|
}
|
||||||
|
|
||||||
describe('UserSuspendService', () => {
|
describe('UserSuspendService', () => {
|
||||||
let app: TestingModule;
|
let app: TestingModule;
|
||||||
|
@ -359,4 +364,53 @@ describe('UserSuspendService', () => {
|
||||||
expect(queueService.deliver).not.toHaveBeenCalled();
|
expect(queueService.deliver).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('remote user suspension', () => {
|
||||||
|
test('should suspend remote user without AP delivery', async () => {
|
||||||
|
const remoteUser = await createUser({ host: genHost() });
|
||||||
|
const moderator = await createUser();
|
||||||
|
|
||||||
|
await userSuspendService.suspend(remoteUser, moderator);
|
||||||
|
await setTimeout(250);
|
||||||
|
|
||||||
|
// ユーザーが凍結されているかチェック
|
||||||
|
const suspendedUser = await usersRepository.findOneBy({ id: remoteUser.id });
|
||||||
|
expect(suspendedUser?.isSuspended).toBe(true);
|
||||||
|
|
||||||
|
// モデレーションログが記録されているかチェック
|
||||||
|
expect(moderationLogService.log).toHaveBeenCalledWith(moderator, 'suspend', {
|
||||||
|
userId: remoteUser.id,
|
||||||
|
userUsername: remoteUser.username,
|
||||||
|
userHost: remoteUser.host,
|
||||||
|
});
|
||||||
|
|
||||||
|
// ActivityPub配信が呼ばれていないことを確認
|
||||||
|
expect(queueService.deliver).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('remote user unsuspension', () => {
|
||||||
|
test('should unsuspend remote user without AP delivery', async () => {
|
||||||
|
const remoteUser = await createUser({ host: genHost(), isSuspended: true });
|
||||||
|
const moderator = await createUser();
|
||||||
|
|
||||||
|
await userSuspendService.unsuspend(remoteUser, moderator);
|
||||||
|
|
||||||
|
await setTimeout(250);
|
||||||
|
|
||||||
|
// ユーザーの凍結が解除されているかチェック
|
||||||
|
const unsuspendedUser = await usersRepository.findOneBy({ id: remoteUser.id });
|
||||||
|
expect(unsuspendedUser?.isSuspended).toBe(false);
|
||||||
|
|
||||||
|
// モデレーションログが記録されているかチェック
|
||||||
|
expect(moderationLogService.log).toHaveBeenCalledWith(moderator, 'unsuspend', {
|
||||||
|
userId: remoteUser.id,
|
||||||
|
userUsername: remoteUser.username,
|
||||||
|
userHost: remoteUser.host,
|
||||||
|
});
|
||||||
|
|
||||||
|
// ActivityPub配信が呼ばれていないことを確認
|
||||||
|
expect(queueService.deliver).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue