2024-01-15 00:19:27 +01:00
|
|
|
/*
|
2024-02-12 03:37:45 +01:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2024-01-15 00:19:27 +01:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
2024-03-03 12:15:35 +01:00
|
|
|
import { api, makeStreamCatcher, post, signup, uploadFile } from '../utils.js';
|
2024-01-15 00:19:27 +01:00
|
|
|
import type * as misskey from 'misskey-js';
|
|
|
|
|
|
|
|
describe('Drive', () => {
|
|
|
|
let alice: misskey.entities.SignupResponse;
|
|
|
|
let bob: misskey.entities.SignupResponse;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2024-02-24 13:32:10 +01:00
|
|
|
await sendEnvUpdateRequest({ key: 'FORCE_IGNORE_IDEMPOTENCY_FOR_TESTING', value: 'true' });
|
|
|
|
|
2024-01-15 00:19:27 +01:00
|
|
|
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();
|
|
|
|
|
2024-02-12 18:27:27 +01:00
|
|
|
const url = 'https://raw.githubusercontent.com/MisskeyIO/misskey/io/packages/backend/test/resources/Lenna.jpg';
|
2024-01-15 00:19:27 +01:00
|
|
|
|
|
|
|
const catcher = makeStreamCatcher(
|
|
|
|
alice,
|
|
|
|
'main',
|
|
|
|
(msg) => msg.type === 'urlUploadFinished' && msg.body.marker === marker,
|
2024-03-03 12:15:35 +01:00
|
|
|
(msg) => msg.body.file,
|
2024-01-15 00:19:27 +01:00
|
|
|
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, 'Lenna.jpg');
|
|
|
|
assert.strictEqual(file.type, 'image/jpeg');
|
2024-02-12 03:37:45 +01:00
|
|
|
});
|
2024-01-15 00:19:27 +01:00
|
|
|
|
|
|
|
test('ローカルからアップロードできる', async () => {
|
|
|
|
// APIレスポンスを直接使用するので utils.js uploadFile が通過することで成功とする
|
|
|
|
|
|
|
|
const res = await uploadFile(alice, { path: 'Lenna.jpg', name: 'テスト画像' });
|
|
|
|
|
|
|
|
assert.strictEqual(res.body?.name, 'テスト画像.jpg');
|
2024-02-12 03:37:45 +01:00
|
|
|
assert.strictEqual(res.body.type, 'image/jpeg');
|
|
|
|
});
|
2024-01-15 00:19:27 +01:00
|
|
|
|
|
|
|
test('添付ノート一覧を取得できる', async () => {
|
2024-02-12 03:37:45 +01:00
|
|
|
const ids = (await Promise.all([uploadFile(alice), uploadFile(alice), uploadFile(alice)])).map(elm => elm.body!.id);
|
2024-01-15 00:19:27 +01:00
|
|
|
|
|
|
|
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);
|
2024-02-12 03:37:45 +01:00
|
|
|
assert.strictEqual(attached0.body[0].id, note1.id);
|
|
|
|
assert.strictEqual(attached0.body[1].id, note0.id);
|
2024-01-15 00:19:27 +01:00
|
|
|
|
|
|
|
const attached1 = await api('drive/files/attached-notes', { fileId: ids[1] }, alice);
|
|
|
|
assert.strictEqual(attached1.body.length, 1);
|
2024-02-12 03:37:45 +01:00
|
|
|
assert.strictEqual(attached1.body[0].id, note1.id);
|
2024-01-15 00:19:27 +01:00
|
|
|
|
|
|
|
const attached2 = await api('drive/files/attached-notes', { fileId: ids[2] }, alice);
|
2024-02-12 03:37:45 +01:00
|
|
|
assert.strictEqual(attached2.body.length, 0);
|
|
|
|
});
|
2024-01-15 00:19:27 +01:00
|
|
|
|
|
|
|
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);
|
2024-02-12 03:37:45 +01:00
|
|
|
});
|
2024-01-15 00:19:27 +01:00
|
|
|
});
|