Changing unit tests to api v2.

This commit is contained in:
Dessalines 2020-12-20 16:16:57 -05:00
parent a27b7f8d1f
commit 5af8257e19
13 changed files with 2531 additions and 1125 deletions

51
api_tests/.eslintrc.json Normal file
View File

@ -0,0 +1,51 @@
{
"root": true,
"env": {
"browser": true
},
"plugins": [
"jane"
],
"extends": [
"plugin:jane/recommended",
"plugin:jane/typescript"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"warnOnUnsupportedTypeScriptVersion": false
},
"rules": {
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/member-delimiter-style": 0,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/no-unused-vars": 0,
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/no-useless-constructor": 0,
"arrow-body-style": 0,
"curly": 0,
"eol-last": 0,
"eqeqeq": 0,
"func-style": 0,
"import/no-duplicates": 0,
"max-statements": 0,
"max-params": 0,
"new-cap": 0,
"no-console": 0,
"no-duplicate-imports": 0,
"no-extra-parens": 0,
"no-return-assign": 0,
"no-throw-literal": 0,
"no-trailing-spaces": 0,
"no-unused-expressions": 0,
"no-useless-constructor": 0,
"no-useless-escape": 0,
"no-var": 0,
"prefer-const": 0,
"prefer-rest-params": 0,
"quote-props": 0,
"unicorn/filename-case": 0
}
}

4
api_tests/.prettierrc.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = Object.assign(require('eslint-plugin-jane/prettier-ts'), {
arrowParens: 'avoid',
semi: true,
});

View File

@ -7,14 +7,19 @@
"author": "Dessalines",
"license": "AGPL-3.0",
"scripts": {
"lint": "tsc --noEmit && eslint --report-unused-disable-directives --ext .js,.ts,.tsx src",
"fix": "prettier --write src && eslint --fix src",
"api-test": "jest src/ -i --verbose"
},
"devDependencies": {
"@types/jest": "^26.0.14",
"jest": "^26.4.2",
"lemmy-js-client": "^1.0.14",
"@types/jest": "^26.0.19",
"jest": "^26.6.3",
"lemmy-js-client": "1.0.17-beta3",
"node-fetch": "^2.6.1",
"ts-jest": "^26.4.1",
"typescript": "^4.0.3"
"ts-jest": "^26.4.4",
"prettier": "^2.1.2",
"eslint": "^7.10.0",
"eslint-plugin-jane": "^9.0.3",
"typescript": "^4.1.3"
}
}

View File

