jest.setTimeout(120000);
+import {None} from '@sniptt/monads';
+import { PostView, CommunityView } from 'lemmy-js-client';
import {
alpha,
beta,
randomString,
registerUser,
API,
- getSite
+ getSite,
+ unfollows,
+ resolveCommunity
} from './shared';
-import { PostView, CommunityView } from 'lemmy-js-client';
let betaCommunity: CommunityView;
beforeAll(async () => {
await setupLogins();
- betaCommunity = (await resolveBetaCommunity(alpha)).community;
+ betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
expect(betaCommunity).toBeDefined();
await unfollows();
});
await unfollows();
});
-async function unfollows() {
- await unfollowRemotes(alpha);
- await unfollowRemotes(gamma);
- await unfollowRemotes(delta);
- await unfollowRemotes(epsilon);
-}
-
function assertPostFederation(postOne: PostView, postTwo: PostView) {
expect(postOne.post.ap_id).toBe(postTwo.post.ap_id);
expect(postOne.post.name).toBe(postTwo.post.name);
- expect(postOne.post.body).toBe(postTwo.post.body);
- expect(postOne.post.url).toBe(postTwo.post.url);
+ expect(postOne.post.body.unwrapOr("none")).toBe(postTwo.post.body.unwrapOr("none"));
+ expect(postOne.post.url.unwrapOr("none")).toBe(postTwo.post.url.unwrapOr("none"));
expect(postOne.post.nsfw).toBe(postTwo.post.nsfw);
- expect(postOne.post.embed_title).toBe(postTwo.post.embed_title);
- expect(postOne.post.embed_description).toBe(postTwo.post.embed_description);
- expect(postOne.post.embed_html).toBe(postTwo.post.embed_html);
+ expect(postOne.post.embed_title.unwrapOr("none")).toBe(postTwo.post.embed_title.unwrapOr("none"));
+ expect(postOne.post.embed_description.unwrapOr("none")).toBe(postTwo.post.embed_description.unwrapOr("none"));
+ expect(postOne.post.embed_html.unwrapOr("none")).toBe(postTwo.post.embed_html.unwrapOr("none"));
expect(postOne.post.published).toBe(postTwo.post.published);
expect(postOne.community.actor_id).toBe(postTwo.community.actor_id);
expect(postOne.post.locked).toBe(postTwo.post.locked);
expect(postRes.post_view.counts.score).toBe(1);
// Make sure that post is liked on beta
- let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(betaPost).toBeDefined();
expect(betaPost.community.local).toBe(true);
// Delta only follows beta, so it should not see an alpha ap_id
let deltaPost = (await resolvePost(delta, postRes.post_view.post)).post;
- expect(deltaPost).toBeUndefined();
+ expect(deltaPost.isNone()).toBe(true)
// Epsilon has alpha blocked, it should not see the alpha post
let epsilonPost = (await resolvePost(epsilon, postRes.post_view.post)).post;
- expect(epsilonPost).toBeUndefined();
+ expect(epsilonPost.isNone()).toBe(true);
});
test('Create a post in a non-existent community', async () => {
- let postRes = await createPost(alpha, -2);
- expect(postRes).toStrictEqual({ error: 'couldnt_find_community' });
+ let postRes = await createPost(alpha, -2) as any;
+ expect(postRes.error).toBe('couldnt_find_community');
});
test('Unlike a post', async () => {
expect(unlike2.post_view.counts.score).toBe(0);
// Make sure that post is unliked on beta
- let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(betaPost).toBeDefined();
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(updatedPost.post_view.creator.local).toBe(true);
// Make sure that post is updated on beta
- let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(betaPost.post.name).toBe(updatedName);
assertPostFederation(betaPost, updatedPost.post_view);
// Make sure lemmy beta cannot update the post
- let updatedPostBeta = await editPost(beta, betaPost.post);
- expect(updatedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
+ let updatedPostBeta = await editPost(beta, betaPost.post) as any;
+ expect(updatedPostBeta.error).toBe('no_post_edit_allowed');
});
test('Sticky a post', async () => {
let postRes = await createPost(alpha, betaCommunity.community.id);
- let betaPost1 = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost1 = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
let stickiedPostRes = await stickyPost(beta, true, betaPost1.post);
expect(stickiedPostRes.post_view.post.stickied).toBe(true);
// Make sure that post is stickied on beta
- let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(betaPost.post.stickied).toBe(true);
expect(unstickiedPost.post_view.post.stickied).toBe(false);
// Make sure that post is unstickied on beta
- let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(betaPost2.community.local).toBe(true);
expect(betaPost2.creator.local).toBe(false);
expect(betaPost2.post.stickied).toBe(false);
// Make sure that gamma cannot sticky the post on beta
- let gammaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
+ let gammaPost = (await resolvePost(gamma, postRes.post_view.post)).post.unwrap();
let gammaTrySticky = await stickyPost(gamma, true, gammaPost.post);
- let betaPost3 = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost3 = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(gammaTrySticky.post_view.post.stickied).toBe(true);
expect(betaPost3.post.stickied).toBe(false);
});
let postRes = await createPost(alpha, betaCommunity.community.id);
// Lock the post
- let betaPost1 = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost1 = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
let lockedPostRes = await lockPost(beta, true, betaPost1.post);
expect(lockedPostRes.post_view.post.locked).toBe(true);
expect(alphaPost1.post.locked).toBe(true);
// Try to make a new comment there, on alpha
- let comment: any = await createComment(alpha, alphaPost1.post.id);
+ let comment: any = await createComment(alpha, alphaPost1.post.id, None);
expect(comment['error']).toBe('locked');
// Unlock a post
expect(alphaPost2.post.locked).toBe(false);
// Try to create a new comment, on alpha
- let commentAlpha = await createComment(alpha, alphaPost1.post.id);
+ let commentAlpha = await createComment(alpha, alphaPost1.post.id, None);
expect(commentAlpha).toBeDefined();
});
// Make sure lemmy beta sees post is deleted
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
// This will be undefined because of the tombstone
- expect(betaPost).toBeUndefined();
+ expect(betaPost.isNone()).toBe(true);
// Undelete
let undeletedPost = await deletePost(alpha, false, postRes.post_view.post);
expect(undeletedPost.post_view.post.deleted).toBe(false);
// Make sure lemmy beta sees post is undeleted
- let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(betaPost2.post.deleted).toBe(false);
assertPostFederation(betaPost2, undeletedPost.post_view);
// Make sure lemmy beta cannot delete the post
- let deletedPostBeta = await deletePost(beta, true, betaPost2.post);
- expect(deletedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
+ let deletedPostBeta = await deletePost(beta, true, betaPost2.post) as any;
+ expect(deletedPostBeta.error).toStrictEqual('no_post_edit_allowed');
});
test('Remove a post from admin and community on different instance', async () => {
- let postRes = await createPost(alpha, betaCommunity.community.id);
+ let gammaCommunity = await resolveCommunity(gamma, betaCommunity.community.actor_id);
+ let postRes = await createPost(gamma, gammaCommunity.community.unwrap().community.id);
- let removedPost = await removePost(alpha, true, postRes.post_view.post);
+ let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post.unwrap();
+ let removedPost = await removePost(alpha, true, alphaPost.post);
expect(removedPost.post_view.post.removed).toBe(true);
expect(removedPost.post_view.post.name).toBe(postRes.post_view.post.name);
// Make sure lemmy beta sees post is NOT removed
- let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(betaPost.post.removed).toBe(false);
// Undelete
- let undeletedPost = await removePost(alpha, false, postRes.post_view.post);
+ let undeletedPost = await removePost(alpha, false, alphaPost.post);
expect(undeletedPost.post_view.post.removed).toBe(false);
// Make sure lemmy beta sees post is undeleted
- let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
+ let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(betaPost2.post.removed).toBe(false);
assertPostFederation(betaPost2, undeletedPost.post_view);
});
expect(removePostRes.post_view.post.removed).toBe(true);
// Make sure lemmy alpha sees post is removed
- let alphaPost = await getPost(alpha, postRes.post_view.post.id);
+ // let alphaPost = await getPost(alpha, postRes.post_view.post.id);
// expect(alphaPost.post_view.post.removed).toBe(true); // TODO this shouldn't be commented
// assertPostFederation(alphaPost.post_view, removePostRes.post_view);
let postRes = await createPost(alpha, betaCommunity.community.id);
expect(postRes.post_view.post).toBeDefined();
- let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
-
- expect(betaPost.post.name).toBeDefined();
-});
-
-test('A and G subscribe to B (center) A posts, it gets announced to G', async () => {
- let postRes = await createPost(alpha, betaCommunity.community.id);
- expect(postRes.post_view.post).toBeDefined();
-
- let betaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
+ let betaPost = (await resolvePost(beta, postRes.post_view.post)).post.unwrap();
expect(betaPost.post.name).toBeDefined();
});
// create a test user
let alphaUserJwt = await registerUser(alpha);
expect(alphaUserJwt).toBeDefined();
- let alphaUser: API = {
+ let alpha_user: API = {
client: alpha.client,
auth: alphaUserJwt.jwt,
};
- let alphaUserActorId = (await getSite(alphaUser)).my_user.local_user_view.person.actor_id;
+ let alphaUserActorId = (await getSite(alpha_user)).my_user.unwrap().local_user_view.person.actor_id;
expect(alphaUserActorId).toBeDefined();
- let alphaPerson = (await resolvePerson(alphaUser, alphaUserActorId)).person;
+ let alphaPerson = (await resolvePerson(alpha_user, alphaUserActorId)).person.unwrap();
expect(alphaPerson).toBeDefined();
// alpha makes post in beta community, it federates to beta instance
- let postRes1 = await createPost(alphaUser, betaCommunity.community.id);
+ let postRes1 = await createPost(alpha_user, betaCommunity.community.id);
let searchBeta1 = await searchPostLocal(beta, postRes1.post_view.post);
expect(searchBeta1.posts[0]).toBeDefined();
// alpha ban should be federated to beta
let alphaUserOnBeta1 = await resolvePerson(beta, alphaUserActorId);
- expect(alphaUserOnBeta1.person.person.banned).toBe(true);
+ expect(alphaUserOnBeta1.person.unwrap().person.banned).toBe(true);
// existing alpha post should be removed on beta
let searchBeta2 = await searchPostLocal(beta, postRes1.post_view.post);
expect(unBanAlpha.banned).toBe(false);
// alpha makes new post in beta community, it federates
- let postRes2 = await createPost(alphaUser, betaCommunity.community.id);
+ let postRes2 = await createPost(alpha_user, betaCommunity.community.id);
let searchBeta3 = await searchPostLocal(beta, postRes2.post_view.post);
expect(searchBeta3.posts[0]).toBeDefined();
let alphaUserOnBeta2 = await resolvePerson(beta, alphaUserActorId)
- expect(alphaUserOnBeta2.person.person.banned).toBe(false);
+ expect(alphaUserOnBeta2.person.unwrap().person.banned).toBe(false);
});
test('Enforce community ban for federated user', async () => {
let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
- let alphaPerson = (await resolvePerson(beta, alphaShortname)).person;
+ let alphaPerson = (await resolvePerson(beta, alphaShortname)).person.unwrap();
expect(alphaPerson).toBeDefined();
// make a post in beta, it goes through
expect(searchBeta2.posts[0]).toBeDefined();
});
+
+test('A and G subscribe to B (center) A posts, it gets announced to G', async () => {
+ let postRes = await createPost(alpha, betaCommunity.community.id);
+ expect(postRes.post_view.post).toBeDefined();
+
+ let betaPost = (await resolvePost(gamma, postRes.post_view.post)).post.unwrap();
+ expect(betaPost.post.name).toBeDefined();
+});
+
test('Report a post', async () => {
- let betaCommunity = (await resolveBetaCommunity(beta)).community;
+ let betaCommunity = (await resolveBetaCommunity(beta)).community.unwrap();
let postRes = await createPost(beta, betaCommunity.community.id);
expect(postRes.post_view.post).toBeDefined();
- let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post;
+ let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post.unwrap();
let alphaReport = (await reportPost(alpha, alphaPost.post.id, randomString(10)))
.post_report_view.post_report;
expect(betaReport).toBeDefined();
expect(betaReport.resolved).toBe(false);
expect(betaReport.original_post_name).toBe(alphaReport.original_post_name);
- expect(betaReport.original_post_url).toBe(alphaReport.original_post_url);
- expect(betaReport.original_post_body).toBe(alphaReport.original_post_body);
+ expect(betaReport.original_post_url.unwrapOr("none")).toBe(alphaReport.original_post_url.unwrapOr("none"));
+ expect(betaReport.original_post_body.unwrapOr("none")).toBe(alphaReport.original_post_body.unwrapOr("none"));
expect(betaReport.reason).toBe(alphaReport.reason);
-});
\ No newline at end of file
+});