API,
delay,
} from './shared';
+import {
+ Comment,
+} from 'lemmy-js-client';
import { PostResponse } from 'lemmy-js-client';
await unfollowRemotes(gamma);
});
+function assertCommentFederation(
+ commentOne: Comment,
+ commentTwo: Comment) {
+ expect(commentOne.ap_id).toBe(commentOne.ap_id);
+ expect(commentOne.content).toBe(commentTwo.content);
+ expect(commentOne.creator_name).toBe(commentTwo.creator_name);
+ expect(commentOne.community_actor_id).toBe(commentTwo.community_actor_id);
+ expect(commentOne.published).toBe(commentTwo.published);
+ expect(commentOne.updated).toBe(commentOne.updated);
+ expect(commentOne.deleted).toBe(commentOne.deleted);
+ expect(commentOne.removed).toBe(commentOne.removed);
+}
+
test('Create a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
expect(commentRes.comment.content).toBeDefined();
expect(betaComment.community_local).toBe(true);
expect(betaComment.creator_local).toBe(false);
expect(betaComment.score).toBe(1);
+ assertCommentFederation(betaComment, commentRes.comment);
});
test('Create a comment in a non-existent post', async () => {
test('Update a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
+ // Federate the comment first
+ let searchBeta = await searchComment(beta, commentRes.comment);
+ assertCommentFederation(searchBeta.comments[0], commentRes.comment);
+
await delay();
let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
expect(updateCommentRes.comment.content).toBe(
await delay();
// Make sure that post is updated on beta
- let searchBeta = await searchComment(beta, commentRes.comment);
- let betaComment = searchBeta.comments[0];
- expect(betaComment.content).toBe('A jest test federated comment update');
+ let searchBetaUpdated = await searchComment(beta, commentRes.comment);
+ assertCommentFederation(searchBetaUpdated.comments[0], updateCommentRes.comment);
});
test('Delete a comment', async () => {
let searchBeta2 = await searchComment(beta, commentRes.comment);
let betaComment2 = searchBeta2.comments[0];
expect(betaComment2.deleted).toBe(false);
+ assertCommentFederation(searchBeta2.comments[0], undeleteCommentRes.comment);
});
test('Remove a comment from admin and community on the same instance', async () => {
// Make sure that comment is unremoved on beta
let refetchedPost2 = await getPost(alpha, postRes.post.id);
expect(refetchedPost2.comments[0].removed).toBe(false);
+ assertCommentFederation(refetchedPost2.comments[0], unremoveCommentRes.comment);
});
test('Remove a comment from admin and community on different instance', async () => {
// Make sure its not removed on alpha
let refetchedPost = await getPost(newAlphaApi, newPost.post.id);
expect(refetchedPost.comments[0].removed).toBe(false);
+ assertCommentFederation(refetchedPost.comments[0], commentRes.comment);
});
test('Unlike a comment', async () => {
expect(alphaComment.community_local).toBe(false);
expect(alphaComment.creator_local).toBe(false);
expect(alphaComment.score).toBe(1);
+ assertCommentFederation(alphaComment, replyRes.comment);
});
test('Mention beta', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
await delay();
let searchBeta = await searchComment(beta, commentRes.comment);
- expect(searchBeta.comments[0].ap_id).toBe(commentRes.comment.ap_id);
+ assertCommentFederation(searchBeta.comments[0], commentRes.comment);
});
test('A and G subscribe to B (center) A posts, G mentions B, it gets announced to A', async () => {
expect(alphaPost2.comments[0].community_local).toBe(true);
expect(alphaPost2.comments[0].creator_local).toBe(false);
expect(alphaPost2.comments[0].score).toBe(1);
+ assertCommentFederation(alphaPost2.comments[0], commentRes.comment);
// Make sure beta has mentions
let mentionsRes = await getMentions(beta);
let alphaPost = await getPost(alpha, alphaPostB.id);
expect(alphaPost.post.name).toBeDefined();
- expect(alphaPost.comments[1].content).toBe(parentCommentContent);
- expect(alphaPost.comments[0].content).toBe(updatedCommentContent);
+ assertCommentFederation(alphaPost.comments[1], parentCommentRes.comment);
+ assertCommentFederation(alphaPost.comments[0], updateRes.comment);
expect(alphaPost.post.community_local).toBe(false);
expect(alphaPost.post.creator_local).toBe(false);
});
removeCommunity,
delay,
} from './shared';
+import {
+ Community,
+} from 'lemmy-js-client';
beforeAll(async () => {
await setupLogins();
});
+function assertCommunityFederation(
+ communityOne: Community,
+ communityTwo: Community) {
+ expect(communityOne.actor_id).toBe(communityTwo.actor_id);
+ expect(communityOne.name).toBe(communityTwo.name);
+ expect(communityOne.title).toBe(communityTwo.title);
+ expect(communityOne.description).toBe(communityTwo.description);
+ expect(communityOne.icon).toBe(communityTwo.icon);
+ expect(communityOne.banner).toBe(communityTwo.banner);
+ expect(communityOne.published).toBe(communityTwo.published);
+ expect(communityOne.creator_actor_id).toBe(communityTwo.creator_actor_id);
+ expect(communityOne.nsfw).toBe(communityTwo.nsfw);
+ expect(communityOne.category_id).toBe(communityTwo.category_id);
+ expect(communityOne.removed).toBe(communityTwo.removed);
+ expect(communityOne.deleted).toBe(communityTwo.deleted);
+}
+
test('Create community', async () => {
let communityRes = await createCommunity(alpha);
expect(communityRes.community.name).toBeDefined();
let searchShort = `!${prevName}@lemmy-alpha:8541`;
let search = await searchForCommunity(beta, searchShort);
let communityOnBeta = search.communities[0];
- expect(communityOnBeta.name).toBe(communityRes.community.name);
- expect(communityOnBeta.title).toBe(communityRes.community.title);
- expect(communityOnBeta.description).toBe(communityRes.community.description);
- expect(communityOnBeta.icon).toBe(communityRes.community.icon);
- expect(communityOnBeta.banner).toBe(communityRes.community.banner);
+ assertCommunityFederation(communityOnBeta, communityRes.community);
});
test('Delete community', async () => {
let communityA = search.communities[0];
// TODO this fails currently, because no updates are pushed
// expect(communityA.deleted).toBe(true);
+ // assertCommunityFederation(communityA, communityRes.community);
// Undelete
let undeleteCommunityRes = await deleteCommunity(
let communityA2 = search2.communities[0];
// TODO this fails currently, because no updates are pushed
// expect(communityA2.deleted).toBe(false);
+ // assertCommunityFederation(communityA2, undeleteCommunityRes.community);
});
test('Remove community', async () => {
let communityA = search.communities[0];
// TODO this fails currently, because no updates are pushed
// expect(communityA.removed).toBe(true);
+ // assertCommunityFederation(communityA, communityRes.community);
await delay();
// unremove
let communityA2 = search2.communities[0];
// TODO this fails currently, because no updates are pushed
// expect(communityA2.removed).toBe(false);
+ // assertCommunityFederation(communityA2, unremoveCommunityRes.community);
});
test('Search for beta community', async () => {
unfollowRemotes,
delay,
} from './shared';
+import {
+ Post,
+} from 'lemmy-js-client';
beforeAll(async () => {
await setupLogins();
await unfollowRemotes(epsilon);
});
+function assertPostFederation(
+ postOne: Post,
+ postTwo: Post) {
+ expect(postOne.ap_id).toBe(postTwo.ap_id);
+ expect(postOne.name).toBe(postTwo.name);
+ expect(postOne.body).toBe(postTwo.body);
+ expect(postOne.url).toBe(postTwo.url);
+ expect(postOne.nsfw).toBe(postTwo.nsfw);
+ expect(postOne.embed_title).toBe(postTwo.embed_title);
+ expect(postOne.embed_description).toBe(postTwo.embed_description);
+ expect(postOne.embed_html).toBe(postTwo.embed_html);
+ expect(postOne.published).toBe(postTwo.published);
+ expect(postOne.community_actor_id).toBe(postTwo.community_actor_id);
+ expect(postOne.locked).toBe(postTwo.locked);
+ expect(postOne.removed).toBe(postTwo.removed);
+ expect(postOne.deleted).toBe(postTwo.deleted);
+}
+
test('Create a post', async () => {
let search = await searchForBetaCommunity(alpha);
await delay();
expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false);
expect(betaPost.score).toBe(1);
- expect(betaPost.name).toBe(postRes.post.name);
- expect(betaPost.body).toBe(postRes.post.body);
- expect(betaPost.url).toBe(postRes.post.url);
- expect(betaPost.nsfw).toBe(postRes.post.nsfw);
+ assertPostFederation(betaPost, postRes.post);
// Delta only follows beta, so it should not see an alpha ap_id
let searchDelta = await searchPost(delta, postRes.post);
expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false);
expect(betaPost.score).toBe(0);
+ assertPostFederation(betaPost, postRes.post);
});
test('Update a post', async () => {
expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false);
expect(betaPost.name).toBe(updatedName);
+ assertPostFederation(betaPost, updatedPost.post);
await delay();
// Make sure lemmy beta cannot update the post
let searchBeta2 = await searchPost(beta, postRes.post);
let betaPost2 = searchBeta2.posts[0];
expect(betaPost2.deleted).toBe(false);
+ assertPostFederation(betaPost2, undeletedPost.post);
// Make sure lemmy beta cannot delete the post
let deletedPostBeta = await deletePost(beta, true, betaPost2);
let searchBeta2 = await searchPost(beta, postRes.post);
let betaPost2 = searchBeta2.posts[0];
expect(betaPost2.removed).toBe(false);
+ assertPostFederation(betaPost2, undeletedPost.post);
});
test('Remove a post from admin and community on same instance', async () => {
// Make sure lemmy alpha sees post is removed
let alphaPost = await getPost(alpha, postRes.post.id);
expect(alphaPost.post.removed).toBe(true);
+ assertPostFederation(alphaPost.post, removePostRes.post);
await delay();
// Undelete
// Make sure lemmy alpha sees post is undeleted
let alphaPost2 = await getPost(alpha, postRes.post.id);
expect(alphaPost2.post.removed).toBe(false);
+ assertPostFederation(alphaPost2.post, undeletedPost.post);
});
test('Search for a post', async () => {
bio: 'a changed bio',
auth,
};
+ return saveUserSettings(api, form);
+}
+
+export async function saveUserSettings(
+ api: API,
+ form: UserSettingsForm
+): Promise<LoginResponse> {
return api.client.saveUserSettings(form);
}
registerUser,
searchForUser,
saveUserSettingsBio,
+ saveUserSettings,
getSite,
} from './shared';
+import {
+ UserView,
+ UserSettingsForm,
+} from 'lemmy-js-client';
let auth: string;
let apShortname: string;
+function assertUserFederation(
+ userOne: UserView,
+ userTwo: UserView) {
+ expect(userOne.name).toBe(userTwo.name);
+ expect(userOne.preferred_username).toBe(userTwo.preferred_username);
+ expect(userOne.bio).toBe(userTwo.bio);
+ expect(userOne.actor_id).toBe(userTwo.actor_id);
+ expect(userOne.avatar).toBe(userTwo.avatar);
+ expect(userOne.banner).toBe(userTwo.banner);
+}
+
test('Create user', async () => {
let userRes = await registerUser(alpha);
expect(userRes.jwt).toBeDefined();
let site = await getSite(alpha, auth);
expect(site.my_user.bio).toBe(bio);
+ let searchAlpha = await searchForUser(alpha, site.my_user.actor_id);
// Make sure beta sees this bio is changed
- let search = await searchForUser(beta, apShortname);
- expect(search.users[0].bio).toBe(bio);
+ let searchBeta = await searchForUser(beta, apShortname);
+ assertUserFederation(searchAlpha.users[0], searchBeta.users[0]);
});
+
+test('Set avatar and banner, check that they are federated', async () => {
+ let avatar = 'https://image.flaticon.com/icons/png/512/35/35896.png';
+ let banner = 'https://image.flaticon.com/icons/png/512/36/35896.png';
+ let form: UserSettingsForm = {
+ show_nsfw: false,
+ theme: "",
+ default_sort_type: 0,
+ default_listing_type: 0,
+ lang: "",
+ avatar,
+ banner,
+ preferred_username: "user321",
+ show_avatars: false,
+ send_notifications_to_email: false,
+ auth,
+ }
+ let settingsRes = await saveUserSettings(alpha, form);
+
+ let searchAlpha = await searchForUser(beta, apShortname);
+ let userOnAlpha = searchAlpha.users[0];
+ let searchBeta = await searchForUser(beta, apShortname);
+ let userOnBeta = searchBeta.users[0];
+ assertUserFederation(userOnAlpha, userOnBeta);
+});
\ No newline at end of file