@ -11,7 +11,7 @@ import {
followBeta,
searchForBetaCommunity,
createComment,
updateComment,
editComment,
deleteComment,
removeComment,
getMentions,
@ -23,9 +23,7 @@ import {
delay,
longDelay,
} from './shared';
import {
Comment,
} from 'lemmy-js-client';
import { CommentView } from 'lemmy-js-client';
import { PostResponse } from 'lemmy-js-client';
@ -39,7 +37,7 @@ beforeAll(async () => {
await longDelay();
postRes = await createPost(
alpha,
search.communities.filter(c => c.local == false)[0].id
search.communities.find(c => c.community.local == false).community.id
);
});
@ -49,34 +47,35 @@ afterAll(async () => {
});
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);
commentOne: CommentView,
commentTwo: CommentView
) {
expect(commentOne.comment.ap_id).toBe(commentOne.comment.ap_id);
expect(commentOne.comment.content).toBe(commentTwo.comment.content);
expect(commentOne.creator.name).toBe(commentTwo.creator.name);
expect(commentOne.community.actor_id).toBe(commentTwo.community.actor_id);
expect(commentOne.comment.published).toBe(commentTwo.comment.published);
expect(commentOne.comment.updated).toBe(commentOne.comment.updated);
expect(commentOne.comment.deleted).toBe(commentOne.comment.deleted);
expect(commentOne.comment.removed).toBe(commentOne.comment.removed);
}
test('Create a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
expect(commentRes.comment.content).toBeDefined();
expect(commentRes.comment.community_local).toBe(false);
expect(commentRes.comment.creator_local).toBe(true);
expect(commentRes.comment.score).toBe(1);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
expect(commentRes.comment_view.comment.content).toBeDefined();
expect(commentRes.comment_view.community.local).toBe(false);
expect(commentRes.comment_view.creator.local).toBe(true);
expect(commentRes.comment_view.counts.score).toBe(1);
await longDelay();
// Make sure that comment is liked on beta
let searchBeta = await searchComment(beta, commentRes.comment);
let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
let betaComment = searchBeta.comments[0];
expect(betaComment).toBeDefined();
expect(betaComment.community_local).toBe(true);
expect(betaComment.creator_local).toBe(false);
expect(betaComment.score).toBe(1);
assertCommentFederation(betaComment, commentRes.comment);
expect(betaComment.community.local).toBe(true);
expect(betaComment.creator.local).toBe(false);
expect(betaComment.counts.score).toBe(1);
assertCommentFederation(betaComment, commentRes.comment_view);
});
test('Create a comment in a non-existent post', async () => {
@ -85,39 +84,48 @@ test('Create a comment in a non-existent post', async () => {
});
test('Update a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
// Federate the comment first
let searchBeta = await searchComment(beta, commentRes.comment);
assertCommentFederation(searchBeta.comments[0], commentRes.comment);
let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
assertCommentFederation(searchBeta.comments[0], commentRes.comment_view);
await delay();
let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
expect(updateCommentRes.comment.content).toBe(
let updateCommentRes = await editComment(
alpha,
commentRes.comment_view.comment.id
);
expect(updateCommentRes.comment_view.comment.content).toBe(
'A jest test federated comment update'
);
expect(updateCommentRes.comment.community_local).toBe(false);
expect(updateCommentRes.comment.creator_local).toBe(true);
expect(updateCommentRes.comment_view.community.local).toBe(false);
expect(updateCommentRes.comment_view.creator.local).toBe(true);
await delay();
// Make sure that post is updated on beta
let searchBetaUpdated = await searchComment(beta, commentRes.comment);
assertCommentFederation(searchBetaUpdated.comments[0], updateCommentRes.comment);
let searchBetaUpdated = await searchComment(
beta,
commentRes.comment_view.comment
);
assertCommentFederation(
searchBetaUpdated.comments[0],
updateCommentRes.comment_view
);
});
test('Delete a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
await delay();
let deleteCommentRes = await deleteComment(
alpha,
true,
commentRes.comment.id
commentRes.comment_view.comment.id
);
expect(deleteCommentRes.comment.deleted).toBe(true);
expect(deleteCommentRes.comment_view.comment.deleted).toBe(true);
await delay();
// Make sure that comment is undefined on beta
let searchBeta = await searchComment(beta, commentRes.comment);
let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
let betaComment = searchBeta.comments[0];
expect(betaComment).toBeUndefined();
await delay();
@ -125,43 +133,50 @@ test('Delete a comment', async () => {
let undeleteCommentRes = await deleteComment(
alpha,
false,
commentRes.comment.id
commentRes.comment_view.comment.id
);
expect(undeleteCommentRes.comment.deleted).toBe(false);
expect(undeleteCommentRes.comment_view.comment.deleted).toBe(false);
await delay();
// Make sure that comment is undeleted on beta
let searchBeta2 = await searchComment(beta, commentRes.comment);
let searchBeta2 = await searchComment(beta, commentRes.comment_view.comment);
let betaComment2 = searchBeta2.comments[0];
expect(betaComment2.deleted).toBe(false);
assertCommentFederation(searchBeta2.comments[0], undeleteCommentRes.comment);
expect(betaComment2.comment.deleted).toBe(false);
assertCommentFederation(
searchBeta2.comments[0],
undeleteCommentRes.comment_view
);
});
test('Remove a comment from admin and community on the same instance', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
await delay();
// Get the id for beta
let betaCommentId = (await searchComment(beta, commentRes.comment))
.comments[0].id;
let betaCommentId = (
await searchComment(beta, commentRes.comment_view.comment)
).comments[0].comment.id;
// The beta admin removes it (the community lives on beta)
let removeCommentRes = await removeComment(beta, true, betaCommentId);
expect(removeCommentRes.comment.removed).toBe(true);
expect(removeCommentRes.comment_view.comment.removed).toBe(true);
await longDelay();
// Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it)
let refetchedPost = await getPost(alpha, postRes.post.id);
expect(refetchedPost.comments[0].removed).toBe(true);
let refetchedPost = await getPost(alpha, postRes.post_view.post.id);
expect(refetchedPost.comments[0].comment.removed).toBe(true);
let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
expect(unremoveCommentRes.comment.removed).toBe(false);
expect(unremoveCommentRes.comment_view.comment.removed).toBe(false);
await longDelay();
// 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);
let refetchedPost2 = await getPost(alpha, postRes.post_view.post.id);
expect(refetchedPost2.comments[0].comment.removed).toBe(false);
assertCommentFederation(
refetchedPost2.comments[0],
unremoveCommentRes.comment_view
);
});
test('Remove a comment from admin and community on different instance', async () => {
@ -174,159 +189,170 @@ test('Remove a comment from admin and community on different instance', async ()
// New alpha user creates a community, post, and comment.
let newCommunity = await createCommunity(newAlphaApi);
await delay();
let newPost = await createPost(newAlphaApi, newCommunity.community.id);
let newPost = await createPost(
newAlphaApi,
newCommunity.community_view.community.id
);
await delay();
let commentRes = await createComment(newAlphaApi, newPost.post.id);
expect(commentRes.comment.content).toBeDefined();
let commentRes = await createComment(newAlphaApi, newPost.post_view.post.id);
expect(commentRes.comment_view.comment.content).toBeDefined();
await delay();
// Beta searches that to cache it, then removes it
let searchBeta = await searchComment(beta, commentRes.comment);
let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
let betaComment = searchBeta.comments[0];
let removeCommentRes = await removeComment(beta, true, betaComment.id);
expect(removeCommentRes.comment.removed).toBe(true);
let removeCommentRes = await removeComment(
beta,
true,
betaComment.comment.id
);
expect(removeCommentRes.comment_view.comment.removed).toBe(true);
await delay();
// 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);
let refetchedPost = await getPost(newAlphaApi, newPost.post_view.post.id);
expect(refetchedPost.comments[0].comment.removed).toBe(false);
assertCommentFederation(refetchedPost.comments[0], commentRes.comment_view);
});
test('Unlike a comment', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
await delay();
let unlike = await likeComment(alpha, 0, commentRes.comment);
expect(unlike.comment.score).toBe(0);
let unlike = await likeComment(alpha, 0, commentRes.comment_view.comment);
expect(unlike.comment_view.counts.score).toBe(0);
await delay();
// Make sure that post is unliked on beta
let searchBeta = await searchComment(beta, commentRes.comment);
let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
let betaComment = searchBeta.comments[0];
expect(betaComment).toBeDefined();
expect(betaComment.community_local).toBe(true);
expect(betaComment.creator_local).toBe(false);
expect(betaComment.score).toBe(0);
expect(betaComment.community.local).toBe(true);
expect(betaComment.creator.local).toBe(false);
expect(betaComment.counts.score).toBe(0);
});
test('Federated comment like', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
await longDelay();
// Find the comment on beta
let searchBeta = await searchComment(beta, commentRes.comment);
let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
let betaComment = searchBeta.comments[0];
let like = await likeComment(beta, 1, betaComment);
expect(like.comment.score).toBe(2);
let like = await likeComment(beta, 1, betaComment.comment);
expect(like.comment_view.counts.score).toBe(2);
await longDelay();
// Get the post from alpha, check the likes
let post = await getPost(alpha, postRes.post.id);
expect(post.comments[0].score).toBe(2);
let post = await getPost(alpha, postRes.post_view.post.id);
expect(post.comments[0].counts.score).toBe(2);
});
test('Reply to a comment', async () => {
// Create a comment on alpha, find it on beta
let commentRes = await createComment(alpha, postRes.post.id);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
await delay();
let searchBeta = await searchComment(beta, commentRes.comment);
let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
let betaComment = searchBeta.comments[0];
// find that comment id on beta
// Reply from beta
let replyRes = await createComment(beta, betaComment.post_id, betaComment.id);
expect(replyRes.comment.content).toBeDefined();
expect(replyRes.comment.community_local).toBe(true);
expect(replyRes.comment.creator_local).toBe(true);
expect(replyRes.comment.parent_id).toBe(betaComment.id);
expect(replyRes.comment.score).toBe(1);
let replyRes = await createComment(
beta,
betaComment.post.id,
betaComment.comment.id
);
expect(replyRes.comment_view.comment.content).toBeDefined();
expect(replyRes.comment_view.community.local).toBe(true);
expect(replyRes.comment_view.creator.local).toBe(true);
expect(replyRes.comment_view.comment.parent_id).toBe(betaComment.comment.id);
expect(replyRes.comment_view.counts.score).toBe(1);
await longDelay();
// Make sure that comment is seen on alpha
// TODO not sure why, but a searchComment back to alpha, for the ap_id of betas
// comment, isn't working.
// let searchAlpha = await searchComment(alpha, replyRes.comment);
let post = await getPost(alpha, postRes.post.id);
let post = await getPost(alpha, postRes.post_view.post.id);
let alphaComment = post.comments[0];
expect(alphaComment.content).toBeDefined();
expect(alphaComment.parent_id).toBe(post.comments[1].id);
expect(alphaComment.community_local).toBe(false);
expect(alphaComment.creator_local).toBe(false);
expect(alphaComment.score).toBe(1);
assertCommentFederation(alphaComment, replyRes.comment);
expect(alphaComment.comment.content).toBeDefined();
expect(alphaComment.comment.parent_id).toBe(post.comments[1].comment.id);
expect(alphaComment.community.local).toBe(false);
expect(alphaComment.creator.local).toBe(false);
expect(alphaComment.counts.score).toBe(1);
assertCommentFederation(alphaComment, replyRes.comment_view);
});
test('Mention beta', async () => {
// Create a mention on alpha
let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8551';
let commentRes = await createComment(alpha, postRes.post.id);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
await delay();
let mentionRes = await createComment(
alpha,
postRes.post.id,
commentRes.comment.id,
postRes.post_view.post.id,
commentRes.comment_view.comment.id,
mentionContent
);
expect(mentionRes.comment.content).toBeDefined();
expect(mentionRes.comment.community_local).toBe(false);
expect(mentionRes.comment.creator_local).toBe(true);
expect(mentionRes.comment.score).toBe(1);
expect(mentionRes.comment_view.comment.content).toBeDefined();
expect(mentionRes.comment_view.community.local).toBe(false);
expect(mentionRes.comment_view.creator.local).toBe(true);
expect(mentionRes.comment_view.counts.score).toBe(1);
await delay();
let mentionsRes = await getMentions(beta);
expect(mentionsRes.mentions[0].content).toBeDefined();
expect(mentionsRes.mentions[0].community_local).toBe(true);
expect(mentionsRes.mentions[0].creator_local).toBe(false);
expect(mentionsRes.mentions[0].score).toBe(1);
expect(mentionsRes.mentions[0].comment.content).toBeDefined();
expect(mentionsRes.mentions[0].community.local).toBe(true);
expect(mentionsRes.mentions[0].creator.local).toBe(false);
expect(mentionsRes.mentions[0].counts.score).toBe(1);
});
test('Comment Search', async () => {
let commentRes = await createComment(alpha, postRes.post.id);
let commentRes = await createComment(alpha, postRes.post_view.post.id);
await delay();
let searchBeta = await searchComment(beta, commentRes.comment);
assertCommentFederation(searchBeta.comments[0], commentRes.comment);
let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
assertCommentFederation(searchBeta.comments[0], commentRes.comment_view);
});
test('A and G subscribe to B (center) A posts, G mentions B, it gets announced to A', async () => {
// Create a local post
let alphaPost = await createPost(alpha, 2);
expect(alphaPost.post.community_local).toBe(true);
expect(alphaPost.post_view.community.local).toBe(true);
await delay();
// Make sure gamma sees it
let search = await searchPost(gamma, alphaPost.post);
let search = await searchPost(gamma, alphaPost.post_view.post);
let gammaPost = search.posts[0];
let commentContent =
'A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8551';
let commentRes = await createComment(
gamma,
gammaPost.id,
gammaPost.post.id,
undefined,
commentContent
);
expect(commentRes.comment.content).toBe(commentContent);
expect(commentRes.comment.community_local).toBe(false);
expect(commentRes.comment.creator_local).toBe(true);
expect(commentRes.comment.score).toBe(1);
expect(commentRes.comment_view.comment.content).toBe(commentContent);
expect(commentRes.comment_view.community.local).toBe(false);
expect(commentRes.comment_view.creator.local).toBe(true);
expect(commentRes.comment_view.counts.score).toBe(1);
await longDelay();
// Make sure alpha sees it
let alphaPost2 = await getPost(alpha, alphaPost.post.id);
expect(alphaPost2.comments[0].content).toBe(commentContent);
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);
let alphaPost2 = await getPost(alpha, alphaPost.post_view.post.id);
expect(alphaPost2.comments[0].comment.content).toBe(commentContent);
expect(alphaPost2.comments[0].community.local).toBe(true);
expect(alphaPost2.comments[0].creator.local).toBe(false);
expect(alphaPost2.comments[0].counts.score).toBe(1);
assertCommentFederation(alphaPost2.comments[0], commentRes.comment_view);
await delay();
// Make sure beta has mentions
let mentionsRes = await getMentions(beta);
expect(mentionsRes.mentions[0].content).toBe(commentContent);
expect(mentionsRes.mentions[0].community_local).toBe(false);
expect(mentionsRes.mentions[0].creator_local).toBe(false);
expect(mentionsRes.mentions[0].comment.content).toBe(commentContent);
expect(mentionsRes.mentions[0].community.local).toBe(false);
expect(mentionsRes.mentions[0].creator.local).toBe(false);
// TODO this is failing because fetchInReplyTos aren't getting score
// expect(mentionsRes.mentions[0].score).toBe(1);
});
@ -335,60 +361,64 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
// Unfollow all remote communities
let followed = await unfollowRemotes(alpha);
expect(
followed.communities.filter(c => c.community_local == false).length
followed.communities.filter(c => c.community.local == false).length
).toBe(0);
// B creates a post, and two comments, should be invisible to A
let postRes = await createPost(beta, 2);
expect(postRes.post.name).toBeDefined();
expect(postRes.post_view.post.name).toBeDefined();
await delay();
let parentCommentContent = 'An invisible top level comment from beta';
let parentCommentRes = await createComment(
beta,
postRes.post.id,
postRes.post_view.post.id,
undefined,
parentCommentContent
);
expect(parentCommentRes.comment.content).toBe(parentCommentContent);
expect(parentCommentRes.comment_view.comment.content).toBe(
parentCommentContent
);
await delay();
// B creates a comment, then a child one of that.
let childCommentContent = 'An invisible child comment from beta';
let childCommentRes = await createComment(
beta,
postRes.post.id,
parentCommentRes.comment.id,
postRes.post_view.post.id,
parentCommentRes.comment_view.comment.id,
childCommentContent
);
expect(childCommentRes.comment_view.comment.content).toBe(
childCommentContent
);
expect(childCommentRes.comment.content).toBe(childCommentContent);
await delay();
// Follow beta again
let follow = await followBeta(alpha);
expect(follow.community.local).toBe(false);
expect(follow.community.name).toBe('main');
expect(follow.community_view.community.local).toBe(false);
expect(follow.community_view.community.name).toBe('main');
await delay();
// An update to the child comment on beta, should push the post, parent, and child to alpha now
let updatedCommentContent = 'An update child comment from beta';
let updateRes = await updateComment(
let updateRes = await editComment(
beta,
childCommentRes.comment.id,
childCommentRes.comment_view.comment.id,
updatedCommentContent
);
expect(updateRes.comment.content).toBe(updatedCommentContent);
expect(updateRes.comment_view.comment.content).toBe(updatedCommentContent);
await delay();
// Get the post from alpha
let search = await searchPost(alpha, postRes.post);
let search = await searchPost(alpha, postRes.post_view.post);
let alphaPostB = search.posts[0];
await longDelay();
let alphaPost = await getPost(alpha, alphaPostB.id);
expect(alphaPost.post.name).toBeDefined();
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);
let alphaPost = await getPost(alpha, alphaPostB.post.id);
expect(alphaPost.post_view.post.name).toBeDefined();
assertCommentFederation(alphaPost.comments[1], parentCommentRes.comment_view);
assertCommentFederation(alphaPost.comments[0], updateRes.comment_view);
expect(alphaPost.post_view.community.local).toBe(false);
expect(alphaPost.post_view.creator.local).toBe(false);
});

