2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2020-08-04 14:57:37 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
beta,
|
|
|
|
setupLogins,
|
|
|
|
followBeta,
|
|
|
|
createPrivateMessage,
|
2020-12-20 21:16:57 +00:00
|
|
|
editPrivateMessage,
|
2020-08-04 14:57:37 +00:00
|
|
|
listPrivateMessages,
|
|
|
|
deletePrivateMessage,
|
2023-09-09 16:25:03 +00:00
|
|
|
waitUntil,
|
2023-12-18 09:25:05 +00:00
|
|
|
reportPrivateMessage,
|
2024-03-26 16:06:11 +00:00
|
|
|
unfollows,
|
2022-10-27 09:24:07 +00:00
|
|
|
} from "./shared";
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
let recipient_id: number;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await setupLogins();
|
2021-04-08 11:29:08 +00:00
|
|
|
await followBeta(alpha);
|
|
|
|
recipient_id = 3;
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
2023-11-17 04:43:40 +00:00
|
|
|
afterAll(() => {
|
2024-03-26 16:06:11 +00:00
|
|
|
unfollows();
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Create a private message", async () => {
|
2020-08-04 14:57:37 +00:00
|
|
|
let pmRes = await createPrivateMessage(alpha, recipient_id);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(pmRes.private_message_view.private_message.content).toBeDefined();
|
|
|
|
expect(pmRes.private_message_view.private_message.local).toBe(true);
|
|
|
|
expect(pmRes.private_message_view.creator.local).toBe(true);
|
|
|
|
expect(pmRes.private_message_view.recipient.local).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-09-09 16:25:03 +00:00
|
|
|
let betaPms = await waitUntil(
|
|
|
|
() => listPrivateMessages(beta),
|
|
|
|
e => !!e.private_messages[0],
|
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPms.private_messages[0].private_message.content).toBeDefined();
|
|
|
|
expect(betaPms.private_messages[0].private_message.local).toBe(false);
|
|
|
|
expect(betaPms.private_messages[0].creator.local).toBe(false);
|
|
|
|
expect(betaPms.private_messages[0].recipient.local).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Update a private message", async () => {
|
|
|
|
let updatedContent = "A jest test federated private message edited";
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
let pmRes = await createPrivateMessage(alpha, recipient_id);
|
2020-12-20 21:16:57 +00:00
|
|
|
let pmUpdated = await editPrivateMessage(
|
|
|
|
alpha,
|
2023-07-06 13:10:38 +00:00
|
|
|
pmRes.private_message_view.private_message.id,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(pmUpdated.private_message_view.private_message.content).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
updatedContent,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-09-09 16:25:03 +00:00
|
|
|
let betaPms = await waitUntil(
|
|
|
|
() => listPrivateMessages(beta),
|
|
|
|
p => p.private_messages[0].private_message.content === updatedContent,
|
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPms.private_messages[0].private_message.content).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
updatedContent,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Delete a private message", async () => {
|
2020-08-04 14:57:37 +00:00
|
|
|
let pmRes = await createPrivateMessage(alpha, recipient_id);
|
2023-09-09 16:25:03 +00:00
|
|
|
let betaPms1 = await waitUntil(
|
|
|
|
() => listPrivateMessages(beta),
|
|
|
|
m =>
|
|
|
|
!!m.private_messages.find(
|
|
|
|
e =>
|
|
|
|
e.private_message.ap_id ===
|
|
|
|
pmRes.private_message_view.private_message.ap_id,
|
|
|
|
),
|
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
let deletedPmRes = await deletePrivateMessage(
|
|
|
|
alpha,
|
|
|
|
true,
|
2023-07-06 13:10:38 +00:00
|
|
|
pmRes.private_message_view.private_message.id,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(deletedPmRes.private_message_view.private_message.deleted).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// The GetPrivateMessages filters out deleted,
|
|
|
|
// even though they are in the actual database.
|
|
|
|
// no reason to show them
|
2023-09-09 16:25:03 +00:00
|
|
|
let betaPms2 = await waitUntil(
|
|
|
|
() => listPrivateMessages(beta),
|
|
|
|
p => p.private_messages.length === betaPms1.private_messages.length - 1,
|
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPms2.private_messages.length).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
betaPms1.private_messages.length - 1,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Undelete
|
|
|
|
let undeletedPmRes = await deletePrivateMessage(
|
|
|
|
alpha,
|
|
|
|
false,
|
2023-07-06 13:10:38 +00:00
|
|
|
pmRes.private_message_view.private_message.id,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(undeletedPmRes.private_message_view.private_message.deleted).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
false,
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
|
|
|
|
2023-09-09 16:25:03 +00:00
|
|
|
let betaPms3 = await waitUntil(
|
|
|
|
() => listPrivateMessages(beta),
|
|
|
|
p => p.private_messages.length === betaPms1.private_messages.length,
|
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPms3.private_messages.length).toBe(
|
2023-07-06 13:10:38 +00:00
|
|
|
betaPms1.private_messages.length,
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
2023-12-18 09:25:05 +00:00
|
|
|
|
|
|
|
test("Create a private message report", async () => {
|
|
|
|
let pmRes = await createPrivateMessage(alpha, recipient_id);
|
|
|
|
let betaPms1 = await waitUntil(
|
|
|
|
() => listPrivateMessages(beta),
|
|
|
|
m =>
|
|
|
|
!!m.private_messages.find(
|
|
|
|
e =>
|
|
|
|
e.private_message.ap_id ===
|
|
|
|
pmRes.private_message_view.private_message.ap_id,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
let betaPm = betaPms1.private_messages[0];
|
|
|
|
expect(betaPm).toBeDefined();
|
|
|
|
|
|
|
|
// Make sure that only the recipient can report it, so this should fail
|
|
|
|
await expect(
|
|
|
|
reportPrivateMessage(
|
|
|
|
alpha,
|
|
|
|
pmRes.private_message_view.private_message.id,
|
|
|
|
"a reason",
|
|
|
|
),
|
|
|
|
).rejects.toStrictEqual(Error("couldnt_create_report"));
|
|
|
|
|
|
|
|
// This one should pass
|
|
|
|
let reason = "another reason";
|
|
|
|
let report = await reportPrivateMessage(
|
|
|
|
beta,
|
|
|
|
betaPm.private_message.id,
|
|
|
|
reason,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(report.private_message_report_view.private_message.id).toBe(
|
|
|
|
betaPm.private_message.id,
|
|
|
|
);
|
|
|
|
expect(report.private_message_report_view.private_message_report.reason).toBe(
|
|
|
|
reason,
|
|
|
|
);
|
|
|
|
});
|