15005c4266
# Conflicts: # .config/docker_example.env # .config/docker_example.yml # CHANGELOG.md # locales/index.d.ts # locales/ja-JP.yml # packages/backend/package.json # packages/backend/src/core/entities/UserEntityService.ts # packages/backend/src/server/api/endpoints/i/update.ts # packages/frontend/package.json # packages/frontend/src/components/MkChannelFollowButton.vue # packages/frontend/src/components/MkFollowButton.vue # packages/frontend/src/components/MkMediaAudio.vue # packages/frontend/src/components/MkMenu.vue # packages/frontend/src/components/MkNote.vue # packages/frontend/src/components/MkNoteDetailed.vue # packages/frontend/src/components/MkPostForm.vue # packages/frontend/src/components/MkRadio.vue # packages/frontend/src/components/MkSuperMenu.vue # packages/frontend/src/components/MkSwitch.vue # packages/frontend/src/components/MkVisitorDashboard.vue # packages/frontend/src/os.ts # packages/frontend/src/pages/about.vue # packages/frontend/src/pages/admin/roles.editor.vue # packages/frontend/src/pages/admin/roles.vue # packages/frontend/src/pages/custom-emojis-manager.vue # packages/frontend/src/pages/follow.vue # packages/frontend/src/pages/timeline.vue # packages/frontend/src/pages/user/home.vue # packages/frontend/src/scripts/get-note-menu.ts # packages/frontend/src/scripts/keycode.ts # packages/frontend/src/ui/_common_/navbar-for-mobile.vue # packages/frontend/src/ui/_common_/navbar.vue # pnpm-lock.yaml
86 lines
2.9 KiB
TypeScript
86 lines
2.9 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project , Type4ny-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
import * as assert from 'assert';
|
|
import { api, makeStreamCatcher, post, signup, uploadFile } from '../utils.js';
|
|
import type * as misskey from 'misskey-js';
|
|
|
|
describe('Drive', () => {
|
|
let alice: misskey.entities.SignupResponse;
|
|
let bob: misskey.entities.SignupResponse;
|
|
|
|
beforeAll(async () => {
|
|
alice = await signup({ username: 'alice' });
|
|
bob = await signup({ username: 'bob' });
|
|
}, 1000 * 60 * 2);
|
|
|
|
test('ファイルURLからアップロードできる', async () => {
|
|
// utils.js uploadUrl の処理だがAPIレスポンスも見るためここで同様の処理を書いている
|
|
|
|
const marker = Math.random().toString();
|
|
|
|
const url = 'https://raw.githubusercontent.com/misskey-dev/misskey/develop/packages/backend/test/resources/192.jpg';
|
|
|
|
const catcher = makeStreamCatcher(
|
|
alice,
|
|
'main',
|
|
(msg) => msg.type === 'urlUploadFinished' && msg.body.marker === marker,
|
|
(msg) => msg.body.file,
|
|
10 * 1000);
|
|
|
|
const res = await api('drive/files/upload-from-url', {
|
|
url,
|
|
marker,
|
|
force: true,
|
|
}, alice);
|
|
|
|
const file = await catcher;
|
|
|
|
assert.strictEqual(res.status, 204);
|
|
assert.strictEqual(file.name, '192.jpg');
|
|
assert.strictEqual(file.type, 'image/jpeg');
|
|
});
|
|
|
|
test('ローカルからアップロードできる', async () => {
|
|
// APIレスポンスを直接使用するので utils.js uploadFile が通過することで成功とする
|
|
|
|
const res = await uploadFile(alice, { path: '192.jpg', name: 'テスト画像' });
|
|
|
|
assert.strictEqual(res.body?.name, 'テスト画像.jpg');
|
|
assert.strictEqual(res.body.type, 'image/jpeg');
|
|
});
|
|
|
|
test('添付ノート一覧を取得できる', async () => {
|
|
const ids = (await Promise.all([uploadFile(alice), uploadFile(alice), uploadFile(alice)])).map(elm => elm.body!.id);
|
|
|
|
const note0 = await post(alice, { fileIds: [ids[0]] });
|
|
const note1 = await post(alice, { fileIds: [ids[0], ids[1]] });
|
|
|
|
const attached0 = await api('drive/files/attached-notes', { fileId: ids[0] }, alice);
|
|
assert.strictEqual(attached0.body.length, 2);
|
|
assert.strictEqual(attached0.body[0].id, note1.id);
|
|
assert.strictEqual(attached0.body[1].id, note0.id);
|
|
|
|
const attached1 = await api('drive/files/attached-notes', { fileId: ids[1] }, alice);
|
|
assert.strictEqual(attached1.body.length, 1);
|
|
assert.strictEqual(attached1.body[0].id, note1.id);
|
|
|
|
const attached2 = await api('drive/files/attached-notes', { fileId: ids[2] }, alice);
|
|
assert.strictEqual(attached2.body.length, 0);
|
|
});
|
|
|
|
test('添付ノート一覧は他の人から見えない', async () => {
|
|
const file = await uploadFile(alice);
|
|
|
|
await post(alice, { fileIds: [file.body!.id] });
|
|
|
|
const res = await api('drive/files/attached-notes', { fileId: file.body!.id }, bob);
|
|
assert.strictEqual(res.status, 400);
|
|
assert.strictEqual('error' in res.body, true);
|
|
});
|
|
});
|