2023-04-07 01:56:46 +00:00
|
|
|
process.env.NODE_ENV = "test";
|
|
|
|
|
|
|
|
import * as assert from "assert";
|
|
|
|
import * as childProcess from "child_process";
|
|
|
|
import { Note } from "../src/models/entities/note.js";
|
|
|
|
import {
|
|
|
|
async,
|
|
|
|
signup,
|
|
|
|
request,
|
|
|
|
post,
|
|
|
|
uploadUrl,
|
|
|
|
startServer,
|
|
|
|
shutdownServer,
|
|
|
|
initTestDb,
|
|
|
|
api,
|
|
|
|
} from "./utils.js";
|
|
|
|
|
|
|
|
describe("Note", () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
let p: childProcess.ChildProcess;
|
|
|
|
let Notes: any;
|
|
|
|
|
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
|
|
|
|
2021-06-12 13:40:17 +00:00
|
|
|
before(async () => {
|
|
|
|
p = await startServer();
|
|
|
|
const connection = await initTestDb(true);
|
2020-01-09 05:35:04 +00:00
|
|
|
Notes = connection.getRepository(Note);
|
2023-04-07 01:56:46 +00:00
|
|
|
alice = await signup({ username: "alice" });
|
|
|
|
bob = await signup({ username: "bob" });
|
2021-06-12 13:40:17 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2021-06-05 05:54:07 +00:00
|
|
|
after(async () => {
|
|
|
|
await shutdownServer(p);
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("投稿できる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "test",
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", post, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.body.createdNote.text, post.text);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("ファイルを添付できる", async(async () => {
|
|
|
|
const file = await uploadUrl(
|
|
|
|
alice,
|
|
|
|
"https://raw.githubusercontent.com/misskey-dev/misskey/develop/packages/backend/test/resources/Lenna.jpg",
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
fileIds: [file.id],
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.deepStrictEqual(res.body.createdNote.fileIds, [file.id]);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("他人のファイルは無視", async(async () => {
|
|
|
|
const file = await uploadUrl(
|
|
|
|
bob,
|
|
|
|
"https://raw.githubusercontent.com/misskey-dev/misskey/develop/packages/backend/test/resources/Lenna.jpg",
|
|
|
|
);
|
|
|
|
|
|
|
|
const res = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
text: "test",
|
|
|
|
fileIds: [file.id],
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.deepStrictEqual(res.body.createdNote.fileIds, []);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("存在しないファイルは無視", async(async () => {
|
|
|
|
const res = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
text: "test",
|
|
|
|
fileIds: ["000000000000000000000000"],
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.deepStrictEqual(res.body.createdNote.fileIds, []);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("不正なファイルIDは無視", async(async () => {
|
|
|
|
const res = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
fileIds: ["kyoppie"],
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2022-06-26 10:16:32 +00:00
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2022-06-26 10:16:32 +00:00
|
|
|
assert.deepStrictEqual(res.body.createdNote.fileIds, []);
|
2019-04-07 12:50:36 +00:00
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("返信できる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const bobPost = await post(bob, {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "foo",
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const alicePost = {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "bar",
|
2022-05-21 13:21:41 +00:00
|
|
|
replyId: bobPost.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", alicePost, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
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);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("renoteできる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const bobPost = await post(bob, {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "test",
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const alicePost = {
|
2022-05-21 13:21:41 +00:00
|
|
|
renoteId: bobPost.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", alicePost, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.body.createdNote.renoteId, alicePost.renoteId);
|
|
|
|
assert.strictEqual(res.body.createdNote.renote.text, bobPost.text);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("引用renoteできる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const bobPost = await post(bob, {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "test",
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const alicePost = {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "test",
|
2022-05-21 13:21:41 +00:00
|
|
|
renoteId: bobPost.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", alicePost, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
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);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("文字数ぎりぎりで怒られない", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "!".repeat(3000),
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", post, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("文字数オーバーで怒られる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "!".repeat(3001),
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", post, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("存在しないリプライ先で怒られる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "test",
|
|
|
|
replyId: "000000000000000000000000",
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", post, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("存在しないrenote対象で怒られる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
renoteId: "000000000000000000000000",
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", post, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("不正なリプライ先IDで怒られる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "test",
|
|
|
|
replyId: "foo",
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", post, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("不正なrenote対象IDで怒られる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
renoteId: "foo",
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", post, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("存在しないユーザーにメンションできる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "@ghost yo",
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", post, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.body.createdNote.text, post.text);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("同じユーザーに複数メンションしても内部的にまとめられる", async(async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const post = {
|
2023-04-07 01:56:46 +00:00
|
|
|
text: "@bob @bob @bob yo",
|
2019-04-07 12:50:36 +00:00
|
|
|
};
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request("/notes/create", post, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.body.createdNote.text, post.text);
|
|
|
|
|
2022-06-26 10:16:32 +00:00
|
|
|
const noteDoc = await Notes.findOneBy({ id: res.body.createdNote.id });
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.deepStrictEqual(noteDoc.mentions, [bob.id]);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
describe("notes/create", () => {
|
|
|
|
it("投票を添付できる", async(async () => {
|
|
|
|
const res = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
text: "test",
|
|
|
|
poll: {
|
|
|
|
choices: ["foo", "bar"],
|
|
|
|
},
|
2022-05-21 13:21:41 +00:00
|
|
|
},
|
2023-04-07 01:56:46 +00:00
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
2023-04-07 01:56:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof res.body === "object" && !Array.isArray(res.body),
|
|
|
|
true,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.body.createdNote.poll != null, true);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("投票の選択肢が無くて怒られる", async(async () => {
|
|
|
|
const res = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
poll: {},
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("投票の選択肢が無くて怒られる (空の配列)", async(async () => {
|
|
|
|
const res = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
poll: {
|
|
|
|
choices: [],
|
|
|
|
},
|
2022-05-21 13:21:41 +00:00
|
|
|
},
|
2023-04-07 01:56:46 +00:00
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("投票の選択肢が1つで怒られる", async(async () => {
|
|
|
|
const res = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
poll: {
|
|
|
|
choices: ["Strawberry Pasta"],
|
|
|
|
},
|
2022-05-21 13:21:41 +00:00
|
|
|
},
|
2023-04-07 01:56:46 +00:00
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("投票できる", async(async () => {
|
|
|
|
const { body } = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
text: "test",
|
|
|
|
poll: {
|
|
|
|
choices: ["sakura", "izumi", "ako"],
|
|
|
|
},
|
2022-05-21 13:21:41 +00:00
|
|
|
},
|
2023-04-07 01:56:46 +00:00
|
|
|
alice,
|
|
|
|
);
|
|
|
|
|
|
|
|
const res = await request(
|
|
|
|
"/notes/polls/vote",
|
|
|
|
{
|
|
|
|
noteId: body.createdNote.id,
|
|
|
|
choice: 1,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("複数投票できない", async(async () => {
|
|
|
|
const { body } = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
text: "test",
|
|
|
|
poll: {
|
|
|
|
choices: ["sakura", "izumi", "ako"],
|
|
|
|
},
|
2022-05-21 13:21:41 +00:00
|
|
|
},
|
2023-04-07 01:56:46 +00:00
|
|
|
alice,
|
|
|
|
);
|
|
|
|
|
|
|
|
await request(
|
|
|
|
"/notes/polls/vote",
|
|
|
|
{
|
|
|
|
noteId: body.createdNote.id,
|
|
|
|
choice: 0,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
|
|
|
|
|
|
|
const res = await request(
|
|
|
|
"/notes/polls/vote",
|
|
|
|
{
|
|
|
|
noteId: body.createdNote.id,
|
|
|
|
choice: 2,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("許可されている場合は複数投票できる", async(async () => {
|
|
|
|
const { body } = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
text: "test",
|
|
|
|
poll: {
|
|
|
|
choices: ["sakura", "izumi", "ako"],
|
|
|
|
multiple: true,
|
|
|
|
},
|
2022-05-21 13:21:41 +00:00
|
|
|
},
|
2023-04-07 01:56:46 +00:00
|
|
|
alice,
|
|
|
|
);
|
|
|
|
|
|
|
|
await request(
|
|
|
|
"/notes/polls/vote",
|
|
|
|
{
|
|
|
|
noteId: body.createdNote.id,
|
|
|
|
choice: 0,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
|
|
|
|
|
|
|
await request(
|
|
|
|
"/notes/polls/vote",
|
|
|
|
{
|
|
|
|
noteId: body.createdNote.id,
|
|
|
|
choice: 1,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
|
|
|
|
|
|
|
const res = await request(
|
|
|
|
"/notes/polls/vote",
|
|
|
|
{
|
|
|
|
noteId: body.createdNote.id,
|
|
|
|
choice: 2,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
it("締め切られている場合は投票できない", async(async () => {
|
|
|
|
const { body } = await request(
|
|
|
|
"/notes/create",
|
|
|
|
{
|
|
|
|
text: "test",
|
|
|
|
poll: {
|
|
|
|
choices: ["sakura", "izumi", "ako"],
|
|
|
|
expiredAfter: 1,
|
|
|
|
},
|
2022-05-21 13:21:41 +00:00
|
|
|
},
|
2023-04-07 01:56:46 +00:00
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
await new Promise((x) => setTimeout(x, 2));
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const res = await request(
|
|
|
|
"/notes/polls/vote",
|
|
|
|
{
|
|
|
|
noteId: body.createdNote.id,
|
|
|
|
choice: 1,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 400);
|
|
|
|
}));
|
|
|
|
});
|
2022-03-22 13:48:33 +00:00
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
describe("notes/delete", () => {
|
|
|
|
it("delete a reply", async(async () => {
|
|
|
|
const mainNoteRes = await api(
|
|
|
|
"notes/create",
|
|
|
|
{
|
|
|
|
text: "main post",
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
|
|
|
const replyOneRes = await api(
|
|
|
|
"notes/create",
|
|
|
|
{
|
|
|
|
text: "reply one",
|
|
|
|
replyId: mainNoteRes.body.createdNote.id,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
|
|
|
const replyTwoRes = await api(
|
|
|
|
"notes/create",
|
|
|
|
{
|
|
|
|
text: "reply two",
|
|
|
|
replyId: mainNoteRes.body.createdNote.id,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
|
|
|
|
|
|
|
const deleteOneRes = await api(
|
|
|
|
"notes/delete",
|
|
|
|
{
|
|
|
|
noteId: replyOneRes.body.createdNote.id,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2022-03-22 13:48:33 +00:00
|
|
|
|
|
|
|
assert.strictEqual(deleteOneRes.status, 204);
|
2023-04-07 01:56:46 +00:00
|
|
|
let mainNote = await Notes.findOneBy({
|
|
|
|
id: mainNoteRes.body.createdNote.id,
|
|
|
|
});
|
2022-03-22 13:48:33 +00:00
|
|
|
assert.strictEqual(mainNote.repliesCount, 1);
|
|
|
|
|
2023-04-07 01:56:46 +00:00
|
|
|
const deleteTwoRes = await api(
|
|
|
|
"notes/delete",
|
|
|
|
{
|
|
|
|
noteId: replyTwoRes.body.createdNote.id,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2022-03-22 13:48:33 +00:00
|
|
|
|
|
|
|
assert.strictEqual(deleteTwoRes.status, 204);
|
2022-06-26 10:16:32 +00:00
|
|
|
mainNote = await Notes.findOneBy({ id: mainNoteRes.body.createdNote.id });
|
2022-03-22 13:48:33 +00:00
|
|
|
assert.strictEqual(mainNote.repliesCount, 0);
|
|
|
|
}));
|
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|