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,
|
|
|
|
unfollowRemotes,
|
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
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await unfollowRemotes(alpha);
|
|
|
|
});
|
|
|
|
|
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
|
|
|
|
|
|
|
let betaPms = await listPrivateMessages(beta);
|
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,
|
|
|
|
pmRes.private_message_view.private_message.id
|
|
|
|
);
|
|
|
|
expect(pmUpdated.private_message_view.private_message.content).toBe(
|
|
|
|
updatedContent
|
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
let betaPms = await listPrivateMessages(beta);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPms.private_messages[0].private_message.content).toBe(
|
|
|
|
updatedContent
|
|
|
|
);
|
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);
|
|
|
|
let betaPms1 = await listPrivateMessages(beta);
|
2020-12-20 21:16:57 +00:00
|
|
|
let deletedPmRes = await deletePrivateMessage(
|
|
|
|
alpha,
|
|
|
|
true,
|
|
|
|
pmRes.private_message_view.private_message.id
|
|
|
|
);
|
|
|
|
expect(deletedPmRes.private_message_view.private_message.deleted).toBe(true);
|
2021-07-30 18:44:15 +00:00
|
|
|
expect(deletedPmRes.private_message_view.private_message.content).toBe("");
|
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
|
|
|
|
let betaPms2 = await listPrivateMessages(beta);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPms2.private_messages.length).toBe(
|
|
|
|
betaPms1.private_messages.length - 1
|
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Undelete
|
|
|
|
let undeletedPmRes = await deletePrivateMessage(
|
|
|
|
alpha,
|
|
|
|
false,
|
2020-12-20 21:16:57 +00:00
|
|
|
pmRes.private_message_view.private_message.id
|
|
|
|
);
|
|
|
|
expect(undeletedPmRes.private_message_view.private_message.deleted).toBe(
|
|
|
|
false
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
let betaPms3 = await listPrivateMessages(beta);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPms3.private_messages.length).toBe(
|
|
|
|
betaPms1.private_messages.length
|
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|