2023-07-27 08:31:52 +03:00
|
|
|
|
/*
|
2024-02-13 17:59:27 +02:00
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 08:31:52 +03:00
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2019-04-07 15:50:36 +03:00
|
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
2023-09-20 05:33:36 +03:00
|
|
|
|
import { MiNote } from '@/models/Note.js';
|
2023-07-27 08:31:52 +03:00
|
|
|
|
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
|
2024-01-08 10:43:52 +02:00
|
|
|
|
import { api, initTestDb, post, signup, uploadFile, uploadUrl } from '../utils.js';
|
2023-06-25 02:34:18 +03:00
|
|
|
|
import type * as misskey from 'misskey-js';
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
|
|
|
|
describe('Note', () => {
|
|
|
|
|
let Notes: any;
|
|
|
|
|
|
2024-01-03 06:41:28 +02:00
|
|
|
|
let alice: misskey.entities.SignupResponse;
|
|
|
|
|
let bob: misskey.entities.SignupResponse;
|
2024-02-09 03:07:18 +02:00
|
|
|
|
let tom: misskey.entities.SignupResponse;
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
|
beforeAll(async () => {
|
2021-06-12 16:40:17 +03:00
|
|
|
|
const connection = await initTestDb(true);
|
2023-08-16 11:51:28 +03:00
|
|
|
|
Notes = connection.getRepository(MiNote);
|
2020-01-09 07:35:04 +02:00
|
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
|
bob = await signup({ username: 'bob' });
|
2024-02-09 03:07:18 +02:00
|
|
|
|
tom = await signup({ username: 'tom', host: 'example.com' });
|
2023-03-03 04:13:12 +02:00
|
|
|
|
}, 1000 * 60 * 2);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('投稿できる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const post = {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
text: 'test',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', post, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.text, post.text);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('ファイルを添付できる', async () => {
|
2022-06-26 13:16:32 +03:00
|
|
|
|
const file = await uploadUrl(alice, 'https://raw.githubusercontent.com/misskey-dev/misskey/develop/packages/backend/test/resources/Lenna.jpg');
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
fileIds: [file.id],
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
|
assert.deepStrictEqual(res.body.createdNote.fileIds, [file.id]);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}, 1000 * 10);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-03-03 04:13:12 +02:00
|
|
|
|
test('他人のファイルで怒られる', async () => {
|
2022-06-26 13:16:32 +03:00
|
|
|
|
const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/misskey/develop/packages/backend/test/resources/Lenna.jpg');
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
text: 'test',
|
2022-05-21 16:21:41 +03:00
|
|
|
|
fileIds: [file.id],
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
2023-03-03 04:13:12 +02:00
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
|
assert.strictEqual(res.body.error.code, 'NO_SUCH_FILE');
|
|
|
|
|
assert.strictEqual(res.body.error.id, 'b6992544-63e7-67f0-fa7f-32444b1b5306');
|
2022-09-17 21:27:08 +03:00
|
|
|
|
}, 1000 * 10);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-03-03 04:13:12 +02:00
|
|
|
|
test('存在しないファイルで怒られる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
text: 'test',
|
2022-05-21 16:21:41 +03:00
|
|
|
|
fileIds: ['000000000000000000000000'],
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
2023-03-03 04:13:12 +02:00
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
|
assert.strictEqual(res.body.error.code, 'NO_SUCH_FILE');
|
|
|
|
|
assert.strictEqual(res.body.error.id, 'b6992544-63e7-67f0-fa7f-32444b1b5306');
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-03-03 04:13:12 +02:00
|
|
|
|
test('不正なファイルIDで怒られる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
fileIds: ['kyoppie'],
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
2023-03-03 04:13:12 +02:00
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
|
assert.strictEqual(res.body.error.code, 'NO_SUCH_FILE');
|
|
|
|
|
assert.strictEqual(res.body.error.id, 'b6992544-63e7-67f0-fa7f-32444b1b5306');
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('返信できる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const bobPost = await post(bob, {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
text: 'foo',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const alicePost = {
|
|
|
|
|
text: 'bar',
|
2022-05-21 16:21:41 +03:00
|
|
|
|
replyId: bobPost.id,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', alicePost, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.text, alicePost.text);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.replyId, alicePost.replyId);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.reply.text, bobPost.text);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('renoteできる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const bobPost = await post(bob, {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
text: 'test',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const alicePost = {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
renoteId: bobPost.id,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', alicePost, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.renoteId, alicePost.renoteId);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.renote.text, bobPost.text);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('引用renoteできる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const bobPost = await post(bob, {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
text: 'test',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const alicePost = {
|
|
|
|
|
text: 'test',
|
2022-05-21 16:21:41 +03:00
|
|
|
|
renoteId: bobPost.id,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', alicePost, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.text, alicePost.text);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.renoteId, alicePost.renoteId);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.renote.text, bobPost.text);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2024-01-13 09:54:25 +02:00
|
|
|
|
test('引用renoteで空白文字のみで構成されたtextにするとレスポンスがtext: nullになる', async () => {
|
|
|
|
|
const bobPost = await post(bob, {
|
|
|
|
|
text: 'test',
|
|
|
|
|
});
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
2024-01-13 09:54:25 +02:00
|
|
|
|
text: ' ',
|
|
|
|
|
renoteId: bobPost.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.text, null);
|
|
|
|
|
});
|
|
|
|
|
|
2023-03-12 05:11:37 +02:00
|
|
|
|
test('visibility: followersでrenoteできる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const createRes = await api('notes/create', {
|
2023-03-12 05:11:37 +02:00
|
|
|
|
text: 'test',
|
|
|
|
|
visibility: 'followers',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(createRes.status, 200);
|
|
|
|
|
|
|
|
|
|
const renoteId = createRes.body.createdNote.id;
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const renoteRes = await api('notes/create', {
|
2023-03-12 05:11:37 +02:00
|
|
|
|
visibility: 'followers',
|
|
|
|
|
renoteId,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(renoteRes.status, 200);
|
|
|
|
|
assert.strictEqual(renoteRes.body.createdNote.renoteId, renoteId);
|
|
|
|
|
assert.strictEqual(renoteRes.body.createdNote.visibility, 'followers');
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const deleteRes = await api('notes/delete', {
|
2023-03-12 05:11:37 +02:00
|
|
|
|
noteId: renoteRes.body.createdNote.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(deleteRes.status, 204);
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-29 13:42:02 +02:00
|
|
|
|
test('visibility: followersなノートに対してフォロワーはリプライできる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
await api('following/create', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
userId: alice.id,
|
|
|
|
|
}, bob);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const aliceNote = await api('notes/create', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
text: 'direct note to bob',
|
|
|
|
|
visibility: 'followers',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(aliceNote.status, 200);
|
|
|
|
|
|
|
|
|
|
const replyId = aliceNote.body.createdNote.id;
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const bobReply = await api('notes/create', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
text: 'reply to alice note',
|
|
|
|
|
replyId,
|
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(bobReply.status, 200);
|
|
|
|
|
assert.strictEqual(bobReply.body.createdNote.replyId, replyId);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
await api('following/delete', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
userId: alice.id,
|
|
|
|
|
}, bob);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('visibility: followersなノートに対してフォロワーでないユーザーがリプライしようとすると怒られる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const aliceNote = await api('notes/create', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
text: 'direct note to bob',
|
|
|
|
|
visibility: 'followers',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(aliceNote.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const bobReply = await api('notes/create', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
text: 'reply to alice note',
|
|
|
|
|
replyId: aliceNote.body.createdNote.id,
|
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(bobReply.status, 400);
|
|
|
|
|
assert.strictEqual(bobReply.body.error.code, 'CANNOT_REPLY_TO_AN_INVISIBLE_NOTE');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('visibility: specifiedなノートに対してvisibility: specifiedで返信できる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const aliceNote = await api('notes/create', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
text: 'direct note to bob',
|
|
|
|
|
visibility: 'specified',
|
|
|
|
|
visibleUserIds: [bob.id],
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(aliceNote.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const bobReply = await api('notes/create', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
text: 'reply to alice note',
|
|
|
|
|
replyId: aliceNote.body.createdNote.id,
|
|
|
|
|
visibility: 'specified',
|
|
|
|
|
visibleUserIds: [alice.id],
|
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(bobReply.status, 200);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('visibility: specifiedなノートに対してvisibility: follwersで返信しようとすると怒られる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const aliceNote = await api('notes/create', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
text: 'direct note to bob',
|
|
|
|
|
visibility: 'specified',
|
|
|
|
|
visibleUserIds: [bob.id],
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(aliceNote.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const bobReply = await api('notes/create', {
|
2024-02-29 13:42:02 +02:00
|
|
|
|
text: 'reply to alice note with visibility: followers',
|
|
|
|
|
replyId: aliceNote.body.createdNote.id,
|
|
|
|
|
visibility: 'followers',
|
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(bobReply.status, 400);
|
|
|
|
|
assert.strictEqual(bobReply.body.error.code, 'CANNOT_REPLY_TO_SPECIFIED_VISIBILITY_NOTE_WITH_EXTENDED_VISIBILITY');
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('文字数ぎりぎりで怒られない', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const post = {
|
2023-07-27 03:00:48 +03:00
|
|
|
|
text: '!'.repeat(MAX_NOTE_TEXT_LENGTH), // 3000文字
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', post, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
assert.strictEqual(res.status, 200);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('文字数オーバーで怒られる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const post = {
|
2023-07-27 03:00:48 +03:00
|
|
|
|
text: '!'.repeat(MAX_NOTE_TEXT_LENGTH + 1), // 3001文字
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', post, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('存在しないリプライ先で怒られる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const post = {
|
|
|
|
|
text: 'test',
|
2022-05-21 16:21:41 +03:00
|
|
|
|
replyId: '000000000000000000000000',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', post, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('存在しないrenote対象で怒られる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const post = {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
renoteId: '000000000000000000000000',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', post, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('不正なリプライ先IDで怒られる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const post = {
|
|
|
|
|
text: 'test',
|
2022-05-21 16:21:41 +03:00
|
|
|
|
replyId: 'foo',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', post, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('不正なrenote対象IDで怒られる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const post = {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
renoteId: 'foo',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', post, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('存在しないユーザーにメンションできる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const post = {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
text: '@ghost yo',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', post, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.text, post.text);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('同じユーザーに複数メンションしても内部的にまとめられる', async () => {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
const post = {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
text: '@bob @bob @bob yo',
|
2019-04-07 15:50:36 +03:00
|
|
|
|
};
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', post, alice);
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.text, post.text);
|
|
|
|
|
|
2022-06-26 13:16:32 +03:00
|
|
|
|
const noteDoc = await Notes.findOneBy({ id: res.body.createdNote.id });
|
2019-04-07 15:50:36 +03:00
|
|
|
|
assert.deepStrictEqual(noteDoc.mentions, [bob.id]);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-03-04 09:48:50 +02:00
|
|
|
|
describe('添付ファイル情報', () => {
|
|
|
|
|
test('ファイルを添付した場合、投稿成功時にファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
|
const file = await uploadFile(alice);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
|
|
|
|
fileIds: [file.body!.id],
|
2023-03-04 09:48:50 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.files.length, 1);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
assert.strictEqual(res.body.createdNote.files[0].id, file.body!.id);
|
2023-03-04 09:48:50 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('ファイルを添付した場合、タイムラインでファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
|
const file = await uploadFile(alice);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const createdNote = await api('notes/create', {
|
|
|
|
|
fileIds: [file.body!.id],
|
2023-03-04 09:48:50 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(createdNote.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes', {
|
2023-03-04 09:48:50 +02:00
|
|
|
|
withFiles: true,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
|
const myNote = res.body.find((note: { id: string; files: { id: string }[] }) => note.id === createdNote.body.createdNote.id);
|
|
|
|
|
assert.notEqual(myNote, null);
|
|
|
|
|
assert.strictEqual(myNote.files.length, 1);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
assert.strictEqual(myNote.files[0].id, file.body!.id);
|
2023-03-04 09:48:50 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('ファイルが添付されたノートをリノートした場合、タイムラインでファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
|
const file = await uploadFile(alice);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const createdNote = await api('notes/create', {
|
|
|
|
|
fileIds: [file.body!.id],
|
2023-03-04 09:48:50 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(createdNote.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const renoted = await api('notes/create', {
|
2023-03-04 09:48:50 +02:00
|
|
|
|
renoteId: createdNote.body.createdNote.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
assert.strictEqual(renoted.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes', {
|
2023-03-04 09:48:50 +02:00
|
|
|
|
renote: true,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
|
const myNote = res.body.find((note: { id: string }) => note.id === renoted.body.createdNote.id);
|
|
|
|
|
assert.notEqual(myNote, null);
|
|
|
|
|
assert.strictEqual(myNote.renote.files.length, 1);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
assert.strictEqual(myNote.renote.files[0].id, file.body!.id);
|
2023-03-04 09:48:50 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('ファイルが添付されたノートに返信した場合、タイムラインでファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
|
const file = await uploadFile(alice);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const createdNote = await api('notes/create', {
|
|
|
|
|
fileIds: [file.body!.id],
|
2023-03-04 09:48:50 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(createdNote.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const reply = await api('notes/create', {
|
2023-03-04 09:48:50 +02:00
|
|
|
|
replyId: createdNote.body.createdNote.id,
|
|
|
|
|
text: 'this is reply',
|
|
|
|
|
}, alice);
|
|
|
|
|
assert.strictEqual(reply.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes', {
|
2023-03-04 09:48:50 +02:00
|
|
|
|
reply: true,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
|
const myNote = res.body.find((note: { id: string }) => note.id === reply.body.createdNote.id);
|
|
|
|
|
assert.notEqual(myNote, null);
|
|
|
|
|
assert.strictEqual(myNote.reply.files.length, 1);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
assert.strictEqual(myNote.reply.files[0].id, file.body!.id);
|
2023-03-04 09:48:50 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('ファイルが添付されたノートへの返信をリノートした場合、タイムラインでファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
|
const file = await uploadFile(alice);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const createdNote = await api('notes/create', {
|
|
|
|
|
fileIds: [file.body!.id],
|
2023-03-04 09:48:50 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(createdNote.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const reply = await api('notes/create', {
|
2023-03-04 09:48:50 +02:00
|
|
|
|
replyId: createdNote.body.createdNote.id,
|
|
|
|
|
text: 'this is reply',
|
|
|
|
|
}, alice);
|
|
|
|
|
assert.strictEqual(reply.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const renoted = await api('notes/create', {
|
2023-03-04 09:48:50 +02:00
|
|
|
|
renoteId: reply.body.createdNote.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
assert.strictEqual(renoted.status, 200);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes', {
|
2023-03-04 09:48:50 +02:00
|
|
|
|
renote: true,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
|
const myNote = res.body.find((note: { id: string }) => note.id === renoted.body.createdNote.id);
|
|
|
|
|
assert.notEqual(myNote, null);
|
|
|
|
|
assert.strictEqual(myNote.renote.reply.files.length, 1);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
assert.strictEqual(myNote.renote.reply.files[0].id, file.body!.id);
|
2023-03-04 09:48:50 +02:00
|
|
|
|
});
|
2023-05-05 08:18:06 +03:00
|
|
|
|
|
|
|
|
|
test('NSFWが強制されている場合変更できない', async () => {
|
|
|
|
|
const file = await uploadFile(alice);
|
|
|
|
|
|
|
|
|
|
const res = await api('admin/roles/create', {
|
|
|
|
|
name: 'test',
|
|
|
|
|
description: '',
|
|
|
|
|
color: null,
|
|
|
|
|
iconUrl: null,
|
|
|
|
|
displayOrder: 0,
|
|
|
|
|
target: 'manual',
|
|
|
|
|
condFormula: {},
|
|
|
|
|
isAdministrator: false,
|
|
|
|
|
isModerator: false,
|
|
|
|
|
isPublic: false,
|
|
|
|
|
isExplorable: false,
|
|
|
|
|
asBadge: false,
|
|
|
|
|
canEditMembersByModerator: false,
|
|
|
|
|
policies: {
|
|
|
|
|
alwaysMarkNsfw: {
|
|
|
|
|
useDefault: false,
|
|
|
|
|
priority: 0,
|
|
|
|
|
value: true,
|
|
|
|
|
},
|
2024-03-07 02:51:57 +02:00
|
|
|
|
} as any,
|
2023-05-05 08:18:06 +03:00
|
|
|
|
}, alice);
|
2023-06-25 02:34:18 +03:00
|
|
|
|
|
2023-05-05 08:18:06 +03:00
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
|
|
|
|
|
const assign = await api('admin/roles/assign', {
|
|
|
|
|
userId: alice.id,
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(assign.status, 204);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
assert.strictEqual(file.body!.isSensitive, false);
|
2023-05-05 08:18:06 +03:00
|
|
|
|
|
|
|
|
|
const nsfwfile = await uploadFile(alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(nsfwfile.status, 200);
|
2024-03-03 13:15:35 +02:00
|
|
|
|
assert.strictEqual(nsfwfile.body!.isSensitive, true);
|
2023-05-05 08:18:06 +03:00
|
|
|
|
|
|
|
|
|
const liftnsfw = await api('drive/files/update', {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
fileId: nsfwfile.body!.id,
|
2023-05-05 08:18:06 +03:00
|
|
|
|
isSensitive: false,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(liftnsfw.status, 400);
|
|
|
|
|
assert.strictEqual(liftnsfw.body.error.code, 'RESTRICTED_BY_ROLE');
|
|
|
|
|
|
|
|
|
|
const oldaddnsfw = await api('drive/files/update', {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
fileId: file.body!.id,
|
2023-05-05 08:18:06 +03:00
|
|
|
|
isSensitive: true,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(oldaddnsfw.status, 200);
|
|
|
|
|
|
|
|
|
|
await api('admin/roles/unassign', {
|
|
|
|
|
userId: alice.id,
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await api('admin/roles/delete', {
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
});
|
2023-03-04 09:48:50 +02:00
|
|
|
|
});
|
|
|
|
|
|
2019-04-07 15:50:36 +03:00
|
|
|
|
describe('notes/create', () => {
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('投票を添付できる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
text: 'test',
|
|
|
|
|
poll: {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choices: ['foo', 'bar'],
|
|
|
|
|
},
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
|
assert.strictEqual(res.body.createdNote.poll != null, true);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('投票の選択肢が無くて怒られる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
|
|
|
|
// @ts-expect-error poll must not be empty
|
2022-05-21 16:21:41 +03:00
|
|
|
|
poll: {},
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('投票の選択肢が無くて怒られる (空の配列)', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
poll: {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choices: [],
|
|
|
|
|
},
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('投票の選択肢が1つで怒られる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/create', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
poll: {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choices: ['Strawberry Pasta'],
|
|
|
|
|
},
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('投票できる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const { body } = await api('notes/create', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
text: 'test',
|
|
|
|
|
poll: {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choices: ['sakura', 'izumi', 'ako'],
|
|
|
|
|
},
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/polls/vote', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choice: 1,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('複数投票できない', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const { body } = await api('notes/create', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
text: 'test',
|
|
|
|
|
poll: {
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choices: ['sakura', 'izumi', 'ako'],
|
|
|
|
|
},
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
await api('notes/polls/vote', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choice: 0,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/polls/vote', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choice: 2,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('許可されている場合は複数投票できる', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const { body } = await api('notes/create', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
text: 'test',
|
|
|
|
|
poll: {
|
|
|
|
|
choices: ['sakura', 'izumi', 'ako'],
|
2022-05-21 16:21:41 +03:00
|
|
|
|
multiple: true,
|
|
|
|
|
},
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
await api('notes/polls/vote', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choice: 0,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
await api('notes/polls/vote', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choice: 1,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/polls/vote', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choice: 2,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('締め切られている場合は投票できない', async () => {
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const { body } = await api('notes/create', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
text: 'test',
|
|
|
|
|
poll: {
|
|
|
|
|
choices: ['sakura', 'izumi', 'ako'],
|
2022-05-21 16:21:41 +03:00
|
|
|
|
expiredAfter: 1,
|
|
|
|
|
},
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const res = await api('notes/polls/vote', {
|
2019-04-07 15:50:36 +03:00
|
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 16:21:41 +03:00
|
|
|
|
choice: 1,
|
2019-04-07 15:50:36 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2023-05-10 12:02:41 +03:00
|
|
|
|
|
|
|
|
|
test('センシティブな投稿はhomeになる (単語指定)', async () => {
|
|
|
|
|
const sensitive = await api('admin/update-meta', {
|
|
|
|
|
sensitiveWords: [
|
2023-07-27 08:31:52 +03:00
|
|
|
|
'test',
|
|
|
|
|
],
|
2023-05-10 12:02:41 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(sensitive.status, 204);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note1 = await api('notes/create', {
|
2023-05-10 12:02:41 +03:00
|
|
|
|
text: 'hogetesthuge',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(note1.status, 200);
|
|
|
|
|
assert.strictEqual(note1.body.createdNote.visibility, 'home');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('センシティブな投稿はhomeになる (正規表現)', async () => {
|
|
|
|
|
const sensitive = await api('admin/update-meta', {
|
|
|
|
|
sensitiveWords: [
|
2023-07-27 08:31:52 +03:00
|
|
|
|
'/Test/i',
|
|
|
|
|
],
|
2023-05-10 12:02:41 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(sensitive.status, 204);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note2 = await api('notes/create', {
|
2023-05-10 12:02:41 +03:00
|
|
|
|
text: 'hogetesthuge',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(note2.status, 200);
|
|
|
|
|
assert.strictEqual(note2.body.createdNote.visibility, 'home');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('センシティブな投稿はhomeになる (スペースアンド)', async () => {
|
|
|
|
|
const sensitive = await api('admin/update-meta', {
|
|
|
|
|
sensitiveWords: [
|
2023-07-27 08:31:52 +03:00
|
|
|
|
'Test hoge',
|
|
|
|
|
],
|
2023-05-10 12:02:41 +03:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(sensitive.status, 204);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note2 = await api('notes/create', {
|
2023-05-10 12:02:41 +03:00
|
|
|
|
text: 'hogeTesthuge',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(note2.status, 200);
|
|
|
|
|
assert.strictEqual(note2.body.createdNote.visibility, 'home');
|
|
|
|
|
});
|
2024-02-09 03:07:18 +02:00
|
|
|
|
|
|
|
|
|
test('禁止ワードを含む投稿はエラーになる (単語指定)', async () => {
|
|
|
|
|
const prohibited = await api('admin/update-meta', {
|
|
|
|
|
prohibitedWords: [
|
|
|
|
|
'test',
|
|
|
|
|
],
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(prohibited.status, 204);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note1 = await api('notes/create', {
|
2024-02-09 03:07:18 +02:00
|
|
|
|
text: 'hogetesthuge',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(note1.status, 400);
|
|
|
|
|
assert.strictEqual(note1.body.error.code, 'CONTAINS_PROHIBITED_WORDS');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('禁止ワードを含む投稿はエラーになる (正規表現)', async () => {
|
|
|
|
|
const prohibited = await api('admin/update-meta', {
|
|
|
|
|
prohibitedWords: [
|
|
|
|
|
'/Test/i',
|
|
|
|
|
],
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(prohibited.status, 204);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note2 = await api('notes/create', {
|
2024-02-09 03:07:18 +02:00
|
|
|
|
text: 'hogetesthuge',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(note2.status, 400);
|
|
|
|
|
assert.strictEqual(note2.body.error.code, 'CONTAINS_PROHIBITED_WORDS');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('禁止ワードを含む投稿はエラーになる (スペースアンド)', async () => {
|
|
|
|
|
const prohibited = await api('admin/update-meta', {
|
|
|
|
|
prohibitedWords: [
|
|
|
|
|
'Test hoge',
|
|
|
|
|
],
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(prohibited.status, 204);
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note2 = await api('notes/create', {
|
2024-02-09 03:07:18 +02:00
|
|
|
|
text: 'hogeTesthuge',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(note2.status, 400);
|
|
|
|
|
assert.strictEqual(note2.body.error.code, 'CONTAINS_PROHIBITED_WORDS');
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-12 21:54:01 +02:00
|
|
|
|
test('禁止ワードを含んでるリモートノートもエラーになる', async () => {
|
2024-02-09 03:07:18 +02:00
|
|
|
|
const prohibited = await api('admin/update-meta', {
|
|
|
|
|
prohibitedWords: [
|
|
|
|
|
'test',
|
|
|
|
|
],
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(prohibited.status, 204);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note1 = await api('notes/create', {
|
2024-02-09 03:07:18 +02:00
|
|
|
|
text: 'hogetesthuge',
|
|
|
|
|
}, tom);
|
|
|
|
|
|
2024-02-12 21:54:01 +02:00
|
|
|
|
assert.strictEqual(note1.status, 400);
|
2024-02-09 03:07:18 +02:00
|
|
|
|
});
|
2024-02-29 13:48:02 +02:00
|
|
|
|
|
|
|
|
|
test('メンションの数が上限を超えるとエラーになる', async () => {
|
|
|
|
|
const res = await api('admin/roles/create', {
|
|
|
|
|
name: 'test',
|
|
|
|
|
description: '',
|
|
|
|
|
color: null,
|
|
|
|
|
iconUrl: null,
|
|
|
|
|
displayOrder: 0,
|
|
|
|
|
target: 'manual',
|
|
|
|
|
condFormula: {},
|
|
|
|
|
isAdministrator: false,
|
|
|
|
|
isModerator: false,
|
|
|
|
|
isPublic: false,
|
|
|
|
|
isExplorable: false,
|
|
|
|
|
asBadge: false,
|
|
|
|
|
canEditMembersByModerator: false,
|
|
|
|
|
policies: {
|
|
|
|
|
mentionLimit: {
|
|
|
|
|
useDefault: false,
|
|
|
|
|
priority: 1,
|
|
|
|
|
value: 0,
|
|
|
|
|
},
|
2024-03-07 02:51:57 +02:00
|
|
|
|
} as any,
|
2024-02-29 13:48:02 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
|
|
|
|
const assign = await api('admin/roles/assign', {
|
|
|
|
|
userId: alice.id,
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(assign.status, 204);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note = await api('notes/create', {
|
2024-02-29 13:48:02 +02:00
|
|
|
|
text: '@bob potentially annoying text',
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(note.status, 400);
|
|
|
|
|
assert.strictEqual(note.body.error.code, 'CONTAINS_TOO_MANY_MENTIONS');
|
|
|
|
|
|
|
|
|
|
await api('admin/roles/unassign', {
|
|
|
|
|
userId: alice.id,
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await api('admin/roles/delete', {
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('ダイレクト投稿もエラーになる', async () => {
|
|
|
|
|
const res = await api('admin/roles/create', {
|
|
|
|
|
name: 'test',
|
|
|
|
|
description: '',
|
|
|
|
|
color: null,
|
|
|
|
|
iconUrl: null,
|
|
|
|
|
displayOrder: 0,
|
|
|
|
|
target: 'manual',
|
|
|
|
|
condFormula: {},
|
|
|
|
|
isAdministrator: false,
|
|
|
|
|
isModerator: false,
|
|
|
|
|
isPublic: false,
|
|
|
|
|
isExplorable: false,
|
|
|
|
|
asBadge: false,
|
|
|
|
|
canEditMembersByModerator: false,
|
|
|
|
|
policies: {
|
|
|
|
|
mentionLimit: {
|
|
|
|
|
useDefault: false,
|
|
|
|
|
priority: 1,
|
|
|
|
|
value: 0,
|
|
|
|
|
},
|
2024-03-07 02:51:57 +02:00
|
|
|
|
} as any,
|
2024-02-29 13:48:02 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
|
|
|
|
const assign = await api('admin/roles/assign', {
|
|
|
|
|
userId: alice.id,
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(assign.status, 204);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note = await api('notes/create', {
|
2024-02-29 13:48:02 +02:00
|
|
|
|
text: 'potentially annoying text',
|
|
|
|
|
visibility: 'specified',
|
2024-03-03 13:15:35 +02:00
|
|
|
|
visibleUserIds: [bob.id],
|
2024-02-29 13:48:02 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(note.status, 400);
|
|
|
|
|
assert.strictEqual(note.body.error.code, 'CONTAINS_TOO_MANY_MENTIONS');
|
|
|
|
|
|
|
|
|
|
await api('admin/roles/unassign', {
|
|
|
|
|
userId: alice.id,
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await api('admin/roles/delete', {
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('ダイレクトの宛先とメンションが同じ場合は重複してカウントしない', async () => {
|
|
|
|
|
const res = await api('admin/roles/create', {
|
|
|
|
|
name: 'test',
|
|
|
|
|
description: '',
|
|
|
|
|
color: null,
|
|
|
|
|
iconUrl: null,
|
|
|
|
|
displayOrder: 0,
|
|
|
|
|
target: 'manual',
|
|
|
|
|
condFormula: {},
|
|
|
|
|
isAdministrator: false,
|
|
|
|
|
isModerator: false,
|
|
|
|
|
isPublic: false,
|
|
|
|
|
isExplorable: false,
|
|
|
|
|
asBadge: false,
|
|
|
|
|
canEditMembersByModerator: false,
|
|
|
|
|
policies: {
|
|
|
|
|
mentionLimit: {
|
|
|
|
|
useDefault: false,
|
|
|
|
|
priority: 1,
|
|
|
|
|
value: 1,
|
|
|
|
|
},
|
2024-03-07 02:51:57 +02:00
|
|
|
|
} as any,
|
2024-02-29 13:48:02 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
|
|
|
|
const assign = await api('admin/roles/assign', {
|
|
|
|
|
userId: alice.id,
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(assign.status, 204);
|
|
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
|
2024-03-03 13:15:35 +02:00
|
|
|
|
const note = await api('notes/create', {
|
2024-02-29 13:48:02 +02:00
|
|
|
|
text: '@bob potentially annoying text',
|
|
|
|
|
visibility: 'specified',
|
2024-03-03 13:15:35 +02:00
|
|
|
|
visibleUserIds: [bob.id],
|
2024-02-29 13:48:02 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(note.status, 200);
|
|
|
|
|
|
|
|
|
|
await api('admin/roles/unassign', {
|
|
|
|
|
userId: alice.id,
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await api('admin/roles/delete', {
|
|
|
|
|
roleId: res.body.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
});
|
2022-03-22 15:48:33 +02:00
|
|
|
|
|
|
|
|
|
describe('notes/delete', () => {
|
2023-02-02 11:18:25 +02:00
|
|
|
|
test('delete a reply', async () => {
|
2022-06-26 13:16:32 +03:00
|
|
|
|
const mainNoteRes = await api('notes/create', {
|
2022-03-22 15:48:33 +02:00
|
|
|
|
text: 'main post',
|
|
|
|
|
}, alice);
|
2022-06-26 13:16:32 +03:00
|
|
|
|
const replyOneRes = await api('notes/create', {
|
2022-03-22 15:48:33 +02:00
|
|
|
|
text: 'reply one',
|
2022-05-21 16:21:41 +03:00
|
|
|
|
replyId: mainNoteRes.body.createdNote.id,
|
2022-03-22 15:48:33 +02:00
|
|
|
|
}, alice);
|
2022-06-26 13:16:32 +03:00
|
|
|
|
const replyTwoRes = await api('notes/create', {
|
2022-03-22 15:48:33 +02:00
|
|
|
|
text: 'reply two',
|
2022-05-21 16:21:41 +03:00
|
|
|
|
replyId: mainNoteRes.body.createdNote.id,
|
2022-03-22 15:48:33 +02:00
|
|
|
|
}, alice);
|
|
|
|
|
|
2022-06-26 13:16:32 +03:00
|
|
|
|
const deleteOneRes = await api('notes/delete', {
|
2022-03-22 15:48:33 +02:00
|
|
|
|
noteId: replyOneRes.body.createdNote.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(deleteOneRes.status, 204);
|
2022-06-26 13:16:32 +03:00
|
|
|
|
let mainNote = await Notes.findOneBy({ id: mainNoteRes.body.createdNote.id });
|
2022-03-22 15:48:33 +02:00
|
|
|
|
assert.strictEqual(mainNote.repliesCount, 1);
|
|
|
|
|
|
2022-06-26 13:16:32 +03:00
|
|
|
|
const deleteTwoRes = await api('notes/delete', {
|
2022-03-22 15:48:33 +02:00
|
|
|
|
noteId: replyTwoRes.body.createdNote.id,
|
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(deleteTwoRes.status, 204);
|
2022-06-26 13:16:32 +03:00
|
|
|
|
mainNote = await Notes.findOneBy({ id: mainNoteRes.body.createdNote.id });
|
2022-03-22 15:48:33 +02:00
|
|
|
|
assert.strictEqual(mainNote.repliesCount, 0);
|
2022-09-17 21:27:08 +03:00
|
|
|
|
});
|
2022-03-22 15:48:33 +02:00
|
|
|
|
});
|
2019-04-07 15:50:36 +03:00
|
|
|
|
});
|