2022-02-19 06:05:32 +01:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
|
|
|
import * as childProcess from 'child_process';
|
2022-09-17 20:27:08 +02:00
|
|
|
import * as openapi from '@redocly/openapi-core';
|
|
|
|
import { startServer, signup, post, request, simpleGet, port, shutdownServer, api } from '../utils.js';
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
describe('Endpoints', () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
let p: childProcess.ChildProcess;
|
2022-09-17 20:27:08 +02:00
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
beforeAll(async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
p = await startServer();
|
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
2022-09-17 20:27:08 +02:00
|
|
|
}, 1000 * 30);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
afterAll(async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
await shutdownServer(p);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('signup', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正なユーザー名でアカウントが作成できない', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await request('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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await request('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
|
|
|
};
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await request('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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await request('api/signup', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await request('api/signin', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await request('api/signin', {
|
|
|
|
username: 'test1',
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await request('api/signin', {
|
|
|
|
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';
|
|
|
|
|
2022-09-17 20:27:08 +02: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-02-02 10:18:25 +01:00
|
|
|
test('名前を空白にできない', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/i/update', {
|
|
|
|
name: ' ',
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
await api('/i/update', {
|
|
|
|
birthday: '2000-09-07',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/i/update', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/i/update', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/users/show', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/users/show', {
|
|
|
|
userId: '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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/users/show', {
|
|
|
|
userId: '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/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
|
|
|
});
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/notes/show', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/notes/show', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/notes/show', {
|
|
|
|
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 () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const bobPost = await post(bob);
|
|
|
|
|
|
|
|
const alice = await signup({ username: 'alice' });
|
2022-09-17 20:27:08 +02: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
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const resNote = await api('/notes/show', {
|
2022-02-27 06:14:27 +01:00
|
|
|
noteId: bobPost.id,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(resNote.status, 200);
|
|
|
|
assert.strictEqual(resNote.body.reactions['🚀'], [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 () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const myPost = await post(alice);
|
|
|
|
|
2022-09-17 20:27:08 +02: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-02-02 10:18:25 +01:00
|
|
|
test('二重にリアクションできない', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const bobPost = await post(bob);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
await api('/notes/reactions/create', {
|
|
|
|
noteId: bobPost.id,
|
|
|
|
reaction: '🥰',
|
|
|
|
}, alice);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
2022-09-17 20:27:08 +02: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, 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-09-17 20:27:08 +02: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
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('空のパラメータで怒られる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02: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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/create', {
|
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
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-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/create', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/create', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/create', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/create', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
await api('/following/create', {
|
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/delete', {
|
|
|
|
userId: alice.id,
|
2022-02-19 06:05:32 +01:00
|
|
|
}, bob);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
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-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/delete', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/delete', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/delete', {
|
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
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 () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/following/delete', {
|
|
|
|
userId: 'kyoppie',
|
2022-02-19 06:05:32 +01:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
describe('/i', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
|
|
|
import * as childProcess from 'child_process';
|
|
|
|
import { async, signup, request, post, react, uploadFile, startServer, shutdownServer } from './utils.js';
|
|
|
|
|
|
|
|
describe('API: Endpoints', () => {
|
|
|
|
let p: childProcess.ChildProcess;
|
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
|
|
|
let carol: any;
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
p = await startServer();
|
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
|
|
|
carol = await signup({ username: 'carol' });
|
|
|
|
});
|
|
|
|
|
|
|
|
after(async () => {
|
|
|
|
await shutdownServer(p);
|
2022-02-19 06:05:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('drive', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ドライブ情報を取得できる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
await uploadFile({
|
|
|
|
userId: alice.id,
|
|
|
|
size: 256
|
|
|
|
});
|
|
|
|
await uploadFile({
|
|
|
|
userId: alice.id,
|
|
|
|
size: 512
|
|
|
|
});
|
|
|
|
await uploadFile({
|
|
|
|
userId: alice.id,
|
|
|
|
size: 1024
|
|
|
|
});
|
2022-09-17 20:27:08 +02: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);
|
|
|
|
expect(res.body).have.property('usage').eql(1792);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
assert.strictEqual(res.body.name, 'Lenna.png');
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ファイルに名前を付けられる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const res = await assert.request(server)
|
|
|
|
.post('/drive/files/create')
|
|
|
|
.field('i', alice.token)
|
|
|
|
.field('name', 'Belmond.png')
|
|
|
|
.attach('file', fs.readFileSync(__dirname + '/resources/Lenna.png'), 'Lenna.png');
|
|
|
|
|
|
|
|
expect(res).have.status(200);
|
|
|
|
expect(res.body).be.a('object');
|
|
|
|
expect(res.body).have.property('name').eql('Belmond.png');
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ファイル無しで怒られる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/create', {}, alice);
|
2022-02-19 06:05:32 +01:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('SVGファイルを作成できる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const res = await uploadFile(alice, __dirname + '/resources/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');
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('drive/files/update', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('名前を更新できる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const file = await uploadFile(alice);
|
|
|
|
const newName = 'いちごパスタ.png';
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
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);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('他人のファイルは更新できない', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const file = await uploadFile(bob);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
fileId: file.id,
|
|
|
|
name: 'いちごパスタ.png'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('親フォルダを更新できる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const file = await uploadFile(alice);
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
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);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('親フォルダを無しにできる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const file = await uploadFile(alice);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
fileId: file.id,
|
|
|
|
folderId: folder.id
|
|
|
|
}, alice);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
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);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('他人のフォルダには入れられない', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const file = await uploadFile(alice);
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, bob)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
fileId: file.id,
|
|
|
|
folderId: folder.id
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しないフォルダで怒られる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const file = await uploadFile(alice);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
fileId: file.id,
|
|
|
|
folderId: '000000000000000000000000'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正なフォルダIDで怒られる', async () => {
|
2022-02-19 06:05:32 +01:00
|
|
|
const file = await uploadFile(alice);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
fileId: file.id,
|
|
|
|
folderId: 'foo'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('ファイルが存在しなかったら怒る', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
fileId: '000000000000000000000000',
|
|
|
|
name: 'いちごパスタ.png'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('間違ったIDで怒られる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/files/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
fileId: 'kyoppie',
|
|
|
|
name: 'いちごパスタ.png'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('drive/folders/create', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォルダを作成できる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
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', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('名前を更新できる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
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');
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('他人のフォルダを更新できない', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, bob)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
|
|
|
name: 'new name'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('親フォルダを更新できる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
2022-09-17 20:27:08 +02:00
|
|
|
const parentFolder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'parent'
|
|
|
|
}, alice)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
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);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('親フォルダを無しに更新できる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
2022-09-17 20:27:08 +02:00
|
|
|
const parentFolder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'parent'
|
|
|
|
}, alice)).body;
|
2022-09-17 20:27:08 +02:00
|
|
|
await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
|
|
|
parentId: parentFolder.id
|
|
|
|
}, alice);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
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);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('他人のフォルダを親フォルダに設定できない', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
2022-09-17 20:27:08 +02:00
|
|
|
const parentFolder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'parent'
|
|
|
|
}, bob)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
|
|
|
parentId: parentFolder.id
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォルダが循環するような構造にできない', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
2022-09-17 20:27:08 +02:00
|
|
|
const parentFolder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'parent'
|
|
|
|
}, alice)).body;
|
2022-09-17 20:27:08 +02:00
|
|
|
await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: parentFolder.id,
|
|
|
|
parentId: folder.id
|
|
|
|
}, alice);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
|
|
|
parentId: parentFolder.id
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォルダが循環するような構造にできない(再帰的)', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folderA = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
2022-09-17 20:27:08 +02:00
|
|
|
const folderB = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
2022-09-17 20:27:08 +02:00
|
|
|
const folderC = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
2022-09-17 20:27:08 +02:00
|
|
|
await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folderB.id,
|
|
|
|
parentId: folderA.id
|
|
|
|
}, alice);
|
2022-09-17 20:27:08 +02:00
|
|
|
await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folderC.id,
|
|
|
|
parentId: folderB.id
|
|
|
|
}, alice);
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folderA.id,
|
|
|
|
parentId: folderC.id
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォルダが循環するような構造にできない(自身)', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folderA = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folderA.id,
|
|
|
|
parentId: folderA.id
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しない親フォルダを設定できない', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
|
|
|
parentId: '000000000000000000000000'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正な親フォルダIDで怒られる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const folder = (await api('/drive/folders/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
name: 'test'
|
|
|
|
}, alice)).body;
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: folder.id,
|
|
|
|
parentId: 'foo'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しないフォルダを更新できない', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: '000000000000000000000000'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正なフォルダIDで怒られる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/drive/folders/update', {
|
2022-02-19 06:05:32 +01:00
|
|
|
folderId: 'foo'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('messaging/messages/create', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('メッセージを送信できる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/messaging/messages/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
userId: bob.id,
|
|
|
|
text: 'test'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.text, 'test');
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('自分自身にはメッセージを送信できない', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/messaging/messages/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
userId: alice.id,
|
|
|
|
text: 'Yo'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('存在しないユーザーにはメッセージを送信できない', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/messaging/messages/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
userId: '000000000000000000000000',
|
|
|
|
text: 'test'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('不正なユーザーIDで怒られる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/messaging/messages/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
userId: 'foo',
|
|
|
|
text: 'test'
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('テキストが無くて怒られる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/messaging/messages/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
userId: bob.id
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 10:18:25 +01:00
|
|
|
test('文字数オーバーで怒られる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/messaging/messages/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
userId: bob.id,
|
|
|
|
text: '!'.repeat(1001)
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
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, {
|
|
|
|
text: 'foo'
|
|
|
|
});
|
|
|
|
|
|
|
|
await post(bob, {
|
|
|
|
replyId: alicePost.id,
|
|
|
|
text: 'bar',
|
|
|
|
visibility: 'specified',
|
|
|
|
visibleUserIds: [alice.id]
|
|
|
|
});
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/notes/replies', {
|
2022-02-19 06:05:32 +01:00
|
|
|
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', () => {
|
2023-02-02 10:18:25 +01:00
|
|
|
test('フォロワー限定投稿が含まれる', async () => {
|
2022-09-17 20:27:08 +02:00
|
|
|
await api('/following/create', {
|
2022-02-19 06:05:32 +01:00
|
|
|
userId: alice.id
|
|
|
|
}, bob);
|
|
|
|
|
|
|
|
const alicePost = await post(alice, {
|
|
|
|
text: 'foo',
|
|
|
|
visibility: 'followers'
|
|
|
|
});
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
const res = await api('/notes/timeline', {}, bob);
|
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);
|
|
|
|
assert.strictEqual(res.body[0].id, alicePost.id);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
*/
|