2019-04-07 07:50:36 -05:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
2023-03-02 20:13:12 -06:00
|
|
|
import { Note } from '@/models/entities/Note.js';
|
2023-03-04 01:48:50 -06:00
|
|
|
import { signup, post, uploadUrl, startServer, initTestDb, api, uploadFile } from '../utils.js';
|
2023-03-02 20:13:12 -06:00
|
|
|
import type { INestApplicationContext } from '@nestjs/common';
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
describe('Note', () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
let p: INestApplicationContext;
|
2019-04-07 07:50:36 -05:00
|
|
|
let Notes: any;
|
|
|
|
|
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
|
|
|
|
2022-09-17 13:27:08 -05:00
|
|
|
beforeAll(async () => {
|
2021-06-12 08:40:17 -05:00
|
|
|
p = await startServer();
|
|
|
|
const connection = await initTestDb(true);
|
2020-01-08 23:35:04 -06:00
|
|
|
Notes = connection.getRepository(Note);
|
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
2023-03-02 20:13:12 -06:00
|
|
|
}, 1000 * 60 * 2);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2022-09-17 13:27:08 -05:00
|
|
|
afterAll(async () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
await p.close();
|
2019-04-07 07:50:36 -05:00
|
|
|
});
|
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('投稿できる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const post = {
|
2022-05-21 08:21:41 -05:00
|
|
|
text: 'test',
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', post, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.createdNote.text, post.text);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('ファイルを添付できる', async () => {
|
2022-06-26 05:16:32 -05:00
|
|
|
const file = await uploadUrl(alice, 'https://raw.githubusercontent.com/misskey-dev/misskey/develop/packages/backend/test/resources/Lenna.jpg');
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', {
|
2022-05-21 08:21:41 -05:00
|
|
|
fileIds: [file.id],
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.deepStrictEqual(res.body.createdNote.fileIds, [file.id]);
|
2022-09-17 13:27:08 -05:00
|
|
|
}, 1000 * 10);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
test('他人のファイルで怒られる', async () => {
|
2022-06-26 05:16:32 -05:00
|
|
|
const file = await uploadUrl(bob, 'https://raw.githubusercontent.com/misskey-dev/misskey/develop/packages/backend/test/resources/Lenna.jpg');
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', {
|
2019-04-07 07:50:36 -05:00
|
|
|
text: 'test',
|
2022-05-21 08:21:41 -05:00
|
|
|
fileIds: [file.id],
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
assert.strictEqual(res.body.error.code, 'NO_SUCH_FILE');
|
|
|
|
assert.strictEqual(res.body.error.id, 'b6992544-63e7-67f0-fa7f-32444b1b5306');
|
2022-09-17 13:27:08 -05:00
|
|
|
}, 1000 * 10);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
test('存在しないファイルで怒られる', async () => {
|
|
|
|
const res = await api('/notes/create', {
|
2019-04-07 07:50:36 -05:00
|
|
|
text: 'test',
|
2022-05-21 08:21:41 -05:00
|
|
|
fileIds: ['000000000000000000000000'],
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
assert.strictEqual(res.body.error.code, 'NO_SUCH_FILE');
|
|
|
|
assert.strictEqual(res.body.error.id, 'b6992544-63e7-67f0-fa7f-32444b1b5306');
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
test('不正なファイルIDで怒られる', async () => {
|
|
|
|
const res = await api('/notes/create', {
|
2022-05-21 08:21:41 -05:00
|
|
|
fileIds: ['kyoppie'],
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
2023-03-02 20:13:12 -06:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
assert.strictEqual(res.body.error.code, 'NO_SUCH_FILE');
|
|
|
|
assert.strictEqual(res.body.error.id, 'b6992544-63e7-67f0-fa7f-32444b1b5306');
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('返信できる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const bobPost = await post(bob, {
|
2022-05-21 08:21:41 -05:00
|
|
|
text: 'foo',
|
2019-04-07 07:50:36 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const alicePost = {
|
|
|
|
text: 'bar',
|
2022-05-21 08:21:41 -05:00
|
|
|
replyId: bobPost.id,
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', alicePost, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.createdNote.text, alicePost.text);
|
|
|
|
assert.strictEqual(res.body.createdNote.replyId, alicePost.replyId);
|
|
|
|
assert.strictEqual(res.body.createdNote.reply.text, bobPost.text);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('renoteできる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const bobPost = await post(bob, {
|
2022-05-21 08:21:41 -05:00
|
|
|
text: 'test',
|
2019-04-07 07:50:36 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const alicePost = {
|
2022-05-21 08:21:41 -05:00
|
|
|
renoteId: bobPost.id,
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', alicePost, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.createdNote.renoteId, alicePost.renoteId);
|
|
|
|
assert.strictEqual(res.body.createdNote.renote.text, bobPost.text);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('引用renoteできる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const bobPost = await post(bob, {
|
2022-05-21 08:21:41 -05:00
|
|
|
text: 'test',
|
2019-04-07 07:50:36 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const alicePost = {
|
|
|
|
text: 'test',
|
2022-05-21 08:21:41 -05:00
|
|
|
renoteId: bobPost.id,
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', alicePost, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.createdNote.text, alicePost.text);
|
|
|
|
assert.strictEqual(res.body.createdNote.renoteId, alicePost.renoteId);
|
|
|
|
assert.strictEqual(res.body.createdNote.renote.text, bobPost.text);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-03-11 21:11:37 -06:00
|
|
|
test('visibility: followersでrenoteできる', async () => {
|
|
|
|
const createRes = await api('/notes/create', {
|
|
|
|
text: 'test',
|
|
|
|
visibility: 'followers',
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(createRes.status, 200);
|
|
|
|
|
|
|
|
const renoteId = createRes.body.createdNote.id;
|
|
|
|
const renoteRes = await api('/notes/create', {
|
|
|
|
visibility: 'followers',
|
|
|
|
renoteId,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(renoteRes.status, 200);
|
|
|
|
assert.strictEqual(renoteRes.body.createdNote.renoteId, renoteId);
|
|
|
|
assert.strictEqual(renoteRes.body.createdNote.visibility, 'followers');
|
|
|
|
|
|
|
|
const deleteRes = await api('/notes/delete', {
|
|
|
|
noteId: renoteRes.body.createdNote.id,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(deleteRes.status, 204);
|
|
|
|
});
|
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('文字数ぎりぎりで怒られない', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const post = {
|
2022-06-26 05:16:32 -05:00
|
|
|
text: '!'.repeat(3000),
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', post, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
assert.strictEqual(res.status, 200);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('文字数オーバーで怒られる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const post = {
|
2022-06-26 05:16:32 -05:00
|
|
|
text: '!'.repeat(3001),
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', post, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('存在しないリプライ先で怒られる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const post = {
|
|
|
|
text: 'test',
|
2022-05-21 08:21:41 -05:00
|
|
|
replyId: '000000000000000000000000',
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', post, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('存在しないrenote対象で怒られる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const post = {
|
2022-05-21 08:21:41 -05:00
|
|
|
renoteId: '000000000000000000000000',
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', post, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('不正なリプライ先IDで怒られる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const post = {
|
|
|
|
text: 'test',
|
2022-05-21 08:21:41 -05:00
|
|
|
replyId: 'foo',
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', post, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('不正なrenote対象IDで怒られる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const post = {
|
2022-05-21 08:21:41 -05:00
|
|
|
renoteId: 'foo',
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', post, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('存在しないユーザーにメンションできる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const post = {
|
2022-05-21 08:21:41 -05:00
|
|
|
text: '@ghost yo',
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', post, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.createdNote.text, post.text);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('同じユーザーに複数メンションしても内部的にまとめられる', async () => {
|
2019-04-07 07:50:36 -05:00
|
|
|
const post = {
|
2022-05-21 08:21:41 -05:00
|
|
|
text: '@bob @bob @bob yo',
|
2019-04-07 07:50:36 -05:00
|
|
|
};
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', post, alice);
|
2019-04-07 07:50:36 -05:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.createdNote.text, post.text);
|
|
|
|
|
2022-06-26 05:16:32 -05:00
|
|
|
const noteDoc = await Notes.findOneBy({ id: res.body.createdNote.id });
|
2019-04-07 07:50:36 -05:00
|
|
|
assert.deepStrictEqual(noteDoc.mentions, [bob.id]);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-03-04 01:48:50 -06:00
|
|
|
describe('添付ファイル情報', () => {
|
|
|
|
test('ファイルを添付した場合、投稿成功時にファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
const file = await uploadFile(alice);
|
|
|
|
const res = await api('/notes/create', {
|
|
|
|
fileIds: [file.body.id],
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.createdNote.files.length, 1);
|
|
|
|
assert.strictEqual(res.body.createdNote.files[0].id, file.body.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('ファイルを添付した場合、タイムラインでファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
const file = await uploadFile(alice);
|
|
|
|
const createdNote = await api('/notes/create', {
|
|
|
|
fileIds: [file.body.id],
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(createdNote.status, 200);
|
|
|
|
|
|
|
|
const res = await api('/notes', {
|
|
|
|
withFiles: true,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
const myNote = res.body.find((note: { id: string; files: { id: string }[] }) => note.id === createdNote.body.createdNote.id);
|
|
|
|
assert.notEqual(myNote, null);
|
|
|
|
assert.strictEqual(myNote.files.length, 1);
|
|
|
|
assert.strictEqual(myNote.files[0].id, file.body.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('ファイルが添付されたノートをリノートした場合、タイムラインでファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
const file = await uploadFile(alice);
|
|
|
|
const createdNote = await api('/notes/create', {
|
|
|
|
fileIds: [file.body.id],
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(createdNote.status, 200);
|
|
|
|
|
|
|
|
const renoted = await api('/notes/create', {
|
|
|
|
renoteId: createdNote.body.createdNote.id,
|
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(renoted.status, 200);
|
|
|
|
|
|
|
|
const res = await api('/notes', {
|
|
|
|
renote: true,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
const myNote = res.body.find((note: { id: string }) => note.id === renoted.body.createdNote.id);
|
|
|
|
assert.notEqual(myNote, null);
|
|
|
|
assert.strictEqual(myNote.renote.files.length, 1);
|
|
|
|
assert.strictEqual(myNote.renote.files[0].id, file.body.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('ファイルが添付されたノートに返信した場合、タイムラインでファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
const file = await uploadFile(alice);
|
|
|
|
const createdNote = await api('/notes/create', {
|
|
|
|
fileIds: [file.body.id],
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(createdNote.status, 200);
|
|
|
|
|
|
|
|
const reply = await api('/notes/create', {
|
|
|
|
replyId: createdNote.body.createdNote.id,
|
|
|
|
text: 'this is reply',
|
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(reply.status, 200);
|
|
|
|
|
|
|
|
const res = await api('/notes', {
|
|
|
|
reply: true,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
const myNote = res.body.find((note: { id: string }) => note.id === reply.body.createdNote.id);
|
|
|
|
assert.notEqual(myNote, null);
|
|
|
|
assert.strictEqual(myNote.reply.files.length, 1);
|
|
|
|
assert.strictEqual(myNote.reply.files[0].id, file.body.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('ファイルが添付されたノートへの返信をリノートした場合、タイムラインでファイル情報入りのレスポンスが帰ってくる', async () => {
|
|
|
|
const file = await uploadFile(alice);
|
|
|
|
const createdNote = await api('/notes/create', {
|
|
|
|
fileIds: [file.body.id],
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(createdNote.status, 200);
|
|
|
|
|
|
|
|
const reply = await api('/notes/create', {
|
|
|
|
replyId: createdNote.body.createdNote.id,
|
|
|
|
text: 'this is reply',
|
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(reply.status, 200);
|
|
|
|
|
|
|
|
const renoted = await api('/notes/create', {
|
|
|
|
renoteId: reply.body.createdNote.id,
|
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(renoted.status, 200);
|
|
|
|
|
|
|
|
const res = await api('/notes', {
|
|
|
|
renote: true,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
const myNote = res.body.find((note: { id: string }) => note.id === renoted.body.createdNote.id);
|
|
|
|
assert.notEqual(myNote, null);
|
|
|
|
assert.strictEqual(myNote.renote.reply.files.length, 1);
|
|
|
|
assert.strictEqual(myNote.renote.reply.files[0].id, file.body.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-07 07:50:36 -05:00
|
|
|
describe('notes/create', () => {
|
2023-02-02 03:18:25 -06:00
|
|
|
test('投票を添付できる', async () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', {
|
2019-04-07 07:50:36 -05:00
|
|
|
text: 'test',
|
|
|
|
poll: {
|
2022-05-21 08:21:41 -05:00
|
|
|
choices: ['foo', 'bar'],
|
|
|
|
},
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(typeof res.body === 'object' && !Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.createdNote.poll != null, true);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('投票の選択肢が無くて怒られる', async () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', {
|
2022-05-21 08:21:41 -05:00
|
|
|
poll: {},
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('投票の選択肢が無くて怒られる (空の配列)', async () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', {
|
2019-04-07 07:50:36 -05:00
|
|
|
poll: {
|
2022-05-21 08:21:41 -05:00
|
|
|
choices: [],
|
|
|
|
},
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('投票の選択肢が1つで怒られる', async () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/create', {
|
2019-04-07 07:50:36 -05:00
|
|
|
poll: {
|
2022-05-21 08:21:41 -05:00
|
|
|
choices: ['Strawberry Pasta'],
|
|
|
|
},
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('投票できる', async () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
const { body } = await api('/notes/create', {
|
2019-04-07 07:50:36 -05:00
|
|
|
text: 'test',
|
|
|
|
poll: {
|
2022-05-21 08:21:41 -05:00
|
|
|
choices: ['sakura', 'izumi', 'ako'],
|
|
|
|
},
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/polls/vote', {
|
2019-04-07 07:50:36 -05:00
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 08:21:41 -05:00
|
|
|
choice: 1,
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('複数投票できない', async () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
const { body } = await api('/notes/create', {
|
2019-04-07 07:50:36 -05:00
|
|
|
text: 'test',
|
|
|
|
poll: {
|
2022-05-21 08:21:41 -05:00
|
|
|
choices: ['sakura', 'izumi', 'ako'],
|
|
|
|
},
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
await api('/notes/polls/vote', {
|
2019-04-07 07:50:36 -05:00
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 08:21:41 -05:00
|
|
|
choice: 0,
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/polls/vote', {
|
2019-04-07 07:50:36 -05:00
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 08:21:41 -05:00
|
|
|
choice: 2,
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('許可されている場合は複数投票できる', async () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
const { body } = await api('/notes/create', {
|
2019-04-07 07:50:36 -05:00
|
|
|
text: 'test',
|
|
|
|
poll: {
|
|
|
|
choices: ['sakura', 'izumi', 'ako'],
|
2022-05-21 08:21:41 -05:00
|
|
|
multiple: true,
|
|
|
|
},
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
await api('/notes/polls/vote', {
|
2019-04-07 07:50:36 -05:00
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 08:21:41 -05:00
|
|
|
choice: 0,
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
await api('/notes/polls/vote', {
|
2019-04-07 07:50:36 -05:00
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 08:21:41 -05:00
|
|
|
choice: 1,
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/polls/vote', {
|
2019-04-07 07:50:36 -05:00
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 08:21:41 -05:00
|
|
|
choice: 2,
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
|
2023-02-02 03:18:25 -06:00
|
|
|
test('締め切られている場合は投票できない', async () => {
|
2023-03-02 20:13:12 -06:00
|
|
|
const { body } = await api('/notes/create', {
|
2019-04-07 07:50:36 -05:00
|
|
|
text: 'test',
|
|
|
|
poll: {
|
|
|
|
choices: ['sakura', 'izumi', 'ako'],
|
2022-05-21 08:21:41 -05:00
|
|
|
expiredAfter: 1,
|
|
|
|
},
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
await new Promise(x => setTimeout(x, 2));
|
|
|
|
|
2023-03-02 20:13:12 -06:00
|
|
|
const res = await api('/notes/polls/vote', {
|
2019-04-07 07:50:36 -05:00
|
|
|
noteId: body.createdNote.id,
|
2022-05-21 08:21:41 -05:00
|
|
|
choice: 1,
|
2019-04-07 07:50:36 -05:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
});
|
2022-03-22 08:48:33 -05:00
|
|
|
|
|
|
|
describe('notes/delete', () => {
|
2023-02-02 03:18:25 -06:00
|
|
|
test('delete a reply', async () => {
|
2022-06-26 05:16:32 -05:00
|
|
|
const mainNoteRes = await api('notes/create', {
|
2022-03-22 08:48:33 -05:00
|
|
|
text: 'main post',
|
|
|
|
}, alice);
|
2022-06-26 05:16:32 -05:00
|
|
|
const replyOneRes = await api('notes/create', {
|
2022-03-22 08:48:33 -05:00
|
|
|
text: 'reply one',
|
2022-05-21 08:21:41 -05:00
|
|
|
replyId: mainNoteRes.body.createdNote.id,
|
2022-03-22 08:48:33 -05:00
|
|
|
}, alice);
|
2022-06-26 05:16:32 -05:00
|
|
|
const replyTwoRes = await api('notes/create', {
|
2022-03-22 08:48:33 -05:00
|
|
|
text: 'reply two',
|
2022-05-21 08:21:41 -05:00
|
|
|
replyId: mainNoteRes.body.createdNote.id,
|
2022-03-22 08:48:33 -05:00
|
|
|
}, alice);
|
|
|
|
|
2022-06-26 05:16:32 -05:00
|
|
|
const deleteOneRes = await api('notes/delete', {
|
2022-03-22 08:48:33 -05:00
|
|
|
noteId: replyOneRes.body.createdNote.id,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(deleteOneRes.status, 204);
|
2022-06-26 05:16:32 -05:00
|
|
|
let mainNote = await Notes.findOneBy({ id: mainNoteRes.body.createdNote.id });
|
2022-03-22 08:48:33 -05:00
|
|
|
assert.strictEqual(mainNote.repliesCount, 1);
|
|
|
|
|
2022-06-26 05:16:32 -05:00
|
|
|
const deleteTwoRes = await api('notes/delete', {
|
2022-03-22 08:48:33 -05:00
|
|
|
noteId: replyTwoRes.body.createdNote.id,
|
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(deleteTwoRes.status, 204);
|
2022-06-26 05:16:32 -05:00
|
|
|
mainNote = await Notes.findOneBy({ id: mainNoteRes.body.createdNote.id });
|
2022-03-22 08:48:33 -05:00
|
|
|
assert.strictEqual(mainNote.repliesCount, 0);
|
2022-09-17 13:27:08 -05:00
|
|
|
});
|
2022-03-22 08:48:33 -05:00
|
|
|
});
|
2019-04-07 07:50:36 -05:00
|
|
|
});
|