hippofish/packages/backend/test/e2e/endpoints.ts
Kisaragi 31e82fc29a
test(backend): kill many any in backend test (partial) (#14054)
* kill any on utils:api

* kill any on timeline test

* use optional chain to kill TS2532 on timeline test
変更前: 該当ノートが見つからなければundefinedに対するプロパティアクセスとしてテストがクラッシュ
変更後: 該当ノートが見つからなければoptional chainがundefinedとして評価されるが、strictEqualの右辺がnon-nullableなためアサーションに失敗しテストがクラッシュ

* kill `as any` for ApMfmService

* kill argument any for api-visibility

* kill argument any across a few tests

* do not return value that has yielded from `await`-ing `Promise<void>`

* force cast

* runtime non-null assertion to coerce

* rewrite `assert.notEqual(expr, null)` to `assert.ok(expr)`
こうすることでassertion type扱いになり、non-nullableになる

* change return type of `failedApiCall` to `void`
戻り値がどこにも使われていない

* split bindings for exports.ts
型が合わなくて文句を言ってくるので適切に分割

* runtime non-null assertion

* runtime non-null assertion

* 何故かうまく行かないので、とりあえずXORしてみる

* Revert "何故かうまく行かないので、とりあえずXORしてみる"

This reverts commit 48cf32c930924840d0892af92d71b9437acb5844.

* castAsErrorで安全ではないキャストを隠蔽

* 型アサーションの追加

* 型アサーションの追加

* 型アサーションの追加

* voidで値を返さない

* castAsError

* assert.ok => kill nullability

* もはや明示的な型の指定は必要ない

* castAsError

* castAsError

* 型アサーションの追加

* nullableを一旦抑止

* 変数を分離して型エラーを排除

* 不要なプロパティを削除する処理を隠蔽してanyを排除

* Repository type

* simple type

* assert.ok => kill nullability

* revert `as any` drop
reverts fe95c05b3f53266108128680d9358a3796844232 partialy

* test: fix invalid assertion
partially revert b99b7b5392d9d20c81dfee1346ba8b33ff9e1fbb

* test: 52d8a54fc7 により型が合うようになった部分の`as any`を除去

* format

* test: apply https://github.com/misskey-dev/misskey/pull/14054#discussion_r1672369526 (part 1)

* test: use non-null assertion to suppress too many error

* Update packages/backend/test/utils.ts

Co-authored-by: anatawa12 <anatawa12@icloud.com>

---------

Co-authored-by: anatawa12 <anatawa12@icloud.com>
2024-07-14 09:33:16 +09:00

1134 lines
32 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
process.env.NODE_ENV = 'test';
import * as assert from 'assert';
// node-fetch only supports it's own Blob yet
// https://github.com/node-fetch/node-fetch/pull/1664
import { Blob } from 'node-fetch';
import { MiUser } from '@/models/_.js';
import { api, castAsError, initTestDb, post, signup, simpleGet, uploadFile } from '../utils.js';
import type * as misskey from 'misskey-js';
describe('Endpoints', () => {
let alice: misskey.entities.SignupResponse;
let bob: misskey.entities.SignupResponse;
let carol: misskey.entities.SignupResponse;
let dave: misskey.entities.SignupResponse;
beforeAll(async () => {
alice = await signup({ username: 'alice' });
bob = await signup({ username: 'bob' });
carol = await signup({ username: 'carol' });
dave = await signup({ username: 'dave' });
}, 1000 * 60 * 2);
describe('signup', () => {
test('不正なユーザー名でアカウントが作成できない', async () => {
const res = await api('signup', {
username: 'test.',
password: 'test',
});
assert.strictEqual(res.status, 400);
});
test('', async () => {
const res = await api('signup', {
username: 'test',
password: '',
});
assert.strictEqual(res.status, 400);
});
test('', async () => {
const me = {
username: 'test1',
password: 'test1',
};
const res = await api('signup', me);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.username, me.username);
});
test('', async () => {
const res = await api('signup', {
username: 'test1',
password: 'test1',
});
assert.strictEqual(res.status, 400);
});
});
describe('signin', () => {
test('', async () => {
const res = await api('signin', {
username: 'test1',
password: 'bar',
});
assert.strictEqual(res.status, 403);
});
test('', async () => {
const res = await api('signin', {
username: 'test1',
// @ts-expect-error password must be string
password: {
$gt: '',
},
});
assert.strictEqual(res.status, 400);
});
test('', async () => {
const res = await api('signin', {
username: 'test1',
password: 'test1',
});
assert.strictEqual(res.status, 200);
});
});
describe('i/update', () => {
test('', async () => {
const myName = '';
const myLocation = '';
const myBirthday = '2000-09-07';
const res = await api('i/update', {
name: myName,
location: myLocation,
birthday: myBirthday,
}, 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);
});
test('nullになる', async () => {
const res = await api('i/update', {
name: ' ',
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(res.body.name, null);
});
test('', async () => {
const res = await api('i/update', {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#white_space
name: ' \u0009\u000b\u000c\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\ufeff',
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(res.body.name, ' ');
});
test('', async () => {
await api('i/update', {
birthday: '2000-09-07',
}, alice);
const res = await api('i/update', {
birthday: null,
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.birthday, null);
});
test('', async () => {
const res = await api('i/update', {
birthday: '2000/09/07',
}, alice);
assert.strictEqual(res.status, 400);
});
});
describe('users/show', () => {
test('', async () => {
const res = await api('users/show', {
userId: alice.id,
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual((res.body as unknown as { id: string }).id, alice.id);
});
test('', async () => {
const res = await api('users/show', {
userId: '000000000000000000000000',
});
assert.strictEqual(res.status, 404);
});
test('IDで怒られる', async () => {
const res = await api('users/show', {
userId: 'kyoppie',
});
assert.strictEqual(res.status, 404);
});
});
describe('notes/show', () => {
test('稿', async () => {
const myPost = await post(alice, {
text: 'test',
});
const res = await api('notes/show', {
noteId: myPost.id,
}, 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);
});
test('稿', async () => {
const res = await api('notes/show', {
noteId: '000000000000000000000000',
});
assert.strictEqual(res.status, 400);
});
test('IDで怒られる', async () => {
const res = await api('notes/show', {
noteId: 'kyoppie',
});
assert.strictEqual(res.status, 400);
});
});
describe('notes/reactions/create', () => {
test('', async () => {
const bobPost = await post(bob, { text: 'hi' });
const res = await api('notes/reactions/create', {
noteId: bobPost.id,
reaction: '🚀',
}, alice);
assert.strictEqual(res.status, 204);
const resNote = await api('notes/show', {
noteId: bobPost.id,
}, alice);
assert.strictEqual(resNote.status, 200);
assert.strictEqual(resNote.body.reactions['🚀'], 1);
});
test('稿', async () => {
const myPost = await post(alice, { text: 'hi' });
const res = await api('notes/reactions/create', {
noteId: myPost.id,
reaction: '🚀',
}, alice);
assert.strictEqual(res.status, 204);
});
test('', async () => {
const bobPost = await post(bob, { text: 'hi' });
await api('notes/reactions/create', {
noteId: bobPost.id,
reaction: '🥰',
}, alice);
const res = await api('notes/reactions/create', {
noteId: bobPost.id,
reaction: '🚀',
}, alice);
assert.strictEqual(res.status, 204);
const resNote = await api('notes/show', {
noteId: bobPost.id,
}, alice);
assert.strictEqual(resNote.status, 200);
assert.deepStrictEqual(resNote.body.reactions, { '🚀': 1 });
});
test('稿', async () => {
const res = await api('notes/reactions/create', {
noteId: '000000000000000000000000',
reaction: '🚀',
}, alice);
assert.strictEqual(res.status, 400);
});
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.ok(res.body);
assert.strictEqual(castAsError(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');
});
test('', async () => {
// @ts-expect-error param must not be empty
const res = await api('notes/reactions/create', {}, alice);
assert.strictEqual(res.status, 400);
});
test('IDで怒られる', async () => {
const res = await api('notes/reactions/create', {
noteId: 'kyoppie',
reaction: '🚀',
}, alice);
assert.strictEqual(res.status, 400);
});
});
describe('following/create', () => {
test('', async () => {
const res = await api('following/create', {
userId: alice.id,
}, bob);
assert.strictEqual(res.status, 200);
const connection = await initTestDb(true);
const Users = connection.getRepository(MiUser);
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();
});
test('', async () => {
const res = await api('following/create', {
userId: alice.id,
}, bob);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const res = await api('following/create', {
userId: '000000000000000000000000',
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const res = await api('following/create', {
userId: alice.id,
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
// @ts-expect-error params must not be empty
const res = await api('following/create', {}, alice);
assert.strictEqual(res.status, 400);
});
test('IDで怒られる', async () => {
const res = await api('following/create', {
userId: 'foo',
}, alice);
assert.strictEqual(res.status, 400);
});
});
describe('following/delete', () => {
test('', async () => {
await api('following/create', {
userId: alice.id,
}, bob);
const res = await api('following/delete', {
userId: alice.id,
}, bob);
assert.strictEqual(res.status, 200);
const connection = await initTestDb(true);
const Users = connection.getRepository(MiUser);
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();
});
test('', async () => {
const res = await api('following/delete', {
userId: alice.id,
}, bob);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const res = await api('following/delete', {
userId: '000000000000000000000000',
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const res = await api('following/delete', {
userId: alice.id,
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
// @ts-expect-error params must not be empty
const res = await api('following/delete', {}, alice);
assert.strictEqual(res.status, 400);
});
test('IDで怒られる', async () => {
const res = await api('following/delete', {
userId: 'kyoppie',
}, alice);
assert.strictEqual(res.status, 400);
});
});
describe('channels/search', () => {
test('', async () => {
await api('channels/create', {
name: 'aaa',
description: 'bbb',
}, bob);
await api('channels/create', {
name: 'ccc1',
description: 'ddd1',
}, bob);
await api('channels/create', {
name: 'ccc2',
description: 'ddd2',
}, bob);
const res = await api('channels/search', {
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 () => {
const res = await api('channels/search', {
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 () => {
const res = await api('channels/search', {
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 () => {
const res = await api('channels/search', {
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 () => {
const res = await api('channels/search', {
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 () => {
const res = await api('channels/search', {
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 () => {
const res = await api('channels/search', {
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 () => {
const res = await api('channels/search', {
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);
});
});
describe('drive', () => {
test('', async () => {
await uploadFile(alice, {
blob: new Blob([new Uint8Array(256)]),
});
await uploadFile(alice, {
blob: new Blob([new Uint8Array(512)]),
});
await uploadFile(alice, {
blob: new Blob([new Uint8Array(1024)]),
});
const res = await api('drive', {}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
expect(res.body).toHaveProperty('usage', 1792);
});
});
describe('drive/files/create', () => {
test('', async () => {
const res = await uploadFile(alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body!.name, '192.jpg');
});
test('', async () => {
const res = await uploadFile(alice, { name: 'Belmond.jpg' });
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body!.name, 'Belmond.jpg');
});
test('', async () => {
const res = await uploadFile(alice, { name: 'Belmond.png' });
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body!.name, 'Belmond.png.jpg');
});
test('', async () => {
// @ts-expect-error params must not be empty
const res = await api('drive/files/create', {}, alice);
assert.strictEqual(res.status, 400);
});
test('SVGファイルを作成できる', async () => {
const res = await uploadFile(alice, { path: 'image.svg' });
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body!.name, 'image.svg');
assert.strictEqual(res.body!.type, 'image/svg+xml');
});
for (const type of ['webp', 'avif']) {
const mediaType = `image/${type}`;
const getWebpublicType = async (user: misskey.entities.SignupResponse, fileId: string): Promise<string> => {
// 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);
assert.strictEqual(res.body!.name, path);
assert.strictEqual(res.body!.type, mediaType);
const webpublicType = await getWebpublicType(alice, res.body!.id);
assert.strictEqual(webpublicType, 'image/webp');
});
test(`透明じゃない${type}ファイルを作成できる`, async () => {
const path = `without-alpha.${type}`;
const res = await uploadFile(alice, { path });
assert.strictEqual(res.status, 200);
assert.strictEqual(res.body!.name, path);
assert.strictEqual(res.body!.type, mediaType);
const webpublicType = await getWebpublicType(alice, res.body!.id);
assert.strictEqual(webpublicType, 'image/webp');
});
}
});
describe('drive/files/update', () => {
test('', async () => {
const file = (await uploadFile(alice)).body;
const newName = '.png';
const res = await api('drive/files/update', {
fileId: file!.id,
name: newName,
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.name, newName);
});
test('', async () => {
const file = (await uploadFile(alice)).body;
const res = await api('drive/files/update', {
fileId: file!.id,
name: '.png',
}, bob);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const file = (await uploadFile(alice)).body;
const folder = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const res = await api('drive/files/update', {
fileId: file!.id,
folderId: folder.id,
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.folderId, folder.id);
});
test('', async () => {
const file = (await uploadFile(alice)).body;
const folder = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
await api('drive/files/update', {
fileId: file!.id,
folderId: folder.id,
}, alice);
const res = await api('drive/files/update', {
fileId: file!.id,
folderId: null,
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.folderId, null);
});
test('', async () => {
const file = (await uploadFile(alice)).body;
const folder = (await api('drive/folders/create', {
name: 'test',
}, bob)).body;
const res = await api('drive/files/update', {
fileId: file!.id,
folderId: folder.id,
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const file = (await uploadFile(alice)).body;
const res = await api('drive/files/update', {
fileId: file!.id,
folderId: '000000000000000000000000',
}, alice);
assert.strictEqual(res.status, 400);
});
test('IDで怒られる', async () => {
const file = (await uploadFile(alice)).body;
const res = await api('drive/files/update', {
fileId: file!.id,
folderId: 'foo',
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const res = await api('drive/files/update', {
fileId: '000000000000000000000000',
name: '.png',
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const file = (await uploadFile(alice)).body;
const newName = '';
const res = await api('drive/files/update', {
fileId: file!.id,
name: newName,
}, alice);
assert.strictEqual(res.status, 400);
});
test('IDで怒られる', async () => {
const res = await api('drive/files/update', {
fileId: 'kyoppie',
name: '.png',
}, alice);
assert.strictEqual(res.status, 400);
});
});
describe('drive/folders/create', () => {
test('', async () => {
const res = await api('drive/folders/create', {
name: 'test',
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.name, 'test');
});
});
describe('drive/folders/update', () => {
test('', async () => {
const folder = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const res = await api('drive/folders/update', {
folderId: folder.id,
name: 'new name',
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.name, 'new name');
});
test('', async () => {
const folder = (await api('drive/folders/create', {
name: 'test',
}, bob)).body;
const res = await api('drive/folders/update', {
folderId: folder.id,
name: 'new name',
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const folder = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const parentFolder = (await api('drive/folders/create', {
name: 'parent',
}, alice)).body;
const res = await api('drive/folders/update', {
folderId: folder.id,
parentId: parentFolder.id,
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.parentId, parentFolder.id);
});
test('', async () => {
const folder = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const parentFolder = (await api('drive/folders/create', {
name: 'parent',
}, alice)).body;
await api('drive/folders/update', {
folderId: folder.id,
parentId: parentFolder.id,
}, alice);
const res = await api('drive/folders/update', {
folderId: folder.id,
parentId: null,
}, alice);
assert.strictEqual(res.status, 200);
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
assert.strictEqual(res.body.parentId, null);
});
test('', async () => {
const folder = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const parentFolder = (await api('drive/folders/create', {
name: 'parent',
}, bob)).body;
const res = await api('drive/folders/update', {
folderId: folder.id,
parentId: parentFolder.id,
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const folder = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const parentFolder = (await api('drive/folders/create', {
name: 'parent',
}, alice)).body;
await api('drive/folders/update', {
folderId: parentFolder.id,
parentId: folder.id,
}, alice);
const res = await api('drive/folders/update', {
folderId: folder.id,
parentId: parentFolder.id,
}, alice);
assert.strictEqual(res.status, 400);
});
test('()', async () => {
const folderA = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const folderB = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const folderC = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
await api('drive/folders/update', {
folderId: folderB.id,
parentId: folderA.id,
}, alice);
await api('drive/folders/update', {
folderId: folderC.id,
parentId: folderB.id,
}, alice);
const res = await api('drive/folders/update', {
folderId: folderA.id,
parentId: folderC.id,
}, alice);
assert.strictEqual(res.status, 400);
});
test('()', async () => {
const folderA = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const res = await api('drive/folders/update', {
folderId: folderA.id,
parentId: folderA.id,
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const folder = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const res = await api('drive/folders/update', {
folderId: folder.id,
parentId: '000000000000000000000000',
}, alice);
assert.strictEqual(res.status, 400);
});
test('IDで怒られる', async () => {
const folder = (await api('drive/folders/create', {
name: 'test',
}, alice)).body;
const res = await api('drive/folders/update', {
folderId: folder.id,
parentId: 'foo',
}, alice);
assert.strictEqual(res.status, 400);
});
test('', async () => {
const res = await api('drive/folders/update', {
folderId: '000000000000000000000000',
}, alice);
assert.strictEqual(res.status, 400);
});
test('IDで怒られる', async () => {
const res = await api('drive/folders/update', {
folderId: 'foo',
}, alice);
assert.strictEqual(res.status, 400);
});
});
describe('notes/replies', () => {
test('稿', async () => {
const alicePost = await post(alice, {
text: 'foo',
});
await post(bob, {
replyId: alicePost.id,
text: 'bar',
visibility: 'specified',
visibleUserIds: [alice.id],
});
const res = await api('notes/replies', {
noteId: alicePost.id,
}, carol);
assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
assert.strictEqual(res.body.length, 0);
});
});
describe('notes/timeline', () => {
test('稿', async () => {
await api('following/create', {
userId: carol.id,
}, dave);
const carolPost = await post(carol, {
text: 'foo',
visibility: 'followers',
});
const res = await api('notes/timeline', {}, dave);
assert.strictEqual(res.status, 200);
assert.strictEqual(Array.isArray(res.body), true);
assert.strictEqual(res.body.length, 1);
assert.strictEqual(res.body[0].id, carolPost.id);
});
});
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');
});
});
describe('パーソナルメモ機能のテスト', () => {
test('他者に関するメモを更新できる', async () => {
const memo = '10月まで低浮上とのこと。';
const res1 = await api('users/update-memo', {
memo,
userId: bob.id,
}, alice);
const res2 = await api('users/show', {
userId: bob.id,
}, alice);
assert.strictEqual(res1.status, 204);
assert.strictEqual((res2.body as unknown as { memo: string })?.memo, memo);
});
test('自分に関するメモを更新できる', async () => {
const memo = 'チケットを月末までに買う。';
const res1 = await api('users/update-memo', {
memo,
userId: alice.id,
}, alice);
const res2 = await api('users/show', {
userId: alice.id,
}, alice);
assert.strictEqual(res1.status, 204);
assert.strictEqual((res2.body as unknown as { memo: string })?.memo, memo);
});
test('メモを削除できる', async () => {
const memo = '10月まで低浮上とのこと。';
await api('users/update-memo', {
memo,
userId: bob.id,
}, alice);
await api('users/update-memo', {
memo: '',
userId: bob.id,
}, alice);
const res = await api('users/show', {
userId: bob.id,
}, alice);
// memoには常に文字列かnullが入っている(5cac151)
assert.strictEqual((res.body as unknown as { memo: string | null }).memo, null);
});
test('メモは個人ごとに独立して保存される', async () => {
const memoAliceToBob = '10月まで低浮上とのこと。';
const memoCarolToBob = '例の件について今度問いただす。';
await Promise.all([
api('users/update-memo', {
memo: memoAliceToBob,
userId: bob.id,
}, alice),
api('users/update-memo', {
memo: memoCarolToBob,
userId: bob.id,
}, carol),
]);
const [resAlice, resCarol] = await Promise.all([
api('users/show', {
userId: bob.id,
}, alice),
api('users/show', {
userId: bob.id,
}, carol),
]);
assert.strictEqual((resAlice.body as unknown as { memo: string }).memo, memoAliceToBob);
assert.strictEqual((resCarol.body as unknown as { memo: string }).memo, memoCarolToBob);
});
});
});