View File

@ -3,7 +3,6 @@ import {
alpha,
beta,
setupLogins,
searchForBetaCommunity,
searchForCommunity,
createCommunity,
deleteCommunity,
@ -11,40 +10,44 @@ import {
getCommunity,
followCommunity,
delay,
longDelay,
} from './shared';
import {
Community,
} from 'lemmy-js-client';
import { CommunityView } 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);
communityOne: CommunityView,
communityTwo: CommunityView
) {
expect(communityOne.community.actor_id).toBe(communityTwo.community.actor_id);
expect(communityOne.community.name).toBe(communityTwo.community.name);
expect(communityOne.community.title).toBe(communityTwo.community.title);
expect(communityOne.community.description).toBe(
communityTwo.community.description
);
expect(communityOne.community.icon).toBe(communityTwo.community.icon);
expect(communityOne.community.banner).toBe(communityTwo.community.banner);
expect(communityOne.community.published).toBe(
communityTwo.community.published
);
expect(communityOne.creator.actor_id).toBe(communityTwo.creator.actor_id);
expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
expect(communityOne.community.category_id).toBe(
communityTwo.community.category_id
);
expect(communityOne.community.removed).toBe(communityTwo.community.removed);
expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
}
test('Create community', async () => {
let communityRes = await createCommunity(alpha);
expect(communityRes.community.name).toBeDefined();
expect(communityRes.community_view.community.name).toBeDefined();
// A dupe check
let prevName = communityRes.community.name;
let communityRes2 = await createCommunity(alpha, prevName);
let prevName = communityRes.community_view.community.name;
let communityRes2: any = await createCommunity(alpha, prevName);
expect(communityRes2['error']).toBe('community_already_exists');
await delay();
@ -52,7 +55,7 @@ test('Create community', async () => {
let searchShort = `!${prevName}@lemmy-alpha:8541`;
let search = await searchForCommunity(beta, searchShort);
let communityOnBeta = search.communities[0];
assertCommunityFederation(communityOnBeta, communityRes.community);
assertCommunityFederation(communityOnBeta, communityRes.community_view);
});
test('Delete community', async () => {
@ -60,44 +63,56 @@ test('Delete community', async () => {
await delay();
// Cache the community on Alpha
let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
let search = await searchForCommunity(alpha, searchShort);
let communityOnAlpha = search.communities[0];
assertCommunityFederation(communityOnAlpha, communityRes.community);
assertCommunityFederation(communityOnAlpha, communityRes.community_view);
await delay();
// Follow the community from alpha
let follow = await followCommunity(alpha, true, communityOnAlpha.id);
let follow = await followCommunity(
alpha,
true,
communityOnAlpha.community.id
);
// Make sure the follow response went through
expect(follow.community.local).toBe(false);
expect(follow.community_view.community.local).toBe(false);
await delay();
let deleteCommunityRes = await deleteCommunity(
beta,
true,
communityRes.community.id
communityRes.community_view.community.id
);
expect(deleteCommunityRes.community.deleted).toBe(true);
expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
await delay();
// Make sure it got deleted on A
let communityOnAlphaDeleted = await getCommunity(alpha, communityOnAlpha.id);
expect(communityOnAlphaDeleted.community.deleted).toBe(true);
let communityOnAlphaDeleted = await getCommunity(
alpha,
communityOnAlpha.community.id
);
expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
await delay();
// Undelete
let undeleteCommunityRes = await deleteCommunity(
beta,
false,
communityRes.community.id
communityRes.community_view.community.id
);
expect(undeleteCommunityRes.community.deleted).toBe(false);
expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
await delay();
// Make sure it got undeleted on A
let communityOnAlphaUnDeleted = await getCommunity(alpha, communityOnAlpha.id);
expect(communityOnAlphaUnDeleted.community.deleted).toBe(false);
let communityOnAlphaUnDeleted = await getCommunity(
alpha,
communityOnAlpha.community.id
);
expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
false
);
});
test('Remove community', async () => {
@ -105,53 +120,65 @@ test('Remove community', async () => {
await delay();
// Cache the community on Alpha
let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
let search = await searchForCommunity(alpha, searchShort);
let communityOnAlpha = search.communities[0];
assertCommunityFederation(communityOnAlpha, communityRes.community);
assertCommunityFederation(communityOnAlpha, communityRes.community_view);
await delay();
// Follow the community from alpha
let follow = await followCommunity(alpha, true, communityOnAlpha.id);
let follow = await followCommunity(
alpha,
true,
communityOnAlpha.community.id
);
// Make sure the follow response went through
expect(follow.community.local).toBe(false);
expect(follow.community_view.community.local).toBe(false);
await delay();
let removeCommunityRes = await removeCommunity(
beta,
true,
communityRes.community.id
communityRes.community_view.community.id
);
expect(removeCommunityRes.community.removed).toBe(true);
expect(removeCommunityRes.community_view.community.removed).toBe(true);
await delay();
// Make sure it got Removed on A
let communityOnAlphaRemoved = await getCommunity(alpha, communityOnAlpha.id);
expect(communityOnAlphaRemoved.community.removed).toBe(true);
let communityOnAlphaRemoved = await getCommunity(
alpha,
communityOnAlpha.community.id
);
expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
await delay();
// unremove
let unremoveCommunityRes = await removeCommunity(
beta,
false,
communityRes.community.id
communityRes.community_view.community.id
);
expect(unremoveCommunityRes.community.removed).toBe(false);
expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
await delay();
// Make sure it got undeleted on A
let communityOnAlphaUnRemoved = await getCommunity(alpha, communityOnAlpha.id);
expect(communityOnAlphaUnRemoved.community.removed).toBe(false);
let communityOnAlphaUnRemoved = await getCommunity(
alpha,
communityOnAlpha.community.id
);
expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
false
);
});
test('Search for beta community', async () => {
let communityRes = await createCommunity(beta);
expect(communityRes.community.name).toBeDefined();
expect(communityRes.community_view.community.name).toBeDefined();
await delay();
let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
let search = await searchForCommunity(alpha, searchShort);
let communityOnAlpha = search.communities[0];
assertCommunityFederation(communityOnAlpha, communityRes.community);
assertCommunityFederation(communityOnAlpha, communityRes.community_view);
});

View File

@ -20,24 +20,28 @@ afterAll(async () => {
test('Follow federated community', async () => {
let search = await searchForBetaCommunity(alpha); // TODO sometimes this is returning null?
let follow = await followCommunity(alpha, true, search.communities[0].id);
let follow = await followCommunity(
alpha,
true,
search.communities[0].community.id
);
// Make sure the follow response went through
expect(follow.community.local).toBe(false);
expect(follow.community.name).toBe('main');
expect(follow.community_view.community.local).toBe(false);
expect(follow.community_view.community.name).toBe('main');
await longDelay();
// Check it from local
let followCheck = await checkFollowedCommunities(alpha);
await delay();
let remoteCommunityId = followCheck.communities.filter(
c => c.community_local == false
)[0].community_id;
let remoteCommunityId = followCheck.communities.find(
c => c.community.local == false
).community.id;
expect(remoteCommunityId).toBeDefined();
// Test an unfollow
let unfollow = await followCommunity(alpha, false, remoteCommunityId);
expect(unfollow.community.local).toBe(false);
expect(unfollow.community_view.community.local).toBe(false);
await delay();
// Make sure you are unsubbed locally

View File

@ -7,7 +7,7 @@ import {
epsilon,
setupLogins,
createPost,
updatePost,
editPost,
stickyPost,
lockPost,
searchPost,
@ -26,9 +26,7 @@ import {
searchPostLocal,
banUserFromCommunity,
} from './shared';
import {
Post,
} from 'lemmy-js-client';
import { PostView } from 'lemmy-js-client';
beforeAll(async () => {
await setupLogins();
@ -46,50 +44,48 @@ afterAll(async () => {
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);
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.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.published).toBe(postTwo.post.published);
expect(postOne.community.actor_id).toBe(postTwo.community.actor_id);
expect(postOne.post.locked).toBe(postTwo.post.locked);
expect(postOne.post.removed).toBe(postTwo.post.removed);
expect(postOne.post.deleted).toBe(postTwo.post.deleted);
}
test('Create a post', async () => {
let search = await searchForBetaCommunity(alpha);
await delay();
let postRes = await createPost(alpha, search.communities[0].id);
expect(postRes.post).toBeDefined();
expect(postRes.post.community_local).toBe(false);
expect(postRes.post.creator_local).toBe(true);
expect(postRes.post.score).toBe(1);
let postRes = await createPost(alpha, search.communities[0].community.id);
expect(postRes.post_view.post).toBeDefined();
expect(postRes.post_view.community.local).toBe(false);
expect(postRes.post_view.creator.local).toBe(true);
expect(postRes.post_view.counts.score).toBe(1);
await longDelay();
// Make sure that post is liked on beta
let searchBeta = await searchPost(beta, postRes.post);
let searchBeta = await searchPost(beta, postRes.post_view.post);
let betaPost = searchBeta.posts[0];
expect(betaPost).toBeDefined();
expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false);
expect(betaPost.score).toBe(1);
assertPostFederation(betaPost, postRes.post);
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(betaPost.counts.score).toBe(1);
assertPostFederation(betaPost, postRes.post_view);
// Delta only follows beta, so it should not see an alpha ap_id
let searchDelta = await searchPost(delta, postRes.post);
let searchDelta = await searchPost(delta, postRes.post_view.post);
expect(searchDelta.posts[0]).toBeUndefined();
// Epsilon has alpha blocked, it should not see the alpha post
let searchEpsilon = await searchPost(epsilon, postRes.post);
let searchEpsilon = await searchPost(epsilon, postRes.post_view.post);
expect(searchEpsilon.posts[0]).toBeUndefined();
});
@ -100,245 +96,244 @@ test('Create a post in a non-existent community', async () => {
test('Unlike a post', async () => {
let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id);
let postRes = await createPost(alpha, search.communities[0].community.id);
await delay();
let unlike = await likePost(alpha, 0, postRes.post);
expect(unlike.post.score).toBe(0);
let unlike = await likePost(alpha, 0, postRes.post_view.post);
expect(unlike.post_view.counts.score).toBe(0);
await delay();
// Try to unlike it again, make sure it stays at 0
let unlike2 = await likePost(alpha, 0, postRes.post);
expect(unlike2.post.score).toBe(0);
let unlike2 = await likePost(alpha, 0, postRes.post_view.post);
expect(unlike2.post_view.counts.score).toBe(0);
await longDelay();
// Make sure that post is unliked on beta
let searchBeta = await searchPost(beta, postRes.post);
let searchBeta = await searchPost(beta, postRes.post_view.post);
let betaPost = searchBeta.posts[0];
expect(betaPost).toBeDefined();
expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false);
expect(betaPost.score).toBe(0);
assertPostFederation(betaPost, postRes.post);
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(betaPost.counts.score).toBe(0);
assertPostFederation(betaPost, postRes.post_view);
});
test('Update a post', async () => {
let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id);
let postRes = await createPost(alpha, search.communities[0].community.id);
await delay();
let updatedName = 'A jest test federated post, updated';
let updatedPost = await updatePost(alpha, postRes.post);
expect(updatedPost.post.name).toBe(updatedName);
expect(updatedPost.post.community_local).toBe(false);
expect(updatedPost.post.creator_local).toBe(true);
let updatedPost = await editPost(alpha, postRes.post_view.post);
expect(updatedPost.post_view.post.name).toBe(updatedName);
expect(updatedPost.post_view.community.local).toBe(false);
expect(updatedPost.post_view.creator.local).toBe(true);
await delay();
// Make sure that post is updated on beta
let searchBeta = await searchPost(beta, postRes.post);
let searchBeta = await searchPost(beta, postRes.post_view.post);
let betaPost = searchBeta.posts[0];
expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false);
expect(betaPost.name).toBe(updatedName);
assertPostFederation(betaPost, updatedPost.post);
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(betaPost.post.name).toBe(updatedName);
assertPostFederation(betaPost, updatedPost.post_view);
await delay();
// Make sure lemmy beta cannot update the post
let updatedPostBeta = await updatePost(beta, betaPost);
let updatedPostBeta = await editPost(beta, betaPost.post);
expect(updatedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
});
test('Sticky a post', async () => {
let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id);
let postRes = await createPost(alpha, search.communities[0].community.id);
await delay();
let stickiedPostRes = await stickyPost(alpha, true, postRes.post);
expect(stickiedPostRes.post.stickied).toBe(true);
let stickiedPostRes = await stickyPost(alpha, true, postRes.post_view.post);
expect(stickiedPostRes.post_view.post.stickied).toBe(true);
await delay();
// Make sure that post is stickied on beta
let searchBeta = await searchPost(beta, postRes.post);
let searchBeta = await searchPost(beta, postRes.post_view.post);
let betaPost = searchBeta.posts[0];
expect(betaPost.community_local).toBe(true);
expect(betaPost.creator_local).toBe(false);
expect(betaPost.stickied).toBe(true);
expect(betaPost.community.local).toBe(true);
expect(betaPost.creator.local).toBe(false);
expect(betaPost.post.stickied).toBe(true);
// Unsticky a post
let unstickiedPost = await stickyPost(alpha, false, postRes.post);
expect(unstickiedPost.post.stickied).toBe(false);
let unstickiedPost = await stickyPost(alpha, false, postRes.post_view.post);
expect(unstickiedPost.post_view.post.stickied).toBe(false);
await delay();
// Make sure that post is unstickied on beta
let searchBeta2 = await searchPost(beta, postRes.post);
let searchBeta2 = await searchPost(beta, postRes.post_view.post);
let betaPost2 = searchBeta2.posts[0];
expect(betaPost2.community_local).toBe(true);
expect(betaPost2.creator_local).toBe(false);
expect(betaPost2.stickied).toBe(false);
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 searchGamma = await searchPost(gamma, postRes.post);
let searchGamma = await searchPost(gamma, postRes.post_view.post);
let gammaPost = searchGamma.posts[0];
let gammaTrySticky = await stickyPost(gamma, true, gammaPost);
let gammaTrySticky = await stickyPost(gamma, true, gammaPost.post);
await delay();
let searchBeta3 = await searchPost(beta, postRes.post);
let searchBeta3 = await searchPost(beta, postRes.post_view.post);
let betaPost3 = searchBeta3.posts[0];
expect(gammaTrySticky.post.stickied).toBe(true);
expect(betaPost3.stickied).toBe(false);
expect(gammaTrySticky.post_view.post.stickied).toBe(true);
expect(betaPost3.post.stickied).toBe(false);
});
test('Lock a post', async () => {
let search = await searchForBetaCommunity(alpha);
await delay();
let postRes = await createPost(alpha, search.communities[0].id);
let postRes = await createPost(alpha, search.communities[0].community.id);
await delay();
// Lock the post
let lockedPostRes = await lockPost(alpha, true, postRes.post);
expect(lockedPostRes.post.locked).toBe(true);
let lockedPostRes = await lockPost(alpha, true, postRes.post_view.post);
expect(lockedPostRes.post_view.post.locked).toBe(true);
await longDelay();
// Make sure that post is locked on beta
let searchBeta = await searchPostLocal(beta, postRes.post);
let searchBeta = await searchPostLocal(beta, postRes.post_view.post);
let betaPost1 = searchBeta.posts[0];
expect(betaPost1.locked).toBe(true);
expect(betaPost1.post.locked).toBe(true);
await delay();
// Try to make a new comment there, on alpha
let comment = await createComment(alpha, postRes.post.id);
let comment: any = await createComment(alpha, postRes.post_view.post.id);
expect(comment['error']).toBe('locked');
await delay();
// Unlock a post
let unlockedPost = await lockPost(alpha, false, postRes.post);
expect(unlockedPost.post.locked).toBe(false);
let unlockedPost = await lockPost(alpha, false, postRes.post_view.post);
expect(unlockedPost.post_view.post.locked).toBe(false);
await delay();
// Make sure that post is unlocked on beta
let searchBeta2 = await searchPost(beta, postRes.post);
let searchBeta2 = await searchPost(beta, postRes.post_view.post);
let betaPost2 = searchBeta2.posts[0];
expect(betaPost2.community_local).toBe(true);
expect(betaPost2.creator_local).toBe(false);
expect(betaPost2.locked).toBe(false);
expect(betaPost2.community.local).toBe(true);
expect(betaPost2.creator.local).toBe(false);
expect(betaPost2.post.locked).toBe(false);
// Try to create a new comment, on beta
let commentBeta = await createComment(beta, betaPost2.id);
let commentBeta = await createComment(beta, betaPost2.post.id);
expect(commentBeta).toBeDefined();
});
test('Delete a post', async () => {
let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id);
let postRes = await createPost(alpha, search.communities[0].community.id);
await delay();
let deletedPost = await deletePost(alpha, true, postRes.post);
expect(deletedPost.post.deleted).toBe(true);
let deletedPost = await deletePost(alpha, true, postRes.post_view.post);
expect(deletedPost.post_view.post.deleted).toBe(true);
await delay();
// Make sure lemmy beta sees post is deleted
let searchBeta = await searchPost(beta, postRes.post);
let searchBeta = await searchPost(beta, postRes.post_view.post);
let betaPost = searchBeta.posts[0];
// This will be undefined because of the tombstone
expect(betaPost).toBeUndefined();
await delay();
// Undelete
let undeletedPost = await deletePost(alpha, false, postRes.post);
expect(undeletedPost.post.deleted).toBe(false);
let undeletedPost = await deletePost(alpha, false, postRes.post_view.post);
expect(undeletedPost.post_view.post.deleted).toBe(false);
await delay();
// Make sure lemmy beta sees post is undeleted
let searchBeta2 = await searchPost(beta, postRes.post);
let searchBeta2 = await searchPost(beta, postRes.post_view.post);
let betaPost2 = searchBeta2.posts[0];
expect(betaPost2.deleted).toBe(false);
assertPostFederation(betaPost2, undeletedPost.post);
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);
let deletedPostBeta = await deletePost(beta, true, betaPost2.post);
expect(deletedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
});
test('Remove a post from admin and community on different instance', async () => {
let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id);
let postRes = await createPost(alpha, search.communities[0].community.id);
await delay();
let removedPost = await removePost(alpha, true, postRes.post);
expect(removedPost.post.removed).toBe(true);
let removedPost = await removePost(alpha, true, postRes.post_view.post);
expect(removedPost.post_view.post.removed).toBe(true);
await delay();
// Make sure lemmy beta sees post is NOT removed
let searchBeta = await searchPost(beta, postRes.post);
let searchBeta = await searchPost(beta, postRes.post_view.post);
let betaPost = searchBeta.posts[0];
expect(betaPost.removed).toBe(false);
expect(betaPost.post.removed).toBe(false);
await delay();
// Undelete
let undeletedPost = await removePost(alpha, false, postRes.post);
expect(undeletedPost.post.removed).toBe(false);
let undeletedPost = await removePost(alpha, false, postRes.post_view.post);
expect(undeletedPost.post_view.post.removed).toBe(false);
await delay();
// Make sure lemmy beta sees post is undeleted
let searchBeta2 = await searchPost(beta, postRes.post);
let searchBeta2 = await searchPost(beta, postRes.post_view.post);
let betaPost2 = searchBeta2.posts[0];
expect(betaPost2.removed).toBe(false);
assertPostFederation(betaPost2, undeletedPost.post);
expect(betaPost2.post.removed).toBe(false);
assertPostFederation(betaPost2, undeletedPost.post_view);
});
test('Remove a post from admin and community on same instance', async () => {
let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id);
let postRes = await createPost(alpha, search.communities[0].community.id);
await longDelay();
// Get the id for beta
let searchBeta = await searchPost(beta, postRes.post);
let searchBeta = await searchPost(beta, postRes.post_view.post);
let betaPost = searchBeta.posts[0];
await longDelay();
// The beta admin removes it (the community lives on beta)
let removePostRes = await removePost(beta, true, betaPost);
expect(removePostRes.post.removed).toBe(true);
let removePostRes = await removePost(beta, true, betaPost.post);
expect(removePostRes.post_view.post.removed).toBe(true);
await longDelay();
// 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);
let alphaPost = await getPost(alpha, postRes.post_view.post.id);
expect(alphaPost.post_view.post.removed).toBe(true);
assertPostFederation(alphaPost.post_view, removePostRes.post_view);
await longDelay();
// Undelete
let undeletedPost = await removePost(beta, false, betaPost);
expect(undeletedPost.post.removed).toBe(false);
let undeletedPost = await removePost(beta, false, betaPost.post);
expect(undeletedPost.post_view.post.removed).toBe(false);
await longDelay();
// Make sure lemmy alpha sees post is undeleted
let alphaPost2 = await getPost(alpha, postRes.post.id);
let alphaPost2 = await getPost(alpha, postRes.post_view.post.id);
await delay();
expect(alphaPost2.post.removed).toBe(false);
assertPostFederation(alphaPost2.post, undeletedPost.post);
expect(alphaPost2.post_view.post.removed).toBe(false);
assertPostFederation(alphaPost2.post_view, undeletedPost.post_view);
});
test('Search for a post', async () => {
let search = await searchForBetaCommunity(alpha);
await delay();
let postRes = await createPost(alpha, search.communities[0].id);
let postRes = await createPost(alpha, search.communities[0].community.id);
await delay();
let searchBeta = await searchPost(beta, postRes.post);
let searchBeta = await searchPost(beta, postRes.post_view.post);
expect(searchBeta.posts[0].name).toBeDefined();
expect(searchBeta.posts[0].post.name).toBeDefined();
});
test('A and G subscribe to B (center) A posts, it gets announced to G', async () => {
let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id);
let postRes = await createPost(alpha, search.communities[0].community.id);
await delay();
let search2 = await searchPost(gamma, postRes.post);
expect(search2.posts[0].name).toBeDefined();
let search2 = await searchPost(gamma, postRes.post_view.post);
expect(search2.posts[0].post.name).toBeDefined();
});
test('Enforce site ban for federated user', async () => {
let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
let userSearch = await searchForUser(beta, alphaShortname);
let alphaUser = userSearch.users[0];
@ -346,28 +341,28 @@ test('Enforce site ban for federated user', async () => {
await delay();
// ban alpha from beta site
let banAlpha = await banUserFromSite(beta, alphaUser.id, true);
let banAlpha = await banUserFromSite(beta, alphaUser.user.id, true);
expect(banAlpha.banned).toBe(true);
await longDelay();
// Alpha makes post on beta
let search = await searchForBetaCommunity(alpha);
await delay();
let postRes = await createPost(alpha, search.communities[0].id);
expect(postRes.post).toBeDefined();
expect(postRes.post.community_local).toBe(false);
expect(postRes.post.creator_local).toBe(true);
expect(postRes.post.score).toBe(1);
let postRes = await createPost(alpha, search.communities[0].community.id);
expect(postRes.post_view.post).toBeDefined();
expect(postRes.post_view.community.local).toBe(false);
expect(postRes.post_view.creator.local).toBe(true);
expect(postRes.post_view.counts.score).toBe(1);
await longDelay();
// Make sure that post doesn't make it to beta
let searchBeta = await searchPostLocal(beta, postRes.post);
let searchBeta = await searchPostLocal(beta, postRes.post_view.post);
let betaPost = searchBeta.posts[0];
expect(betaPost).toBeUndefined();
await delay();
// Unban alpha
let unBanAlpha = await banUserFromSite(beta, alphaUser.id, false);
let unBanAlpha = await banUserFromSite(beta, alphaUser.user.id, false);
expect(unBanAlpha.banned).toBe(false);
});
@ -379,27 +374,32 @@ test('Enforce community ban for federated user', async () => {
await delay();
// ban alpha from beta site
await banUserFromCommunity(beta, alphaUser.id, 2, false);
let banAlpha = await banUserFromCommunity(beta, alphaUser.id, 2, true);
await banUserFromCommunity(beta, alphaUser.user.id, 2, false);
let banAlpha = await banUserFromCommunity(beta, alphaUser.user.id, 2, true);
expect(banAlpha.banned).toBe(true);
await longDelay();
// Alpha makes post on beta
let search = await searchForBetaCommunity(alpha);
await delay();
let postRes = await createPost(alpha, search.communities[0].id);
expect(postRes.post).toBeDefined();
expect(postRes.post.community_local).toBe(false);
expect(postRes.post.creator_local).toBe(true);
expect(postRes.post.score).toBe(1);
let postRes = await createPost(alpha, search.communities[0].community.id);
expect(postRes.post_view.post).toBeDefined();
expect(postRes.post_view.community.local).toBe(false);
expect(postRes.post_view.creator.local).toBe(true);
expect(postRes.post_view.counts.score).toBe(1);
await longDelay();
// Make sure that post doesn't make it to beta community
let searchBeta = await searchPostLocal(beta, postRes.post);
let searchBeta = await searchPostLocal(beta, postRes.post_view.post);
let betaPost = searchBeta.posts[0];
expect(betaPost).toBeUndefined();
// Unban alpha
let unBanAlpha = await banUserFromCommunity(beta, alphaUser.id, 2, false);
let unBanAlpha = await banUserFromCommunity(
beta,
alphaUser.user.id,
2,
false
);
expect(unBanAlpha.banned).toBe(false);
});

View File

@ -5,7 +5,7 @@ import {
setupLogins,
followBeta,
createPrivateMessage,
updatePrivateMessage,
editPrivateMessage,
listPrivateMessages,
deletePrivateMessage,
unfollowRemotes,
@ -19,7 +19,7 @@ beforeAll(async () => {
await setupLogins();
let follow = await followBeta(alpha);
await longDelay();
recipient_id = follow.community.creator_id;
recipient_id = follow.community_view.creator.id;
});
afterAll(async () => {
@ -28,55 +28,72 @@ afterAll(async () => {
test('Create a private message', async () => {
let pmRes = await createPrivateMessage(alpha, recipient_id);
expect(pmRes.message.content).toBeDefined();
expect(pmRes.message.local).toBe(true);
expect(pmRes.message.creator_local).toBe(true);
expect(pmRes.message.recipient_local).toBe(false);
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);
await delay();
let betaPms = await listPrivateMessages(beta);
expect(betaPms.messages[0].content).toBeDefined();
expect(betaPms.messages[0].local).toBe(false);
expect(betaPms.messages[0].creator_local).toBe(false);
expect(betaPms.messages[0].recipient_local).toBe(true);
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);
});
test('Update a private message', async () => {
let updatedContent = 'A jest test federated private message edited';
let pmRes = await createPrivateMessage(alpha, recipient_id);
let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id);
expect(pmUpdated.message.content).toBe(updatedContent);
let pmUpdated = await editPrivateMessage(
alpha,
pmRes.private_message_view.private_message.id
);
expect(pmUpdated.private_message_view.private_message.content).toBe(
updatedContent
);
await longDelay();
let betaPms = await listPrivateMessages(beta);
expect(betaPms.messages[0].content).toBe(updatedContent);
expect(betaPms.private_messages[0].private_message.content).toBe(
updatedContent
);
});
test('Delete a private message', async () => {
let pmRes = await createPrivateMessage(alpha, recipient_id);
await delay();
let betaPms1 = await listPrivateMessages(beta);
let deletedPmRes = await deletePrivateMessage(alpha, true, pmRes.message.id);
expect(deletedPmRes.message.deleted).toBe(true);
let deletedPmRes = await deletePrivateMessage(
alpha,
true,
pmRes.private_message_view.private_message.id
);
expect(deletedPmRes.private_message_view.private_message.deleted).toBe(true);
await delay();
// The GetPrivateMessages filters out deleted,
// even though they are in the actual database.
// no reason to show them
let betaPms2 = await listPrivateMessages(beta);
expect(betaPms2.messages.length).toBe(betaPms1.messages.length - 1);
expect(betaPms2.private_messages.length).toBe(
betaPms1.private_messages.length - 1
);
await delay();
// Undelete
let undeletedPmRes = await deletePrivateMessage(
alpha,
false,
pmRes.message.id
pmRes.private_message_view.private_message.id
);
expect(undeletedPmRes.private_message_view.private_message.deleted).toBe(
false
);
expect(undeletedPmRes.message.deleted).toBe(false);
await longDelay();
let betaPms3 = await listPrivateMessages(beta);
expect(betaPms3.messages.length).toBe(betaPms1.messages.length);
expect(betaPms3.private_messages.length).toBe(
betaPms1.private_messages.length
);
});

View File

@ -1,52 +1,54 @@
import {
LoginForm,
Login,
LoginResponse,
Post,
PostForm,
Comment,
DeletePostForm,
RemovePostForm,
StickyPostForm,
LockPostForm,
CreatePost,
EditPost,
CreateComment,
DeletePost,
RemovePost,
StickyPost,
LockPost,
PostResponse,
SearchResponse,
FollowCommunityForm,
FollowCommunity,
CommunityResponse,
GetFollowedCommunitiesResponse,
GetPostResponse,
RegisterForm,
CommentForm,
DeleteCommentForm,
RemoveCommentForm,
SearchForm,
Register,
Comment,
EditComment,
DeleteComment,
RemoveComment,
Search,
CommentResponse,
GetCommunityForm,
CommunityForm,
DeleteCommunityForm,
RemoveCommunityForm,
GetUserMentionsForm,
CommentLikeForm,
CreatePostLikeForm,
PrivateMessageForm,
EditPrivateMessageForm,
DeletePrivateMessageForm,
GetFollowedCommunitiesForm,
GetPrivateMessagesForm,
GetSiteForm,
GetPostForm,
GetCommunity,
CreateCommunity,
DeleteCommunity,
RemoveCommunity,
GetUserMentions,
CreateCommentLike,
CreatePostLike,
EditPrivateMessage,
DeletePrivateMessage,
GetFollowedCommunities,
GetPrivateMessages,
GetSite,
GetPost,
PrivateMessageResponse,
PrivateMessagesResponse,
GetUserMentionsResponse,
UserSettingsForm,
SaveUserSettings,
SortType,
ListingType,
GetSiteResponse,
SearchType,
LemmyHttp,
BanUserResponse,
BanUserForm,
BanFromCommunityForm,
BanUser,
BanFromCommunity,
BanFromCommunityResponse,
Post,
CreatePrivateMessage,
} from 'lemmy-js-client';
export interface API {
@ -55,27 +57,27 @@ export interface API {
}
export let alpha: API = {
client: new LemmyHttp('http://localhost:8541/api/v1'),
client: new LemmyHttp('http://localhost:8541/api/v2'),
};
export let beta: API = {
client: new LemmyHttp('http://localhost:8551/api/v1'),
client: new LemmyHttp('http://localhost:8551/api/v2'),
};
export let gamma: API = {
client: new LemmyHttp('http://localhost:8561/api/v1'),
client: new LemmyHttp('http://localhost:8561/api/v2'),
};
export let delta: API = {
client: new LemmyHttp('http://localhost:8571/api/v1'),
client: new LemmyHttp('http://localhost:8571/api/v2'),
};
export let epsilon: API = {
client: new LemmyHttp('http://localhost:8581/api/v1'),
client: new LemmyHttp('http://localhost:8581/api/v2'),
};
export async function setupLogins() {
let formAlpha: LoginForm = {
let formAlpha: Login = {
username_or_email: 'lemmy_alpha',
password: 'lemmy',
};
@ -127,7 +129,7 @@ export async function createPost(
let name = randomString(5);
let body = randomString(10);
let url = 'https://google.com/';
let form: PostForm = {
let form: CreatePost = {
name,
url,
body,
@ -138,9 +140,9 @@ export async function createPost(
return api.client.createPost(form);
}
export async function updatePost(api: API, post: Post): Promise<PostResponse> {
export async function editPost(api: API, post: Post): Promise<PostResponse> {
let name = 'A jest test federated post, updated';
let form: PostForm = {
let form: EditPost = {
name,
edit_id: post.id,
auth: api.auth,
@ -154,7 +156,7 @@ export async function deletePost(
deleted: boolean,
post: Post
): Promise<PostResponse> {
let form: DeletePostForm = {
let form: DeletePost = {
edit_id: post.id,
deleted: deleted,
auth: api.auth,
@ -167,7 +169,7 @@ export async function removePost(
removed: boolean,
post: Post
): Promise<PostResponse> {
let form: RemovePostForm = {
let form: RemovePost = {
edit_id: post.id,
removed,
auth: api.auth,
@ -180,7 +182,7 @@ export async function stickyPost(
stickied: boolean,
post: Post
): Promise<PostResponse> {
let form: StickyPostForm = {
let form: StickyPost = {
edit_id: post.id,
stickied,
auth: api.auth,
@ -193,7 +195,7 @@ export async function lockPost(
locked: boolean,
post: Post
): Promise<PostResponse> {
let form: LockPostForm = {
let form: LockPost = {
edit_id: post.id,
locked,
auth: api.auth,
@ -205,7 +207,7 @@ export async function searchPost(
api: API,
post: Post
): Promise<SearchResponse> {
let form: SearchForm = {
let form: Search = {
q: post.ap_id,
type_: SearchType.Posts,
sort: SortType.TopAll,
@ -217,7 +219,7 @@ export async function searchPostLocal(
api: API,
post: Post
): Promise<SearchResponse> {
let form: SearchForm = {
let form: Search = {
q: post.name,
type_: SearchType.Posts,
sort: SortType.TopAll,
@ -229,7 +231,7 @@ export async function getPost(
api: API,
post_id: number
): Promise<GetPostResponse> {
let form: GetPostForm = {
let form: GetPost = {
id: post_id,
};
return api.client.getPost(form);
@ -239,7 +241,7 @@ export async function searchComment(
api: API,
comment: Comment
): Promise<SearchResponse> {
let form: SearchForm = {
let form: Search = {
q: comment.ap_id,
type_: SearchType.Comments,
sort: SortType.TopAll,
@ -252,7 +254,7 @@ export async function searchForBetaCommunity(
): Promise<SearchResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
// Use short-hand search url
let form: SearchForm = {
let form: Search = {
q: '!main@lemmy-beta:8551',
type_: SearchType.Communities,
sort: SortType.TopAll,
@ -262,10 +264,10 @@ export async function searchForBetaCommunity(
export async function searchForCommunity(
api: API,
q: string,
q: string
): Promise<SearchResponse> {
// Use short-hand search url
let form: SearchForm = {
let form: Search = {
q,
type_: SearchType.Communities,
sort: SortType.TopAll,
@ -279,7 +281,7 @@ export async function searchForUser(
): Promise<SearchResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
// Use short-hand search url
let form: SearchForm = {
let form: Search = {
q: apShortname,
type_: SearchType.Users,
sort: SortType.TopAll,
@ -290,13 +292,14 @@ export async function searchForUser(
export async function banUserFromSite(
api: API,
user_id: number,
ban: boolean,
ban: boolean
): Promise<BanUserResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
// Use short-hand search url
let form: BanUserForm = {
let form: BanUser = {
user_id,
ban,
remove_data: false,
auth: api.auth,
};
return api.client.banUser(form);
@ -306,13 +309,14 @@ export async function banUserFromCommunity(
api: API,
user_id: number,
community_id: number,
ban: boolean,
ban: boolean
): Promise<BanFromCommunityResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
// Use short-hand search url
let form: BanFromCommunityForm = {
let form: BanFromCommunity = {
user_id,
community_id,
remove_data: false,
ban,
auth: api.auth,
};
@ -324,7 +328,7 @@ export async function followCommunity(
follow: boolean,
community_id: number
): Promise<CommunityResponse> {
let form: FollowCommunityForm = {
let form: FollowCommunity = {
community_id,
follow,
auth: api.auth,
@ -335,7 +339,7 @@ export async function followCommunity(
export async function checkFollowedCommunities(
api: API
): Promise<GetFollowedCommunitiesResponse> {
let form: GetFollowedCommunitiesForm = {
let form: GetFollowedCommunities = {
auth: api.auth,
};
return api.client.getFollowedCommunities(form);
@ -346,7 +350,7 @@ export async function likePost(
score: number,
post: Post
): Promise<PostResponse> {
let form: CreatePostLikeForm = {
let form: CreatePostLike = {
post_id: post.id,
score: score,
auth: api.auth,
@ -361,7 +365,7 @@ export async function createComment(
parent_id?: number,
content = 'a jest test comment'
): Promise<CommentResponse> {
let form: CommentForm = {
let form: CreateComment = {
content,
post_id,
parent_id,
@ -370,12 +374,12 @@ export async function createComment(
return api.client.createComment(form);
}
export async function updateComment(
export async function editComment(
api: API,
edit_id: number,
content = 'A jest test federated comment update'
): Promise<CommentResponse> {
let form: CommentForm = {
let form: EditComment = {
content,
edit_id,
auth: api.auth,
@ -388,7 +392,7 @@ export async function deleteComment(
deleted: boolean,
edit_id: number
): Promise<CommentResponse> {
let form: DeleteCommentForm = {
let form: DeleteComment = {
edit_id,
deleted,
auth: api.auth,
@ -401,7 +405,7 @@ export async function removeComment(
removed: boolean,
edit_id: number
): Promise<CommentResponse> {
let form: RemoveCommentForm = {
let form: RemoveComment = {
edit_id,
removed,
auth: api.auth,
@ -410,7 +414,7 @@ export async function removeComment(
}
export async function getMentions(api: API): Promise<GetUserMentionsResponse> {
let form: GetUserMentionsForm = {
let form: GetUserMentions = {
sort: SortType.New,
unread_only: false,
auth: api.auth,
@ -423,7 +427,7 @@ export async function likeComment(
score: number,
comment: Comment
): Promise<CommentResponse> {
let form: CommentLikeForm = {
let form: CreateCommentLike = {
comment_id: comment.id,
score,
auth: api.auth,
@ -438,7 +442,7 @@ export async function createCommunity(
let description = 'a sample description';
let icon = 'https://image.flaticon.com/icons/png/512/35/35896.png';
let banner = 'https://image.flaticon.com/icons/png/512/35/35896.png';
let form: CommunityForm = {
let form: CreateCommunity = {
name: name_,
title: name_,
description,
@ -453,9 +457,9 @@ export async function createCommunity(
export async function getCommunity(
api: API,
id: number,
id: number
): Promise<CommunityResponse> {
let form: GetCommunityForm = {
let form: GetCommunity = {
id,
};
return api.client.getCommunity(form);
@ -466,7 +470,7 @@ export async function deleteCommunity(
deleted: boolean,
edit_id: number
): Promise<CommunityResponse> {
let form: DeleteCommunityForm = {
let form: DeleteCommunity = {
edit_id,
deleted,
auth: api.auth,
@ -479,7 +483,7 @@ export async function removeCommunity(
removed: boolean,
edit_id: number
): Promise<CommunityResponse> {
let form: RemoveCommunityForm = {
let form: RemoveCommunity = {
edit_id,
removed,
auth: api.auth,
@ -492,7 +496,7 @@ export async function createPrivateMessage(
recipient_id: number
): Promise<PrivateMessageResponse> {
let content = 'A jest test federated private message';
let form: PrivateMessageForm = {
let form: CreatePrivateMessage = {
content,
recipient_id,
auth: api.auth,
@ -500,12 +504,12 @@ export async function createPrivateMessage(
return api.client.createPrivateMessage(form);
}
export async function updatePrivateMessage(
export async function editPrivateMessage(
api: API,
edit_id: number
): Promise<PrivateMessageResponse> {
let updatedContent = 'A jest test federated private message edited';
let form: EditPrivateMessageForm = {
let form: EditPrivateMessage = {
content: updatedContent,
edit_id,
auth: api.auth,
@ -518,7 +522,7 @@ export async function deletePrivateMessage(
deleted: boolean,
edit_id: number
): Promise<PrivateMessageResponse> {
let form: DeletePrivateMessageForm = {
let form: DeletePrivateMessage = {
deleted,
edit_id,
auth: api.auth,
@ -530,7 +534,7 @@ export async function registerUser(
api: API,
username: string = randomString(5)
): Promise<LoginResponse> {
let form: RegisterForm = {
let form: Register = {
username,
password: 'test',
password_verify: 'test',
@ -544,11 +548,11 @@ export async function saveUserSettingsBio(
api: API,
auth: string
): Promise<LoginResponse> {
let form: UserSettingsForm = {
let form: SaveUserSettings = {
show_nsfw: true,
theme: 'darkly',
default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
default_sort_type: SortType.Active,
default_listing_type: ListingType.All,
lang: 'en',
show_avatars: true,
send_notifications_to_email: false,
@ -560,7 +564,7 @@ export async function saveUserSettingsBio(
export async function saveUserSettings(
api: API,
form: UserSettingsForm
form: SaveUserSettings
): Promise<LoginResponse> {
return api.client.saveUserSettings(form);
}
@ -569,7 +573,7 @@ export async function getSite(
api: API,
auth: string
): Promise<GetSiteResponse> {
let form: GetSiteForm = {
let form: GetSite = {
auth,
};
return api.client.getSite(form);
@ -578,7 +582,7 @@ export async function getSite(
export async function listPrivateMessages(
api: API
): Promise<PrivateMessagesResponse> {
let form: GetPrivateMessagesForm = {
let form: GetPrivateMessages = {
auth: api.auth,
unread_only: false,
limit: 999,
@ -592,10 +596,10 @@ export async function unfollowRemotes(
// Unfollow all remote communities
let followed = await checkFollowedCommunities(api);
let remoteFollowed = followed.communities.filter(
c => c.community_local == false
c => c.community.local == false
);
for (let cu of remoteFollowed) {
await followCommunity(api, false, cu.community_id);
await followCommunity(api, false, cu.community.id);
}
let followed2 = await checkFollowedCommunities(api);
return followed2;
@ -606,17 +610,15 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
// Cache it
let search = await searchForBetaCommunity(api);
let com = search.communities.filter(c => c.local == false);
if (com[0]) {
let follow = await followCommunity(api, true, com[0].id);
let com = search.communities.find(c => c.community.local == false);
if (com) {
let follow = await followCommunity(api, true, com.community.id);
return follow;
}
}
export function delay(millis: number = 500) {
return new Promise((resolve, _reject) => {
setTimeout(_ => resolve(), millis);
});
return new Promise(resolve => setTimeout(resolve, millis));
}
export function longDelay() {

View File

@ -9,23 +9,23 @@ import {
getSite,
} from './shared';
import {
UserView,
UserSettingsForm,
UserViewSafe,
SaveUserSettings,
SortType,
ListingType,
} 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);
expect(userOne.published).toBe(userTwo.published);
function assertUserFederation(userOne: UserViewSafe, userTwo: UserViewSafe) {
expect(userOne.user.name).toBe(userTwo.user.name);
expect(userOne.user.preferred_username).toBe(userTwo.user.preferred_username);
expect(userOne.user.bio).toBe(userTwo.user.bio);
expect(userOne.user.actor_id).toBe(userTwo.user.actor_id);
expect(userOne.user.avatar).toBe(userTwo.user.avatar);
expect(userOne.user.banner).toBe(userTwo.user.banner);
expect(userOne.user.published).toBe(userTwo.user.published);
}
test('Create user', async () => {
@ -55,20 +55,20 @@ test('Save user settings, check changed bio from beta', async () => {
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 = {
let form: SaveUserSettings = {
show_nsfw: false,
theme: "",
default_sort_type: 0,
default_listing_type: 0,
lang: "",
theme: '',
default_sort_type: SortType.Hot,
default_listing_type: ListingType.All,
lang: '',
avatar,
banner,
preferred_username: "user321",
preferred_username: 'user321',
show_avatars: false,
send_notifications_to_email: false,
auth,
}
let settingsRes = await saveUserSettings(alpha, form);
};
let _settingsRes = await saveUserSettings(alpha, form);
let searchAlpha = await searchForUser(beta, apShortname);
let userOnAlpha = searchAlpha.users[0];

16
api_tests/tsconfig.json Normal file
View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"declaration": true,
"declarationDir": "./dist",
"module": "CommonJS",
"noImplicitAny": true,
"lib": ["es2017", "es7", "es6", "dom"],
"outDir": "./dist",
"target": "ES5",
"moduleResolution": "Node"
},
"include": [
"src/**/*"
],
"exclude": ["node_modules", "dist"]
}

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ use serde::Deserialize;
pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
cfg.service(
web::scope("/api/v1")
web::scope("/api/v2")
// Websockets
.service(web::resource("/ws").to(super::websocket::chat_route))
// Site