2023-04-07 03:56:46 +02:00
|
|
|
process.env.NODE_ENV = "test";
|
|
|
|
|
|
|
|
import * as assert from "assert";
|
|
|
|
import * as childProcess from "child_process";
|
|
|
|
import {
|
|
|
|
async,
|
2023-10-22 10:33:40 +02:00
|
|
|
signup,
|
|
|
|
request,
|
2023-04-07 03:56:46 +02:00
|
|
|
post,
|
|
|
|
react,
|
2023-10-20 02:10:30 +02:00
|
|
|
startServer,
|
2023-10-22 10:33:40 +02:00
|
|
|
shutdownServer,
|
2023-04-07 03:56:46 +02:00
|
|
|
waitFire,
|
|
|
|
} from "./utils.js";
|
|
|
|
|
|
|
|
describe("Mute", () => {
|
2019-04-07 14:50:36 +02:00
|
|
|
let p: childProcess.ChildProcess;
|
|
|
|
|
|
|
|
// alice mutes carol
|
|
|
|
let alice: any;
|
|
|
|
let bob: any;
|
|
|
|
let carol: any;
|
|
|
|
|
2021-06-12 15:40:17 +02:00
|
|
|
before(async () => {
|
|
|
|
p = await startServer();
|
2023-04-07 03:56:46 +02:00
|
|
|
alice = await signup({ username: "alice" });
|
|
|
|
bob = await signup({ username: "bob" });
|
|
|
|
carol = await signup({ username: "carol" });
|
2021-06-12 15:40:17 +02:00
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2021-06-05 07:54:07 +02:00
|
|
|
after(async () => {
|
|
|
|
await shutdownServer(p);
|
2019-04-07 14:50:36 +02:00
|
|
|
});
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("ミュート作成", async(async () => {
|
|
|
|
const res = await request(
|
|
|
|
"/mute/create",
|
|
|
|
{
|
|
|
|
userId: carol.id,
|
|
|
|
},
|
|
|
|
alice,
|
|
|
|
);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("「自分宛ての投稿」にミュートしているユーザーの投稿が含まれない", async(async () => {
|
|
|
|
const bobNote = await post(bob, { text: "@alice hi" });
|
|
|
|
const carolNote = await post(carol, { text: "@alice hi" });
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
const res = await request("/notes/mentions", {}, alice);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
2023-04-07 03:56:46 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((note: any) => note.id === bobNote.id),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((note: any) => note.id === carolNote.id),
|
|
|
|
false,
|
|
|
|
);
|
2019-04-07 14:50:36 +02:00
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("ミュートしているユーザーからメンションされても、hasUnreadMentions が true にならない", async(async () => {
|
2019-04-07 14:50:36 +02:00
|
|
|
// 状態リセット
|
2023-04-07 03:56:46 +02:00
|
|
|
await request("/i/read-all-unread-notes", {}, alice);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
await post(carol, { text: "@alice hi" });
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
const res = await request("/i", {}, alice);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(res.body.hasUnreadMentions, false);
|
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("ミュートしているユーザーからメンションされても、ストリームに unreadMention イベントが流れてこない", async () => {
|
2019-04-07 14:50:36 +02:00
|
|
|
// 状態リセット
|
2023-04-07 03:56:46 +02:00
|
|
|
await request("/i/read-all-unread-notes", {}, alice);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
const fired = await waitFire(
|
|
|
|
alice,
|
|
|
|
"main",
|
|
|
|
() => post(carol, { text: "@alice hi" }),
|
|
|
|
(msg) => msg.type === "unreadMention",
|
|
|
|
);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2022-06-26 12:16:32 +02:00
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("ミュートしているユーザーからメンションされても、ストリームに unreadNotification イベントが流れてこない", async () => {
|
2019-04-07 14:50:36 +02:00
|
|
|
// 状態リセット
|
2023-04-07 03:56:46 +02:00
|
|
|
await request("/i/read-all-unread-notes", {}, alice);
|
|
|
|
await request("/notifications/mark-all-as-read", {}, alice);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
const fired = await waitFire(
|
|
|
|
alice,
|
|
|
|
"main",
|
|
|
|
() => post(carol, { text: "@alice hi" }),
|
|
|
|
(msg) => msg.type === "unreadNotification",
|
|
|
|
);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2022-06-26 12:16:32 +02:00
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
});
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
describe("Timeline", () => {
|
|
|
|
it("タイムラインにミュートしているユーザーの投稿が含まれない", async(async () => {
|
2019-04-07 14:50:36 +02:00
|
|
|
const aliceNote = await post(alice);
|
|
|
|
const bobNote = await post(bob);
|
|
|
|
const carolNote = await post(carol);
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
const res = await request("/notes/local-timeline", {}, alice);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
2023-04-07 03:56:46 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((note: any) => note.id === aliceNote.id),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((note: any) => note.id === bobNote.id),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((note: any) => note.id === carolNote.id),
|
|
|
|
false,
|
|
|
|
);
|
2019-04-07 14:50:36 +02:00
|
|
|
}));
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
it("タイムラインにミュートしているユーザーの投稿のRenoteが含まれない", async(async () => {
|
2019-04-07 14:50:36 +02:00
|
|
|
const aliceNote = await post(alice);
|
|
|
|
const carolNote = await post(carol);
|
|
|
|
const bobNote = await post(bob, {
|
2022-05-21 15:21:41 +02:00
|
|
|
renoteId: carolNote.id,
|
2019-04-07 14:50:36 +02:00
|
|
|
});
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
const res = await request("/notes/local-timeline", {}, alice);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
2023-04-07 03:56:46 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((note: any) => note.id === aliceNote.id),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((note: any) => note.id === bobNote.id),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((note: any) => note.id === carolNote.id),
|
|
|
|
false,
|
|
|
|
);
|
2019-04-07 14:50:36 +02:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
describe("Notification", () => {
|
|
|
|
it("通知にミュートしているユーザーの通知が含まれない(リアクション)", async(async () => {
|
2019-04-07 14:50:36 +02:00
|
|
|
const aliceNote = await post(alice);
|
2023-04-07 03:56:46 +02:00
|
|
|
await react(bob, aliceNote, "like");
|
|
|
|
await react(carol, aliceNote, "like");
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2023-04-07 03:56:46 +02:00
|
|
|
const res = await request("/i/notifications", {}, alice);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
2023-04-07 03:56:46 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((notification: any) => notification.userId === bob.id),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
res.body.some((notification: any) => notification.userId === carol.id),
|
|
|
|
false,
|
|
|
|
);
|
2019-04-07 14:50:36 +02:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|