Merge remote-tracking branch 'misskey-dev/develop' into io

This commit is contained in:
まっちゃとーにゅ 2024-04-29 04:41:23 +09:00
commit fd696a9621
No known key found for this signature in database
GPG key ID: 6AFBBF529601C1DB
113 changed files with 2272 additions and 443 deletions

View file

@ -8,12 +8,13 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert';
import { MiNote } from '@/models/Note.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import { api, initTestDb, post, sendEnvUpdateRequest, signup, uploadFile, uploadUrl } from '../utils.js';
import { api, initTestDb, post, role, sendEnvUpdateRequest, signup, uploadFile, uploadUrl } from '../utils.js';
import type * as misskey from 'misskey-js';
describe('Note', () => {
let Notes: any;
let root: misskey.entities.SignupResponse;
let alice: misskey.entities.SignupResponse;
let bob: misskey.entities.SignupResponse;
let tom: misskey.entities.SignupResponse;
@ -23,6 +24,7 @@ describe('Note', () => {
const connection = await initTestDb(true);
Notes = connection.getRepository(MiNote);
root = await signup({ username: 'root' });
alice = await signup({ username: 'alice' });
bob = await signup({ username: 'bob' });
tom = await signup({ username: 'tom', host: 'example.com' });
@ -476,14 +478,14 @@ describe('Note', () => {
value: true,
},
} as FIXME,
}, alice);
}, root);
assert.strictEqual(res.status, 200);
const assign = await api('admin/roles/assign', {
userId: alice.id,
roleId: res.body.id,
}, alice);
}, root);
assert.strictEqual(assign.status, 204);
assert.strictEqual(file.body!.isSensitive, false);
@ -511,11 +513,11 @@ describe('Note', () => {
await api('admin/roles/unassign', {
userId: alice.id,
roleId: res.body.id,
});
}, root);
await api('admin/roles/delete', {
roleId: res.body.id,
}, alice);
}, root);
});
});
@ -647,7 +649,7 @@ describe('Note', () => {
sensitiveWords: [
'test',
],
}, alice);
}, root);
assert.strictEqual(sensitive.status, 204);
@ -666,7 +668,7 @@ describe('Note', () => {
sensitiveWords: [
'/Test/i',
],
}, alice);
}, root);
assert.strictEqual(sensitive.status, 204);
@ -683,7 +685,7 @@ describe('Note', () => {
sensitiveWords: [
'Test hoge',
],
}, alice);
}, root);
assert.strictEqual(sensitive.status, 204);
@ -700,7 +702,7 @@ describe('Note', () => {
prohibitedWords: [
'test',
],
}, alice);
}, root);
assert.strictEqual(prohibited.status, 204);
@ -719,7 +721,7 @@ describe('Note', () => {
prohibitedWords: [
'/Test/i',
],
}, alice);
}, root);
assert.strictEqual(prohibited.status, 204);
@ -736,7 +738,7 @@ describe('Note', () => {
prohibitedWords: [
'Test hoge',
],
}, alice);
}, root);
assert.strictEqual(prohibited.status, 204);
@ -753,7 +755,7 @@ describe('Note', () => {
prohibitedWords: [
'test',
],
}, alice);
}, root);
assert.strictEqual(prohibited.status, 204);
@ -790,7 +792,7 @@ describe('Note', () => {
value: 0,
},
} as FIXME,
}, alice);
}, root);
assert.strictEqual(res.status, 200);
@ -799,7 +801,7 @@ describe('Note', () => {
const assign = await api('admin/roles/assign', {
userId: alice.id,
roleId: res.body.id,
}, alice);
}, root);
assert.strictEqual(assign.status, 204);
@ -815,11 +817,11 @@ describe('Note', () => {
await api('admin/roles/unassign', {
userId: alice.id,
roleId: res.body.id,
});
}, root);
await api('admin/roles/delete', {
roleId: res.body.id,
}, alice);
}, root);
});
test('ダイレクト投稿もエラーになる', async () => {
@ -845,7 +847,7 @@ describe('Note', () => {
value: 0,
},
} as FIXME,
}, alice);
}, root);
assert.strictEqual(res.status, 200);
@ -854,7 +856,7 @@ describe('Note', () => {
const assign = await api('admin/roles/assign', {
userId: alice.id,
roleId: res.body.id,
}, alice);
}, root);
assert.strictEqual(assign.status, 204);
@ -872,11 +874,11 @@ describe('Note', () => {
await api('admin/roles/unassign', {
userId: alice.id,
roleId: res.body.id,
});
}, root);
await api('admin/roles/delete', {
roleId: res.body.id,
}, alice);
}, root);
});
test('ダイレクトの宛先とメンションが同じ場合は重複してカウントしない', async () => {
@ -902,7 +904,7 @@ describe('Note', () => {
value: 1,
},
} as FIXME,
}, alice);
}, root);
assert.strictEqual(res.status, 200);
@ -911,7 +913,7 @@ describe('Note', () => {
const assign = await api('admin/roles/assign', {
userId: alice.id,
roleId: res.body.id,
}, alice);
}, root);
assert.strictEqual(assign.status, 204);
@ -928,11 +930,11 @@ describe('Note', () => {
await api('admin/roles/unassign', {
userId: alice.id,
roleId: res.body.id,
});
}, root);
await api('admin/roles/delete', {
roleId: res.body.id,
}, alice);
}, root);
});
});
@ -967,4 +969,61 @@ describe('Note', () => {
assert.strictEqual(mainNote.repliesCount, 0);
});
});
describe('notes/translate', () => {
describe('翻訳機能の利用が許可されていない場合', () => {
let cannotTranslateRole: misskey.entities.Role;
beforeAll(async () => {
cannotTranslateRole = await role(root, {}, { canUseTranslator: false });
await api('admin/roles/assign', { roleId: cannotTranslateRole.id, userId: alice.id }, root);
});
test('翻訳機能の利用が許可されていない場合翻訳できない', async () => {
const aliceNote = await post(alice, { text: 'Hello' });
const res = await api('notes/translate', {
noteId: aliceNote.id,
targetLang: 'ja',
}, alice);
assert.strictEqual(res.status, 400);
assert.strictEqual(res.body.error.code, 'UNAVAILABLE');
});
afterAll(async () => {
await api('admin/roles/unassign', { roleId: cannotTranslateRole.id, userId: alice.id }, root);
});
});
test('存在しないノートは翻訳できない', async () => {
const res = await api('notes/translate', { noteId: 'foo', targetLang: 'ja' }, alice);
assert.strictEqual(res.status, 400);
assert.strictEqual(res.body.error.code, 'NO_SUCH_NOTE');
});
test('不可視なノートは翻訳できない', async () => {
const aliceNote = await post(alice, { visibility: 'followers', text: 'Hello' });
const bobTranslateAttempt = await api('notes/translate', { noteId: aliceNote.id, targetLang: 'ja' }, bob);
assert.strictEqual(bobTranslateAttempt.status, 400);
assert.strictEqual(bobTranslateAttempt.body.error.code, 'CANNOT_TRANSLATE_INVISIBLE_NOTE');
});
test('text: null なノートを翻訳すると空のレスポンスが返ってくる', async () => {
const aliceNote = await post(alice, { text: null, poll: { choices: ['kinoko', 'takenoko'] } });
const res = await api('notes/translate', { noteId: aliceNote.id, targetLang: 'ja' }, alice);
assert.strictEqual(res.status, 204);
});
test('サーバーに DeepL 認証キーが登録されていない場合翻訳できない', async () => {
const aliceNote = await post(alice, { text: 'Hello' });
const res = await api('notes/translate', { noteId: aliceNote.id, targetLang: 'ja' }, alice);
// NOTE: デフォルトでは登録されていないので落ちる
assert.strictEqual(res.status, 400);
assert.strictEqual(res.body.error.code, 'UNAVAILABLE');
});
});
});