2023-07-27 07:31:52 +02:00
|
|
|
/*
|
2024-02-13 16:59:27 +01:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
2023-03-03 03:13:12 +01:00
|
|
|
// node-fetch only supports it's own Blob yet
|
|
|
|
// https://github.com/node-fetch/node-fetch/pull/1664
|
|
|
|
import { Blob } from 'node-fetch';
|
2023-09-15 07:28:29 +02:00
|
|
|
import { MiUser } from '@/models/_.js';
|
2024-01-08 09:43:52 +01:00
|
|
|
import { api, initTestDb, post, signup, simpleGet, uploadFile } from '../utils.js';
|
2023-06-25 01:34:18 +02:00
|
|
|
import type * as misskey from 'misskey-js';
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
describe('Endpoints', () => {
|
2024-01-03 05:41:28 +01:00
|
|
|
let alice: misskey.entities.SignupResponse;
|
|
|
|
let bob: misskey.entities.SignupResponse;
|
|
|
|
let carol: misskey.entities.SignupResponse;
|
|
|
|
let dave: misskey.entities.SignupResponse;
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
beforeAll(async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
2023-03-03 03:13:12 +01:00
|
|
|
carol = await signup({ username: 'carol' });
|
|
|
|
dave = await signup({ username: 'dave' });
|
|
|
|
}, 1000 * 60 * 2);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
describe('signup', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正なユーザー名でアカウントが作成できない', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const res = await api('signup', {
|
2022-02-19 06:05:32 +01:00
|
|
|
username: 'test.',
|
2022-09-17 20:27:08 +02:00
|
|
|
password: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('空のパスワードでアカウントが作成できない', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const res = await api('signup', {
|
2022-02-19 06:05:32 +01:00
|
|
|
username: 'test',
|
2022-09-17 20:27:08 +02:00
|
|
|
password: '',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('正しくアカウントが作成できる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const me = {
|
|
|
|
username: 'test1',
|
2022-09-17 20:27:08 +02:00
|
|
|
password: 'test1',
|
2022-02-19 06:05:32 +01:00
|
|
|
};
|
|
|
|
|
2023-03-03 03:13:12 +01:00
|
|
|
const res = await api('signup', me);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.username, me.username);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('同じユーザー名のアカウントは作成できない', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const res = await api('signup', {
|
2022-09-17 20:27:08 +02:00
|
|
|
username: 'test1',
|
|
|
|
password: 'test1',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('signin', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('間違ったパスワードでサインインできない', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const res = await api('signin', {
|
2022-09-17 20:27:08 +02:00
|
|
|
username: 'test1',
|
|
|
|
password: 'bar',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 403);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('クエリをインジェクションできない', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const res = await api('signin', {
|
2022-09-17 20:27:08 +02:00
|
|
|
username: 'test1',
|
2024-03-03 12:15:35 +01:00
|
|
|
// @ts-expect-error password must be string
|
2022-02-19 06:05:32 +01:00
|
|
|
password: {
|
2022-09-17 20:27:08 +02:00
|
|
|
$gt: '',
|
|
|
|
},
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('正しい情報でサインインできる', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const res = await api('signin', {
|
2022-09-17 20:27:08 +02:00
|
|
|
username: 'test1',
|
|
|
|
password: 'test1',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('i/update', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('アカウント設定を更新できる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const myName = '大室櫻子';
|
|
|
|
const myLocation = '七森中';
|
|
|
|
const myBirthday = '2000-09-07';
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('i/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: myName,
|
|
|
|
location: myLocation,
|
2022-09-17 20:27:08 +02:00
|
|
|
birthday: myBirthday,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.name, myName);
|
|
|
|
assert.strictEqual(res.body.location, myLocation);
|
|
|
|
assert.strictEqual(res.body.birthday, myBirthday);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-03-03 03:13:12 +01:00
|
|
|
test('名前を空白にできる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('i/update', {
|
2022-09-17 20:27:08 +02:00
|
|
|
name: ' ',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
2023-03-03 03:13:12 +01:00
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(res.body.name, ' ');
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('誕生日の設定を削除できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('i/update', {
|
2022-09-17 20:27:08 +02:00
|
|
|
birthday: '2000-09-07',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('i/update', {
|
2022-09-17 20:27:08 +02:00
|
|
|
birthday: null,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.birthday, null);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正な誕生日の形式で怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('i/update', {
|
2022-09-17 20:27:08 +02:00
|
|
|
birthday: '2000/09/07',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('users/show', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ユーザーが取得できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('users/show', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.id, alice.id);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ユーザーが存在しなかったら怒る', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('users/show', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: '000000000000000000000000',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
2023-03-20 06:26:11 +01:00
|
|
|
assert.strictEqual(res.status, 404);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('間違ったIDで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('users/show', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: 'kyoppie',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
2023-03-20 06:26:11 +01:00
|
|
|
assert.strictEqual(res.status, 404);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('notes/show', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('投稿が取得できる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const myPost = await post(alice, {
|
2022-09-17 20:27:08 +02:00
|
|
|
text: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/show', {
|
2022-09-17 20:27:08 +02:00
|
|
|
noteId: myPost.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.id, myPost.id);
|
|
|
|
assert.strictEqual(res.body.text, myPost.text);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('投稿が存在しなかったら怒る', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/show', {
|
2022-09-17 20:27:08 +02:00
|
|
|
noteId: '000000000000000000000000',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('間違ったIDで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/show', {
|
2022-09-17 20:27:08 +02:00
|
|
|
noteId: 'kyoppie',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('notes/reactions/create', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('リアクションできる', async () => {
|
2023-03-08 00:56:09 +01:00
|
|
|
const bobPost = await post(bob, { text: 'hi' });
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/reactions/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
noteId: bobPost.id,
|
2022-02-27 06:14:27 +01:00
|
|
|
reaction: '🚀',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
2022-02-27 06:14:27 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const resNote = await api('notes/show', {
|
2022-02-27 06:14:27 +01:00
|
|
|
noteId: bobPost.id,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(resNote.status, 200);
|
2023-03-03 03:13:12 +01:00
|
|
|
assert.strictEqual(resNote.body.reactions['🚀'], 1);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('自分の投稿にもリアクションできる', async () => {
|
2023-03-08 00:56:09 +01:00
|
|
|
const myPost = await post(alice, { text: 'hi' });
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/reactions/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
noteId: myPost.id,
|
2022-02-27 06:14:27 +01:00
|
|
|
reaction: '🚀',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-03-03 03:13:12 +01:00
|
|
|
test('二重にリアクションすると上書きされる', async () => {
|
2023-03-08 00:56:09 +01:00
|
|
|
const bobPost = await post(bob, { text: 'hi' });
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('notes/reactions/create', {
|
2022-09-17 20:27:08 +02:00
|
|
|
noteId: bobPost.id,
|
|
|
|
reaction: '🥰',
|
|
|
|
}, alice);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/reactions/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
noteId: bobPost.id,
|
2022-02-27 06:14:27 +01:00
|
|
|
reaction: '🚀',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
2023-03-03 03:13:12 +01:00
|
|
|
assert.strictEqual(res.status, 204);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const resNote = await api('notes/show', {
|
2023-03-03 03:13:12 +01:00
|
|
|
noteId: bobPost.id,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(resNote.status, 200);
|
|
|
|
assert.deepStrictEqual(resNote.body.reactions, { '🚀': 1 });
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しない投稿にはリアクションできない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/reactions/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
noteId: '000000000000000000000000',
|
2022-02-27 06:14:27 +01:00
|
|
|
reaction: '🚀',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-06-22 12:49:38 +02:00
|
|
|
test('リノートにリアクションできない', async () => {
|
|
|
|
const bobNote = await post(bob, { text: 'hi' });
|
|
|
|
const bobRenote = await post(bob, { renoteId: bobNote.id });
|
|
|
|
|
|
|
|
const res = await api('notes/reactions/create', {
|
|
|
|
noteId: bobRenote.id,
|
|
|
|
reaction: '🚀',
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
assert.strictEqual(res.body.error.code, 'CANNOT_REACT_TO_RENOTE');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('引用にリアクションできる', async () => {
|
|
|
|
const bobNote = await post(bob, { text: 'hi' });
|
|
|
|
const bobRenote = await post(bob, { text: 'hi again', renoteId: bobNote.id });
|
|
|
|
|
|
|
|
const res = await api('notes/reactions/create', {
|
|
|
|
noteId: bobRenote.id,
|
|
|
|
reaction: '🚀',
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('空文字列のリアクションは\u2764にフォールバックされる', async () => {
|
|
|
|
const bobNote = await post(bob, { text: 'hi' });
|
|
|
|
|
|
|
|
const res = await api('notes/reactions/create', {
|
|
|
|
noteId: bobNote.id,
|
|
|
|
reaction: '',
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
|
|
|
|
|
|
|
const reaction = await api('notes/reactions', {
|
|
|
|
noteId: bobNote.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(reaction.body.length, 1);
|
|
|
|
assert.strictEqual(reaction.body[0].type, '\u2764');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('絵文字ではない文字列のリアクションは\u2764にフォールバックされる', async () => {
|
|
|
|
const bobNote = await post(bob, { text: 'hi' });
|
|
|
|
|
|
|
|
const res = await api('notes/reactions/create', {
|
|
|
|
noteId: bobNote.id,
|
|
|
|
reaction: 'Hello!',
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
|
|
|
|
|
|
|
const reaction = await api('notes/reactions', {
|
|
|
|
noteId: bobNote.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(reaction.body.length, 1);
|
|
|
|
assert.strictEqual(reaction.body[0].type, '\u2764');
|
|
|
|
});
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('空のパラメータで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
// @ts-expect-error param must not be empty
|
|
|
|
const res = await api('notes/reactions/create', {}, alice);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('間違ったIDで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/reactions/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
noteId: 'kyoppie',
|
2022-02-27 06:14:27 +01:00
|
|
|
reaction: '🚀',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('following/create', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォローできる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/create', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
enhance: account migration (#10592)
* copy block and mute then create follow and unfollow jobs
* copy block and mute and update lists when detecting an account has moved
* no need to care promise orders
* refactor updating actor and target
* automatically accept if a locked account had accepted an old account
* fix exception format
* prevent the old account from calling some endpoints
* do not unfollow when moving
* adjust following and follower counts
* check movedToUri when receiving a follow request
* skip if no need to adjust
* Revert "disable account migration"
This reverts commit 2321214c98591bcfe1385c1ab5bf0ff7b471ae1d.
* fix translation specifier
* fix checking alsoKnownAs and uri
* fix updating account
* fix refollowing locked account
* decrease followersCount if followed by the old account
* adjust following and followers counts when unfollowing
* fix copying mutings
* prohibit moved account from moving again
* fix move service
* allow app creation after moving
* fix lint
* remove unnecessary field
* fix cache update
* add e2e test
* add e2e test of accepting the new account automatically
* force follow if any error happens
* remove unnecessary joins
* use Array.map instead of for const of
* ユーザーリストの移行は追加のみを行う
* nanka iroiro
* fix misskey-js?
* :v:
* 移行を行ったアカウントからのフォローリクエストの自動許可を調整
* newUriを外に出す
* newUriを外に出す2
* clean up
* fix newUri
* prevent moving if the destination account has already moved
* set alsoKnownAs via /i/update
* fix database initialization
* add return type
* prohibit updating alsoKnownAs after moving
* skip to add to alsoKnownAs if toUrl is known
* skip adding to the list if it already has
* use Acct.parse instead
* rename error code
* :art:
* 制限を5から10に緩和
* movedTo(Uri), alsoKnownAsはユーザーidを返すように
* test api res
* fix
* 元アカウントはミュートし続ける
* :art:
* unfollow
* fix
* getUserUriをUserEntityServiceに
* ?
* job!
* :art:
* instance => server
* accountMovedShort, forbiddenBecauseYouAreMigrated
* accountMovedShort
* fix test
* import, pin禁止
* 実績を凍結する
* clean up
* :v:
* change message
* ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに
* Revert "ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに"
This reverts commit 3bd7be35d8aa455cb01ae58f8172a71a50485db1.
* validateAlsoKnownAs
* 移行後2時間以内はインポート可能なファイルサイズを拡大
* clean up
* どうせactorをupdatePersonで更新するならupdatePersonしか移行処理を発行しないことにする
* handle error?
* リモートからの移行処理の条件を是正
* log, port
* fix
* fix
* enhance(dev): non-production環境でhttpサーバー間でもユーザー、ノートの連合が可能なように
* refactor (use checkHttps)
* MISSKEY_WEBFINGER_USE_HTTP
* Environment Variable readme
* NEVER USE IN PRODUCTION
* fix punyHost
* fix indent
* fix
* experimental
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-04-29 17:09:29 +02:00
|
|
|
|
|
|
|
const connection = await initTestDb(true);
|
2023-08-16 10:51:28 +02:00
|
|
|
const Users = connection.getRepository(MiUser);
|
enhance: account migration (#10592)
* copy block and mute then create follow and unfollow jobs
* copy block and mute and update lists when detecting an account has moved
* no need to care promise orders
* refactor updating actor and target
* automatically accept if a locked account had accepted an old account
* fix exception format
* prevent the old account from calling some endpoints
* do not unfollow when moving
* adjust following and follower counts
* check movedToUri when receiving a follow request
* skip if no need to adjust
* Revert "disable account migration"
This reverts commit 2321214c98591bcfe1385c1ab5bf0ff7b471ae1d.
* fix translation specifier
* fix checking alsoKnownAs and uri
* fix updating account
* fix refollowing locked account
* decrease followersCount if followed by the old account
* adjust following and followers counts when unfollowing
* fix copying mutings
* prohibit moved account from moving again
* fix move service
* allow app creation after moving
* fix lint
* remove unnecessary field
* fix cache update
* add e2e test
* add e2e test of accepting the new account automatically
* force follow if any error happens
* remove unnecessary joins
* use Array.map instead of for const of
* ユーザーリストの移行は追加のみを行う
* nanka iroiro
* fix misskey-js?
* :v:
* 移行を行ったアカウントからのフォローリクエストの自動許可を調整
* newUriを外に出す
* newUriを外に出す2
* clean up
* fix newUri
* prevent moving if the destination account has already moved
* set alsoKnownAs via /i/update
* fix database initialization
* add return type
* prohibit updating alsoKnownAs after moving
* skip to add to alsoKnownAs if toUrl is known
* skip adding to the list if it already has
* use Acct.parse instead
* rename error code
* :art:
* 制限を5から10に緩和
* movedTo(Uri), alsoKnownAsはユーザーidを返すように
* test api res
* fix
* 元アカウントはミュートし続ける
* :art:
* unfollow
* fix
* getUserUriをUserEntityServiceに
* ?
* job!
* :art:
* instance => server
* accountMovedShort, forbiddenBecauseYouAreMigrated
* accountMovedShort
* fix test
* import, pin禁止
* 実績を凍結する
* clean up
* :v:
* change message
* ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに
* Revert "ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに"
This reverts commit 3bd7be35d8aa455cb01ae58f8172a71a50485db1.
* validateAlsoKnownAs
* 移行後2時間以内はインポート可能なファイルサイズを拡大
* clean up
* どうせactorをupdatePersonで更新するならupdatePersonしか移行処理を発行しないことにする
* handle error?
* リモートからの移行処理の条件を是正
* log, port
* fix
* fix
* enhance(dev): non-production環境でhttpサーバー間でもユーザー、ノートの連合が可能なように
* refactor (use checkHttps)
* MISSKEY_WEBFINGER_USE_HTTP
* Environment Variable readme
* NEVER USE IN PRODUCTION
* fix punyHost
* fix indent
* fix
* experimental
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-04-29 17:09:29 +02:00
|
|
|
const newBob = await Users.findOneByOrFail({ id: bob.id });
|
|
|
|
assert.strictEqual(newBob.followersCount, 0);
|
|
|
|
assert.strictEqual(newBob.followingCount, 1);
|
|
|
|
const newAlice = await Users.findOneByOrFail({ id: alice.id });
|
|
|
|
assert.strictEqual(newAlice.followersCount, 1);
|
|
|
|
assert.strictEqual(newAlice.followingCount, 0);
|
|
|
|
connection.destroy();
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('既にフォローしている場合は怒る', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/create', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しないユーザーはフォローできない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/create', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: '000000000000000000000000',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('自分自身はフォローできない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/create', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('空のパラメータで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
// @ts-expect-error params must not be empty
|
|
|
|
const res = await api('following/create', {}, alice);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('間違ったIDで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/create', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: 'foo',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('following/delete', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォロー解除できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('following/create', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/delete', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
enhance: account migration (#10592)
* copy block and mute then create follow and unfollow jobs
* copy block and mute and update lists when detecting an account has moved
* no need to care promise orders
* refactor updating actor and target
* automatically accept if a locked account had accepted an old account
* fix exception format
* prevent the old account from calling some endpoints
* do not unfollow when moving
* adjust following and follower counts
* check movedToUri when receiving a follow request
* skip if no need to adjust
* Revert "disable account migration"
This reverts commit 2321214c98591bcfe1385c1ab5bf0ff7b471ae1d.
* fix translation specifier
* fix checking alsoKnownAs and uri
* fix updating account
* fix refollowing locked account
* decrease followersCount if followed by the old account
* adjust following and followers counts when unfollowing
* fix copying mutings
* prohibit moved account from moving again
* fix move service
* allow app creation after moving
* fix lint
* remove unnecessary field
* fix cache update
* add e2e test
* add e2e test of accepting the new account automatically
* force follow if any error happens
* remove unnecessary joins
* use Array.map instead of for const of
* ユーザーリストの移行は追加のみを行う
* nanka iroiro
* fix misskey-js?
* :v:
* 移行を行ったアカウントからのフォローリクエストの自動許可を調整
* newUriを外に出す
* newUriを外に出す2
* clean up
* fix newUri
* prevent moving if the destination account has already moved
* set alsoKnownAs via /i/update
* fix database initialization
* add return type
* prohibit updating alsoKnownAs after moving
* skip to add to alsoKnownAs if toUrl is known
* skip adding to the list if it already has
* use Acct.parse instead
* rename error code
* :art:
* 制限を5から10に緩和
* movedTo(Uri), alsoKnownAsはユーザーidを返すように
* test api res
* fix
* 元アカウントはミュートし続ける
* :art:
* unfollow
* fix
* getUserUriをUserEntityServiceに
* ?
* job!
* :art:
* instance => server
* accountMovedShort, forbiddenBecauseYouAreMigrated
* accountMovedShort
* fix test
* import, pin禁止
* 実績を凍結する
* clean up
* :v:
* change message
* ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに
* Revert "ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに"
This reverts commit 3bd7be35d8aa455cb01ae58f8172a71a50485db1.
* validateAlsoKnownAs
* 移行後2時間以内はインポート可能なファイルサイズを拡大
* clean up
* どうせactorをupdatePersonで更新するならupdatePersonしか移行処理を発行しないことにする
* handle error?
* リモートからの移行処理の条件を是正
* log, port
* fix
* fix
* enhance(dev): non-production環境でhttpサーバー間でもユーザー、ノートの連合が可能なように
* refactor (use checkHttps)
* MISSKEY_WEBFINGER_USE_HTTP
* Environment Variable readme
* NEVER USE IN PRODUCTION
* fix punyHost
* fix indent
* fix
* experimental
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-04-29 17:09:29 +02:00
|
|
|
|
|
|
|
const connection = await initTestDb(true);
|
2023-08-16 10:51:28 +02:00
|
|
|
const Users = connection.getRepository(MiUser);
|
enhance: account migration (#10592)
* copy block and mute then create follow and unfollow jobs
* copy block and mute and update lists when detecting an account has moved
* no need to care promise orders
* refactor updating actor and target
* automatically accept if a locked account had accepted an old account
* fix exception format
* prevent the old account from calling some endpoints
* do not unfollow when moving
* adjust following and follower counts
* check movedToUri when receiving a follow request
* skip if no need to adjust
* Revert "disable account migration"
This reverts commit 2321214c98591bcfe1385c1ab5bf0ff7b471ae1d.
* fix translation specifier
* fix checking alsoKnownAs and uri
* fix updating account
* fix refollowing locked account
* decrease followersCount if followed by the old account
* adjust following and followers counts when unfollowing
* fix copying mutings
* prohibit moved account from moving again
* fix move service
* allow app creation after moving
* fix lint
* remove unnecessary field
* fix cache update
* add e2e test
* add e2e test of accepting the new account automatically
* force follow if any error happens
* remove unnecessary joins
* use Array.map instead of for const of
* ユーザーリストの移行は追加のみを行う
* nanka iroiro
* fix misskey-js?
* :v:
* 移行を行ったアカウントからのフォローリクエストの自動許可を調整
* newUriを外に出す
* newUriを外に出す2
* clean up
* fix newUri
* prevent moving if the destination account has already moved
* set alsoKnownAs via /i/update
* fix database initialization
* add return type
* prohibit updating alsoKnownAs after moving
* skip to add to alsoKnownAs if toUrl is known
* skip adding to the list if it already has
* use Acct.parse instead
* rename error code
* :art:
* 制限を5から10に緩和
* movedTo(Uri), alsoKnownAsはユーザーidを返すように
* test api res
* fix
* 元アカウントはミュートし続ける
* :art:
* unfollow
* fix
* getUserUriをUserEntityServiceに
* ?
* job!
* :art:
* instance => server
* accountMovedShort, forbiddenBecauseYouAreMigrated
* accountMovedShort
* fix test
* import, pin禁止
* 実績を凍結する
* clean up
* :v:
* change message
* ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに
* Revert "ブロック, フォロー, ミュート, リストのインポートファイルの制限を32MiBに"
This reverts commit 3bd7be35d8aa455cb01ae58f8172a71a50485db1.
* validateAlsoKnownAs
* 移行後2時間以内はインポート可能なファイルサイズを拡大
* clean up
* どうせactorをupdatePersonで更新するならupdatePersonしか移行処理を発行しないことにする
* handle error?
* リモートからの移行処理の条件を是正
* log, port
* fix
* fix
* enhance(dev): non-production環境でhttpサーバー間でもユーザー、ノートの連合が可能なように
* refactor (use checkHttps)
* MISSKEY_WEBFINGER_USE_HTTP
* Environment Variable readme
* NEVER USE IN PRODUCTION
* fix punyHost
* fix indent
* fix
* experimental
---------
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
2023-04-29 17:09:29 +02:00
|
|
|
const newBob = await Users.findOneByOrFail({ id: bob.id });
|
|
|
|
assert.strictEqual(newBob.followersCount, 0);
|
|
|
|
assert.strictEqual(newBob.followingCount, 0);
|
|
|
|
const newAlice = await Users.findOneByOrFail({ id: alice.id });
|
|
|
|
assert.strictEqual(newAlice.followersCount, 0);
|
|
|
|
assert.strictEqual(newAlice.followingCount, 0);
|
|
|
|
connection.destroy();
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォローしていない場合は怒る', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/delete', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しないユーザーはフォロー解除できない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/delete', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: '000000000000000000000000',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('自分自身はフォロー解除できない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/delete', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('空のパラメータで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
// @ts-expect-error params must not be empty
|
|
|
|
const res = await api('following/delete', {}, alice);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('間違ったIDで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('following/delete', {
|
2022-09-17 20:27:08 +02:00
|
|
|
userId: 'kyoppie',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-05-05 01:48:14 +02:00
|
|
|
describe('channels/search', () => {
|
|
|
|
test('空白検索で一覧を取得できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('channels/create', {
|
2023-05-05 01:48:14 +02:00
|
|
|
name: 'aaa',
|
|
|
|
description: 'bbb',
|
|
|
|
}, bob);
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('channels/create', {
|
2023-05-05 01:48:14 +02:00
|
|
|
name: 'ccc1',
|
|
|
|
description: 'ddd1',
|
|
|
|
}, bob);
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('channels/create', {
|
2023-05-05 01:48:14 +02:00
|
|
|
name: 'ccc2',
|
|
|
|
description: 'ddd2',
|
|
|
|
}, bob);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('channels/search', {
|
2023-05-05 01:48:14 +02:00
|
|
|
query: '',
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 3);
|
|
|
|
});
|
|
|
|
test('名前のみの検索で名前を検索できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('channels/search', {
|
2023-05-05 01:48:14 +02:00
|
|
|
query: 'aaa',
|
|
|
|
type: 'nameOnly',
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 1);
|
|
|
|
assert.strictEqual(res.body[0].name, 'aaa');
|
|
|
|
});
|
|
|
|
test('名前のみの検索で名前を複数検索できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('channels/search', {
|
2023-05-05 01:48:14 +02:00
|
|
|
query: 'ccc',
|
|
|
|
type: 'nameOnly',
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 2);
|
|
|
|
});
|
|
|
|
test('名前のみの検索で説明は検索できない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('channels/search', {
|
2023-05-05 01:48:14 +02:00
|
|
|
query: 'bbb',
|
|
|
|
type: 'nameOnly',
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 0);
|
|
|
|
});
|
|
|
|
test('名前と説明の検索で名前を検索できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('channels/search', {
|
2023-05-05 01:48:14 +02:00
|
|
|
query: 'ccc1',
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 1);
|
|
|
|
assert.strictEqual(res.body[0].name, 'ccc1');
|
|
|
|
});
|
|
|
|
test('名前と説明での検索で説明を検索できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('channels/search', {
|
2023-05-05 01:48:14 +02:00
|
|
|
query: 'ddd1',
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 1);
|
|
|
|
assert.strictEqual(res.body[0].name, 'ccc1');
|
|
|
|
});
|
|
|
|
test('名前と説明の検索で名前を複数検索できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('channels/search', {
|
2023-05-05 01:48:14 +02:00
|
|
|
query: 'ccc',
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 2);
|
|
|
|
});
|
|
|
|
test('名前と説明での検索で説明を複数検索できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('channels/search', {
|
2023-05-05 01:48:14 +02:00
|
|
|
query: 'ddd',
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
describe('drive', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ドライブ情報を取得できる', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
await uploadFile(alice, {
|
|
|
|
blob: new Blob([new Uint8Array(256)]),
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
2023-03-03 03:13:12 +01:00
|
|
|
await uploadFile(alice, {
|
|
|
|
blob: new Blob([new Uint8Array(512)]),
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
2023-03-03 03:13:12 +01:00
|
|
|
await uploadFile(alice, {
|
|
|
|
blob: new Blob([new Uint8Array(1024)]),
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive', {}, alice);
|
2022-02-19 06:05:32 +01:00
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
2023-03-03 03:13:12 +01:00
|
|
|
expect(res.body).toHaveProperty('usage', 1792);
|
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('drive/files/create', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ファイルを作成できる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const res = await uploadFile(alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
2024-03-03 12:15:35 +01:00
|
|
|
assert.strictEqual(res.body!.name, 'Lenna.jpg');
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ファイルに名前を付けられる', async () => {
|
2023-03-04 08:51:07 +01:00
|
|
|
const res = await uploadFile(alice, { name: 'Belmond.jpg' });
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
2024-03-03 12:15:35 +01:00
|
|
|
assert.strictEqual(res.body!.name, 'Belmond.jpg');
|
2023-03-04 08:51:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('ファイルに名前を付けられるが、拡張子は正しいものになる', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const res = await uploadFile(alice, { name: 'Belmond.png' });
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-03-03 03:13:12 +01:00
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
2024-03-03 12:15:35 +01:00
|
|
|
assert.strictEqual(res.body!.name, 'Belmond.png.jpg');
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ファイル無しで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
// @ts-expect-error params must not be empty
|
|
|
|
const res = await api('drive/files/create', {}, alice);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('SVGファイルを作成できる', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const res = await uploadFile(alice, { path: 'image.svg' });
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
2024-03-03 12:15:35 +01:00
|
|
|
assert.strictEqual(res.body!.name, 'image.svg');
|
|
|
|
assert.strictEqual(res.body!.type, 'image/svg+xml');
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2023-03-10 01:37:22 +01:00
|
|
|
|
|
|
|
for (const type of ['webp', 'avif']) {
|
|
|
|
const mediaType = `image/${type}`;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const getWebpublicType = async (user: misskey.entities.SignupResponse, fileId: string): Promise<string> => {
|
2023-03-10 01:37:22 +01:00
|
|
|
// drive/files/create does not expose webpublicType directly, so get it by posting it
|
|
|
|
const res = await post(user, {
|
|
|
|
text: mediaType,
|
|
|
|
fileIds: [fileId],
|
|
|
|
});
|
|
|
|
const apRes = await simpleGet(`notes/${res.id}`, 'application/activity+json');
|
|
|
|
assert.strictEqual(apRes.status, 200);
|
|
|
|
assert.ok(Array.isArray(apRes.body.attachment));
|
|
|
|
return apRes.body.attachment[0].mediaType;
|
|
|
|
};
|
|
|
|
|
|
|
|
test(`透明な${type}ファイルを作成できる`, async () => {
|
|
|
|
const path = `with-alpha.${type}`;
|
|
|
|
const res = await uploadFile(alice, { path });
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2024-03-03 12:15:35 +01:00
|
|
|
assert.strictEqual(res.body!.name, path);
|
|
|
|
assert.strictEqual(res.body!.type, mediaType);
|
2023-03-10 01:37:22 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const webpublicType = await getWebpublicType(alice, res.body!.id);
|
2023-03-10 01:37:22 +01:00
|
|
|
assert.strictEqual(webpublicType, 'image/webp');
|
|
|
|
});
|
|
|
|
|
|
|
|
test(`透明じゃない${type}ファイルを作成できる`, async () => {
|
|
|
|
const path = `without-alpha.${type}`;
|
|
|
|
const res = await uploadFile(alice, { path });
|
|
|
|
assert.strictEqual(res.status, 200);
|
2024-03-03 12:15:35 +01:00
|
|
|
assert.strictEqual(res.body!.name, path);
|
|
|
|
assert.strictEqual(res.body!.type, mediaType);
|
2023-03-10 01:37:22 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const webpublicType = await getWebpublicType(alice, res.body!.id);
|
2023-03-10 01:37:22 +01:00
|
|
|
assert.strictEqual(webpublicType, 'image/webp');
|
|
|
|
});
|
|
|
|
}
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('drive/files/update', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('名前を更新できる', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const file = (await uploadFile(alice)).body;
|
2022-02-19 06:05:32 +01:00
|
|
|
const newName = 'いちごパスタ.png';
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
|
|
|
fileId: file!.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
name: newName,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.name, newName);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('他人のファイルは更新できない', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const file = (await uploadFile(alice)).body;
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
|
|
|
fileId: file!.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'いちごパスタ.png',
|
|
|
|
}, bob);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('親フォルダを更新できる', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const file = (await uploadFile(alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
|
|
|
fileId: file!.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
folderId: folder.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.folderId, folder.id);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('親フォルダを無しにできる', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const file = (await uploadFile(alice)).body;
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('drive/files/update', {
|
|
|
|
fileId: file!.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
folderId: folder.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
|
|
|
fileId: file!.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
folderId: null,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.folderId, null);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('他人のフォルダには入れられない', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const file = (await uploadFile(alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
|
|
|
fileId: file!.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
folderId: folder.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しないフォルダで怒られる', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const file = (await uploadFile(alice)).body;
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
|
|
|
fileId: file!.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
folderId: '000000000000000000000000',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正なフォルダIDで怒られる', async () => {
|
2023-03-03 03:13:12 +01:00
|
|
|
const file = (await uploadFile(alice)).body;
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
|
|
|
fileId: file!.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
folderId: 'foo',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ファイルが存在しなかったら怒る', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
fileId: '000000000000000000000000',
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'いちごパスタ.png',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2024-01-08 09:40:37 +01:00
|
|
|
test('不正なファイル名で怒られる', async () => {
|
|
|
|
const file = (await uploadFile(alice)).body;
|
|
|
|
const newName = '';
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
|
|
|
fileId: file!.id,
|
2024-01-08 09:40:37 +01:00
|
|
|
name: newName,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
});
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('間違ったIDで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
fileId: 'kyoppie',
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'いちごパスタ.png',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('drive/folders/create', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォルダを作成できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.name, 'test');
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('drive/folders/update', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('名前を更新できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'new name',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.name, 'new name');
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('他人のフォルダを更新できない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'new name',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('親フォルダを更新できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
const parentFolder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'parent',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: parentFolder.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.parentId, parentFolder.id);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('親フォルダを無しに更新できる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
const parentFolder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'parent',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: parentFolder.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: null,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.parentId, null);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('他人のフォルダを親フォルダに設定できない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
const parentFolder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'parent',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: parentFolder.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォルダが循環するような構造にできない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
const parentFolder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'parent',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: parentFolder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: folder.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: parentFolder.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォルダが循環するような構造にできない(再帰的)', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folderA = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
const folderB = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
const folderC = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folderB.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: folderA.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folderC.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: folderB.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folderA.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: folderC.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォルダが循環するような構造にできない(自身)', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folderA = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folderA.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: folderA.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しない親フォルダを設定できない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: '000000000000000000000000',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正な親フォルダIDで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const folder = (await api('drive/folders/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
name: 'test',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice)).body;
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
2023-03-03 03:13:12 +01:00
|
|
|
parentId: 'foo',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しないフォルダを更新できない', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2023-03-03 03:13:12 +01:00
|
|
|
folderId: '000000000000000000000000',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正なフォルダIDで怒られる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('drive/folders/update', {
|
2023-03-03 03:13:12 +01:00
|
|
|
folderId: 'foo',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('notes/replies', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('自分に閲覧権限のない投稿は含まれない', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const alicePost = await post(alice, {
|
2023-03-03 03:13:12 +01:00
|
|
|
text: 'foo',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
await post(bob, {
|
|
|
|
replyId: alicePost.id,
|
|
|
|
text: 'bar',
|
|
|
|
visibility: 'specified',
|
2023-03-03 03:13:12 +01:00
|
|
|
visibleUserIds: [alice.id],
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/replies', {
|
2023-03-03 03:13:12 +01:00
|
|
|
noteId: alicePost.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, carol);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 0);
|
2023-03-03 03:13:12 +01:00
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('notes/timeline', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォロワー限定投稿が含まれる', async () => {
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('following/create', {
|
2023-03-03 03:13:12 +01:00
|
|
|
userId: carol.id,
|
|
|
|
}, dave);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2023-03-03 03:13:12 +01:00
|
|
|
const carolPost = await post(carol, {
|
2022-02-19 06:05:32 +01:00
|
|
|
text: 'foo',
|
2023-03-03 03:13:12 +01:00
|
|
|
visibility: 'followers',
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('notes/timeline', {}, dave);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.length, 1);
|
2023-03-03 03:13:12 +01:00
|
|
|
assert.strictEqual(res.body[0].id, carolPost.id);
|
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
2023-03-19 12:27:17 +01:00
|
|
|
|
|
|
|
describe('URL preview', () => {
|
|
|
|
test('Error from summaly becomes HTTP 422', async () => {
|
|
|
|
const res = await simpleGet('/url?url=https://e:xample.com');
|
|
|
|
assert.strictEqual(res.status, 422);
|
|
|
|
assert.strictEqual(res.body.error.code, 'URL_PREVIEW_FAILED');
|
|
|
|
});
|
|
|
|
});
|
2023-04-13 06:17:32 +02:00
|
|
|
|
|
|
|
describe('パーソナルメモ機能のテスト', () => {
|
|
|
|
test('他者に関するメモを更新できる', async () => {
|
|
|
|
const memo = '10月まで低浮上とのこと。';
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res1 = await api('users/update-memo', {
|
2023-04-13 06:17:32 +02:00
|
|
|
memo,
|
|
|
|
userId: bob.id,
|
|
|
|
}, alice);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res2 = await api('users/show', {
|
2023-04-13 06:17:32 +02:00
|
|
|
userId: bob.id,
|
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(res1.status, 204);
|
|
|
|
assert.strictEqual(res2.body?.memo, memo);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('自分に関するメモを更新できる', async () => {
|
|
|
|
const memo = 'チケットを月末までに買う。';
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res1 = await api('users/update-memo', {
|
2023-04-13 06:17:32 +02:00
|
|
|
memo,
|
|
|
|
userId: alice.id,
|
|
|
|
}, alice);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res2 = await api('users/show', {
|
2023-04-13 06:17:32 +02:00
|
|
|
userId: alice.id,
|
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(res1.status, 204);
|
|
|
|
assert.strictEqual(res2.body?.memo, memo);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('メモを削除できる', async () => {
|
|
|
|
const memo = '10月まで低浮上とのこと。';
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('users/update-memo', {
|
2023-04-13 06:17:32 +02:00
|
|
|
memo,
|
|
|
|
userId: bob.id,
|
|
|
|
}, alice);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
await api('users/update-memo', {
|
2023-04-13 06:17:32 +02:00
|
|
|
memo: '',
|
|
|
|
userId: bob.id,
|
|
|
|
}, alice);
|
|
|
|
|
2024-03-03 12:15:35 +01:00
|
|
|
const res = await api('users/show', {
|
2023-04-13 06:17:32 +02:00
|
|
|
userId: bob.id,
|
|
|
|
}, alice);
|
|
|
|
|
2023-04-13 18:10:36 +02:00
|
|
|
// memoには常に文字列かnullが入っている(5cac151)
|
|
|
|
assert.strictEqual(res.body.memo, null);
|
2023-04-13 06:17:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('メモは個人ごとに独立して保存される', async () => {
|
|
|
|
const memoAliceToBob = '10月まで低浮上とのこと。';
|
|
|
|
const memoCarolToBob = '例の件について今度問いただす。';
|
|
|
|
|
|
|
|
await Promise.all([
|
2024-03-03 12:15:35 +01:00
|
|
|
api('users/update-memo', {
|
2023-04-13 06:17:32 +02:00
|
|
|
memo: memoAliceToBob,
|
|
|
|
userId: bob.id,
|
|
|
|
}, alice),
|
2024-03-03 12:15:35 +01:00
|
|
|
api('users/update-memo', {
|
2023-04-13 06:17:32 +02:00
|
|
|
memo: memoCarolToBob,
|
|
|
|
userId: bob.id,
|
|
|
|
}, carol),
|
|
|
|
]);
|
|
|
|
|
|
|
|
const [resAlice, resCarol] = await Promise.all([
|
2024-03-03 12:15:35 +01:00
|
|
|
api('users/show', {
|
2023-04-13 06:17:32 +02:00
|
|
|
userId: bob.id,
|
|
|
|
}, alice),
|
2024-03-03 12:15:35 +01:00
|
|
|
api('users/show', {
|
2023-04-13 06:17:32 +02:00
|
|
|
userId: bob.id,
|
|
|
|
}, carol),
|
|
|
|
]);
|
|
|
|
|
|
|
|
assert.strictEqual(resAlice.body.memo, memoAliceToBob);
|
|
|
|
assert.strictEqual(resCarol.body.memo, memoCarolToBob);
|
|
|
|
});
|
|
|
|
});
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|