Trying to re-add API tests.
This commit is contained in:
parent
4023fe96fc
commit
72ad278226
14 changed files with 5155 additions and 8 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -17,3 +17,6 @@ target
|
|||
env_setup.sh
|
||||
query_testing/*.json
|
||||
query_testing/*.json.old
|
||||
|
||||
# API tests
|
||||
api_tests/node_modules
|
||||
|
|
2
ansible/templates/config.hjson
vendored
2
ansible/templates/config.hjson
vendored
|
@ -13,8 +13,6 @@
|
|||
hostname: "{{ domain }}"
|
||||
# json web token for authorization between server and client
|
||||
jwt_secret: "{{ jwt_password }}"
|
||||
# The location of the frontend
|
||||
front_end_dir: "/app/dist"
|
||||
# email sending configuration
|
||||
email: {
|
||||
# hostname of the smtp server
|
||||
|
|
4
api_tests/jest.config.js
vendored
Normal file
4
api_tests/jest.config.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
};
|
20
api_tests/package.json
vendored
Normal file
20
api_tests/package.json
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "api_tests",
|
||||
"version": "0.0.1",
|
||||
"description": "API tests for lemmy backend",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/LemmyNet/lemmy",
|
||||
"author": "Dessalines",
|
||||
"license": "AGPL-3.0",
|
||||
"scripts": {
|
||||
"api-test": "jest src/ -i --verbose"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.13",
|
||||
"jest": "^26.4.2",
|
||||
"lemmy-js-client": "^1.0.11",
|
||||
"node-fetch": "^2.6.1",
|
||||
"ts-jest": "^26.3.0",
|
||||
"typescript": "^4.0.2"
|
||||
}
|
||||
}
|
367
api_tests/src/comment.spec.ts
vendored
Normal file
367
api_tests/src/comment.spec.ts
vendored
Normal file
|
@ -0,0 +1,367 @@
|
|||
jest.setTimeout(120000);
|
||||
import {
|
||||
alpha,
|
||||
beta,
|
||||
gamma,
|
||||
setupLogins,
|
||||
createPost,
|
||||
getPost,
|
||||
searchComment,
|
||||
likeComment,
|
||||
followBeta,
|
||||
searchForBetaCommunity,
|
||||
createComment,
|
||||
updateComment,
|
||||
deleteComment,
|
||||
removeComment,
|
||||
getMentions,
|
||||
searchPost,
|
||||
unfollowRemotes,
|
||||
createCommunity,
|
||||
registerUser,
|
||||
API,
|
||||
delay,
|
||||
} from './shared';
|
||||
|
||||
import { PostResponse } from 'lemmy-js-client';
|
||||
|
||||
let postRes: PostResponse;
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupLogins();
|
||||
await followBeta(alpha);
|
||||
await followBeta(gamma);
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
await delay(10000);
|
||||
postRes = await createPost(
|
||||
alpha,
|
||||
search.communities.filter(c => c.local == false)[0].id
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await unfollowRemotes(alpha);
|
||||
await unfollowRemotes(gamma);
|
||||
});
|
||||
|
||||
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);
|
||||
await delay();
|
||||
|
||||
// Make sure that comment is liked on beta
|
||||
let searchBeta = await searchComment(beta, commentRes.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);
|
||||
});
|
||||
|
||||
test('Create a comment in a non-existent post', async () => {
|
||||
let commentRes = await createComment(alpha, -1);
|
||||
expect(commentRes).toStrictEqual({ error: 'couldnt_find_post' });
|
||||
});
|
||||
|
||||
test('Update a comment', async () => {
|
||||
let commentRes = await createComment(alpha, postRes.post.id);
|
||||
await delay();
|
||||
let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
|
||||
expect(updateCommentRes.comment.content).toBe(
|
||||
'A jest test federated comment update'
|
||||
);
|
||||
expect(updateCommentRes.comment.community_local).toBe(false);
|
||||
expect(updateCommentRes.comment.creator_local).toBe(true);
|
||||
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');
|
||||
});
|
||||
|
||||
test('Delete a comment', async () => {
|
||||
let commentRes = await createComment(alpha, postRes.post.id);
|
||||
await delay();
|
||||
|
||||
let deleteCommentRes = await deleteComment(
|
||||
alpha,
|
||||
true,
|
||||
commentRes.comment.id
|
||||
);
|
||||
expect(deleteCommentRes.comment.deleted).toBe(true);
|
||||
await delay();
|
||||
|
||||
// Make sure that comment is undefined on beta
|
||||
let searchBeta = await searchComment(beta, commentRes.comment);
|
||||
let betaComment = searchBeta.comments[0];
|
||||
expect(betaComment).toBeUndefined();
|
||||
await delay();
|
||||
|
||||
let undeleteCommentRes = await deleteComment(
|
||||
alpha,
|
||||
false,
|
||||
commentRes.comment.id
|
||||
);
|
||||
expect(undeleteCommentRes.comment.deleted).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Make sure that comment is undeleted on beta
|
||||
let searchBeta2 = await searchComment(beta, commentRes.comment);
|
||||
let betaComment2 = searchBeta2.comments[0];
|
||||
expect(betaComment2.deleted).toBe(false);
|
||||
});
|
||||
|
||||
test('Remove a comment from admin and community on the same instance', async () => {
|
||||
let commentRes = await createComment(alpha, postRes.post.id);
|
||||
await delay();
|
||||
|
||||
// Get the id for beta
|
||||
let betaCommentId = (await searchComment(beta, commentRes.comment))
|
||||
.comments[0].id;
|
||||
|
||||
// The beta admin removes it (the community lives on beta)
|
||||
let removeCommentRes = await removeComment(beta, true, betaCommentId);
|
||||
expect(removeCommentRes.comment.removed).toBe(true);
|
||||
await delay();
|
||||
|
||||
// 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 unremoveCommentRes = await removeComment(beta, false, betaCommentId);
|
||||
expect(unremoveCommentRes.comment.removed).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Make sure that comment is unremoved on beta
|
||||
let refetchedPost2 = await getPost(alpha, postRes.post.id);
|
||||
expect(refetchedPost2.comments[0].removed).toBe(false);
|
||||
});
|
||||
|
||||
test('Remove a comment from admin and community on different instance', async () => {
|
||||
let alphaUser = await registerUser(alpha);
|
||||
let newAlphaApi: API = {
|
||||
client: alpha.client,
|
||||
auth: alphaUser.jwt,
|
||||
};
|
||||
|
||||
// New alpha user creates a community, post, and comment.
|
||||
let newCommunity = await createCommunity(newAlphaApi);
|
||||
await delay();
|
||||
let newPost = await createPost(newAlphaApi, newCommunity.community.id);
|
||||
await delay();
|
||||
let commentRes = await createComment(newAlphaApi, newPost.post.id);
|
||||
expect(commentRes.comment.content).toBeDefined();
|
||||
await delay();
|
||||
|
||||
// Beta searches that to cache it, then removes it
|
||||
let searchBeta = await searchComment(beta, commentRes.comment);
|
||||
let betaComment = searchBeta.comments[0];
|
||||
let removeCommentRes = await removeComment(beta, true, betaComment.id);
|
||||
expect(removeCommentRes.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);
|
||||
});
|
||||
|
||||
test('Unlike a comment', async () => {
|
||||
let commentRes = await createComment(alpha, postRes.post.id);
|
||||
await delay();
|
||||
let unlike = await likeComment(alpha, 0, commentRes.comment);
|
||||
expect(unlike.comment.score).toBe(0);
|
||||
await delay();
|
||||
|
||||
// Make sure that post is unliked on beta
|
||||
let searchBeta = await searchComment(beta, commentRes.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);
|
||||
});
|
||||
|
||||
test('Federated comment like', async () => {
|
||||
let commentRes = await createComment(alpha, postRes.post.id);
|
||||
await delay();
|
||||
|
||||
// Find the comment on beta
|
||||
let searchBeta = await searchComment(beta, commentRes.comment);
|
||||
let betaComment = searchBeta.comments[0];
|
||||
|
||||
let like = await likeComment(beta, 1, betaComment);
|
||||
expect(like.comment.score).toBe(2);
|
||||
await delay();
|
||||
|
||||
// Get the post from alpha, check the likes
|
||||
let post = await getPost(alpha, postRes.post.id);
|
||||
expect(post.comments[0].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);
|
||||
await delay();
|
||||
let searchBeta = await searchComment(beta, commentRes.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);
|
||||
await delay();
|
||||
|
||||
// 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 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);
|
||||
});
|
||||
|
||||
test('Mention beta', async () => {
|
||||
// Create a mention on alpha
|
||||
let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8550';
|
||||
let commentRes = await createComment(alpha, postRes.post.id);
|
||||
await delay();
|
||||
let mentionRes = await createComment(
|
||||
alpha,
|
||||
postRes.post.id,
|
||||
commentRes.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);
|
||||
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);
|
||||
});
|
||||
|
||||
test('Comment Search', 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);
|
||||
});
|
||||
|
||||
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);
|
||||
await delay();
|
||||
|
||||
// Make sure gamma sees it
|
||||
let search = await searchPost(gamma, alphaPost.post);
|
||||
let gammaPost = search.posts[0];
|
||||
|
||||
let commentContent =
|
||||
'A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8550';
|
||||
let commentRes = await createComment(
|
||||
gamma,
|
||||
gammaPost.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);
|
||||
await delay();
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
// TODO this is failing because fetchInReplyTos aren't getting score
|
||||
// expect(mentionsRes.mentions[0].score).toBe(1);
|
||||
});
|
||||
|
||||
test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedded comments, A subs to B, B updates the lowest level comment, A fetches both the post and all the inreplyto comments for that post.', async () => {
|
||||
// Unfollow all remote communities
|
||||
let followed = await unfollowRemotes(alpha);
|
||||
expect(
|
||||
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();
|
||||
await delay();
|
||||
|
||||
let parentCommentContent = 'An invisible top level comment from beta';
|
||||
let parentCommentRes = await createComment(
|
||||
beta,
|
||||
postRes.post.id,
|
||||
undefined,
|
||||
parentCommentContent
|
||||
);
|
||||
expect(parentCommentRes.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,
|
||||
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');
|
||||
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(
|
||||
beta,
|
||||
childCommentRes.comment.id,
|
||||
updatedCommentContent
|
||||
);
|
||||
expect(updateRes.comment.content).toBe(updatedCommentContent);
|
||||
await delay();
|
||||
|
||||
// Get the post from alpha
|
||||
let search = await searchPost(alpha, postRes.post);
|
||||
let alphaPostB = search.posts[0];
|
||||
await delay();
|
||||
|
||||
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);
|
||||
expect(alphaPost.post.community_local).toBe(false);
|
||||
expect(alphaPost.post.creator_local).toBe(false);
|
||||
});
|
95
api_tests/src/community.spec.ts
vendored
Normal file
95
api_tests/src/community.spec.ts
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
import {
|
||||
alpha,
|
||||
beta,
|
||||
setupLogins,
|
||||
searchForBetaCommunity,
|
||||
createCommunity,
|
||||
deleteCommunity,
|
||||
removeCommunity,
|
||||
delay,
|
||||
} from './shared';
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupLogins();
|
||||
});
|
||||
|
||||
test('Create community', async () => {
|
||||
let communityRes = await createCommunity(alpha);
|
||||
expect(communityRes.community.name).toBeDefined();
|
||||
|
||||
// A dupe check
|
||||
let prevName = communityRes.community.name;
|
||||
let communityRes2 = await createCommunity(alpha, prevName);
|
||||
expect(communityRes2['error']).toBe('community_already_exists');
|
||||
});
|
||||
|
||||
test('Delete community', async () => {
|
||||
let communityRes = await createCommunity(beta);
|
||||
await delay();
|
||||
let deleteCommunityRes = await deleteCommunity(
|
||||
beta,
|
||||
true,
|
||||
communityRes.community.id
|
||||
);
|
||||
expect(deleteCommunityRes.community.deleted).toBe(true);
|
||||
await delay();
|
||||
|
||||
// Make sure it got deleted on A
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
let communityA = search.communities[0];
|
||||
// TODO this fails currently, because no updates are pushed
|
||||
// expect(communityA.deleted).toBe(true);
|
||||
|
||||
// Undelete
|
||||
let undeleteCommunityRes = await deleteCommunity(
|
||||
beta,
|
||||
false,
|
||||
communityRes.community.id
|
||||
);
|
||||
expect(undeleteCommunityRes.community.deleted).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Make sure it got undeleted on A
|
||||
let search2 = await searchForBetaCommunity(alpha);
|
||||
let communityA2 = search2.communities[0];
|
||||
// TODO this fails currently, because no updates are pushed
|
||||
// expect(communityA2.deleted).toBe(false);
|
||||
});
|
||||
|
||||
test('Remove community', async () => {
|
||||
let communityRes = await createCommunity(beta);
|
||||
await delay();
|
||||
let removeCommunityRes = await removeCommunity(
|
||||
beta,
|
||||
true,
|
||||
communityRes.community.id
|
||||
);
|
||||
expect(removeCommunityRes.community.removed).toBe(true);
|
||||
|
||||
// Make sure it got removed on A
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
let communityA = search.communities[0];
|
||||
// TODO this fails currently, because no updates are pushed
|
||||
// expect(communityA.removed).toBe(true);
|
||||
await delay();
|
||||
|
||||
// unremove
|
||||
let unremoveCommunityRes = await removeCommunity(
|
||||
beta,
|
||||
false,
|
||||
communityRes.community.id
|
||||
);
|
||||
expect(unremoveCommunityRes.community.removed).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Make sure it got unremoved on A
|
||||
let search2 = await searchForBetaCommunity(alpha);
|
||||
let communityA2 = search2.communities[0];
|
||||
// TODO this fails currently, because no updates are pushed
|
||||
// expect(communityA2.removed).toBe(false);
|
||||
});
|
||||
|
||||
test('Search for beta community', async () => {
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
expect(search.communities[0].name).toBe('main');
|
||||
});
|
43
api_tests/src/follow.spec.ts
vendored
Normal file
43
api_tests/src/follow.spec.ts
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
import {
|
||||
alpha,
|
||||
setupLogins,
|
||||
searchForBetaCommunity,
|
||||
followCommunity,
|
||||
checkFollowedCommunities,
|
||||
unfollowRemotes,
|
||||
delay,
|
||||
} from './shared';
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupLogins();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await unfollowRemotes(alpha);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
// Make sure the follow response went through
|
||||
expect(follow.community.local).toBe(false);
|
||||
expect(follow.community.name).toBe('main');
|
||||
await delay();
|
||||
|
||||
// Check it from local
|
||||
let followCheck = await checkFollowedCommunities(alpha);
|
||||
let remoteCommunityId = followCheck.communities.filter(
|
||||
c => c.community_local == false
|
||||
)[0].community_id;
|
||||
expect(remoteCommunityId).toBeDefined();
|
||||
|
||||
// Test an unfollow
|
||||
let unfollow = await followCommunity(alpha, false, remoteCommunityId);
|
||||
expect(unfollow.community.local).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Make sure you are unsubbed locally
|
||||
let unfollowCheck = await checkFollowedCommunities(alpha);
|
||||
expect(unfollowCheck.communities.length).toBeGreaterThanOrEqual(1);
|
||||
});
|
305
api_tests/src/post.spec.ts
vendored
Normal file
305
api_tests/src/post.spec.ts
vendored
Normal file
|
@ -0,0 +1,305 @@
|
|||
jest.setTimeout(120000);
|
||||
import {
|
||||
alpha,
|
||||
beta,
|
||||
gamma,
|
||||
delta,
|
||||
epsilon,
|
||||
setupLogins,
|
||||
createPost,
|
||||
updatePost,
|
||||
stickyPost,
|
||||
lockPost,
|
||||
searchPost,
|
||||
likePost,
|
||||
followBeta,
|
||||
searchForBetaCommunity,
|
||||
createComment,
|
||||
deletePost,
|
||||
removePost,
|
||||
getPost,
|
||||
unfollowRemotes,
|
||||
delay,
|
||||
} from './shared';
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupLogins();
|
||||
await followBeta(alpha);
|
||||
await followBeta(gamma);
|
||||
await followBeta(delta);
|
||||
await followBeta(epsilon);
|
||||
await delay(10000);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await unfollowRemotes(alpha);
|
||||
await unfollowRemotes(gamma);
|
||||
await unfollowRemotes(delta);
|
||||
await unfollowRemotes(epsilon);
|
||||
});
|
||||
|
||||
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);
|
||||
await delay();
|
||||
|
||||
// Make sure that post is liked on beta
|
||||
let searchBeta = await searchPost(beta, postRes.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);
|
||||
|
||||
// Delta only follows beta, so it should not see an alpha ap_id
|
||||
let searchDelta = await searchPost(delta, postRes.post);
|
||||
expect(searchDelta.posts[0]).toBeUndefined();
|
||||
|
||||
// Epsilon has alpha blocked, it should not see the alpha post
|
||||
let searchEpsilon = await searchPost(epsilon, postRes.post);
|
||||
expect(searchEpsilon.posts[0]).toBeUndefined();
|
||||
});
|
||||
|
||||
test('Create a post in a non-existent community', async () => {
|
||||
let postRes = await createPost(alpha, -2);
|
||||
expect(postRes).toStrictEqual({ error: 'couldnt_create_post' });
|
||||
});
|
||||
|
||||
test('Unlike a post', async () => {
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
let postRes = await createPost(alpha, search.communities[0].id);
|
||||
await delay();
|
||||
let unlike = await likePost(alpha, 0, postRes.post);
|
||||
expect(unlike.post.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);
|
||||
await delay();
|
||||
|
||||
// Make sure that post is unliked on beta
|
||||
let searchBeta = await searchPost(beta, postRes.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);
|
||||
});
|
||||
|
||||
test('Update a post', async () => {
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
let postRes = await createPost(alpha, search.communities[0].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);
|
||||
await delay();
|
||||
|
||||
// Make sure that post is updated on beta
|
||||
let searchBeta = await searchPost(beta, postRes.post);
|
||||
let betaPost = searchBeta.posts[0];
|
||||
expect(betaPost.community_local).toBe(true);
|
||||
expect(betaPost.creator_local).toBe(false);
|
||||
expect(betaPost.name).toBe(updatedName);
|
||||
await delay();
|
||||
|
||||
// Make sure lemmy beta cannot update the post
|
||||
let updatedPostBeta = await updatePost(beta, betaPost);
|
||||
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);
|
||||
await delay();
|
||||
|
||||
let stickiedPostRes = await stickyPost(alpha, true, postRes.post);
|
||||
expect(stickiedPostRes.post.stickied).toBe(true);
|
||||
await delay();
|
||||
|
||||
// Make sure that post is stickied on beta
|
||||
let searchBeta = await searchPost(beta, postRes.post);
|
||||
let betaPost = searchBeta.posts[0];
|
||||
expect(betaPost.community_local).toBe(true);
|
||||
expect(betaPost.creator_local).toBe(false);
|
||||
expect(betaPost.stickied).toBe(true);
|
||||
|
||||
// Unsticky a post
|
||||
let unstickiedPost = await stickyPost(alpha, false, postRes.post);
|
||||
expect(unstickiedPost.post.stickied).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Make sure that post is unstickied on beta
|
||||
let searchBeta2 = await searchPost(beta, postRes.post);
|
||||
let betaPost2 = searchBeta2.posts[0];
|
||||
expect(betaPost2.community_local).toBe(true);
|
||||
expect(betaPost2.creator_local).toBe(false);
|
||||
expect(betaPost2.stickied).toBe(false);
|
||||
|
||||
// Make sure that gamma cannot sticky the post on beta
|
||||
let searchGamma = await searchPost(gamma, postRes.post);
|
||||
let gammaPost = searchGamma.posts[0];
|
||||
let gammaTrySticky = await stickyPost(gamma, true, gammaPost);
|
||||
await delay();
|
||||
let searchBeta3 = await searchPost(beta, postRes.post);
|
||||
let betaPost3 = searchBeta3.posts[0];
|
||||
expect(gammaTrySticky.post.stickied).toBe(true);
|
||||
expect(betaPost3.stickied).toBe(false);
|
||||
});
|
||||
|
||||
test('Lock a post', async () => {
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
await delay();
|
||||
let postRes = await createPost(alpha, search.communities[0].id);
|
||||
await delay();
|
||||
|
||||
let lockedPostRes = await lockPost(alpha, true, postRes.post);
|
||||
expect(lockedPostRes.post.locked).toBe(true);
|
||||
await delay();
|
||||
|
||||
// Make sure that post is locked on beta
|
||||
let searchBeta = await searchPost(beta, postRes.post);
|
||||
let betaPost = searchBeta.posts[0];
|
||||
expect(betaPost.community_local).toBe(true);
|
||||
expect(betaPost.creator_local).toBe(false);
|
||||
expect(betaPost.locked).toBe(true);
|
||||
|
||||
// Try to make a new comment there, on alpha
|
||||
let comment = await createComment(alpha, postRes.post.id);
|
||||
expect(comment['error']).toBe('locked');
|
||||
await delay();
|
||||
|
||||
// Try to create a new comment, on beta
|
||||
let commentBeta = await createComment(beta, betaPost.id);
|
||||
expect(commentBeta['error']).toBe('locked');
|
||||
await delay();
|
||||
|
||||
// Unlock a post
|
||||
let unlockedPost = await lockPost(alpha, false, postRes.post);
|
||||
expect(unlockedPost.post.locked).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Make sure that post is unlocked on beta
|
||||
let searchBeta2 = await searchPost(beta, postRes.post);
|
||||
let betaPost2 = searchBeta2.posts[0];
|
||||
expect(betaPost2.community_local).toBe(true);
|
||||
expect(betaPost2.creator_local).toBe(false);
|
||||
expect(betaPost2.locked).toBe(false);
|
||||
});
|
||||
|
||||
test('Delete a post', async () => {
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
let postRes = await createPost(alpha, search.communities[0].id);
|
||||
await delay();
|
||||
|
||||
let deletedPost = await deletePost(alpha, true, postRes.post);
|
||||
expect(deletedPost.post.deleted).toBe(true);
|
||||
await delay();
|
||||
|
||||
// Make sure lemmy beta sees post is deleted
|
||||
let searchBeta = await searchPost(beta, postRes.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);
|
||||
await delay();
|
||||
|
||||
// Make sure lemmy beta sees post is undeleted
|
||||
let searchBeta2 = await searchPost(beta, postRes.post);
|
||||
let betaPost2 = searchBeta2.posts[0];
|
||||
expect(betaPost2.deleted).toBe(false);
|
||||
|
||||
// Make sure lemmy beta cannot delete the post
|
||||
let deletedPostBeta = await deletePost(beta, true, betaPost2);
|
||||
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);
|
||||
await delay();
|
||||
|
||||
let removedPost = await removePost(alpha, true, postRes.post);
|
||||
expect(removedPost.post.removed).toBe(true);
|
||||
await delay();
|
||||
|
||||
// Make sure lemmy beta sees post is NOT removed
|
||||
let searchBeta = await searchPost(beta, postRes.post);
|
||||
let betaPost = searchBeta.posts[0];
|
||||
expect(betaPost.removed).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Undelete
|
||||
let undeletedPost = await removePost(alpha, false, postRes.post);
|
||||
expect(undeletedPost.post.removed).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Make sure lemmy beta sees post is undeleted
|
||||
let searchBeta2 = await searchPost(beta, postRes.post);
|
||||
let betaPost2 = searchBeta2.posts[0];
|
||||
expect(betaPost2.removed).toBe(false);
|
||||
});
|
||||
|
||||
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);
|
||||
await delay();
|
||||
|
||||
// Get the id for beta
|
||||
let searchBeta = await searchPost(beta, postRes.post);
|
||||
let betaPost = searchBeta.posts[0];
|
||||
await delay();
|
||||
|
||||
// The beta admin removes it (the community lives on beta)
|
||||
let removePostRes = await removePost(beta, true, betaPost);
|
||||
expect(removePostRes.post.removed).toBe(true);
|
||||
await delay();
|
||||
|
||||
// Make sure lemmy alpha sees post is removed
|
||||
let alphaPost = await getPost(alpha, postRes.post.id);
|
||||
expect(alphaPost.post.removed).toBe(true);
|
||||
await delay();
|
||||
|
||||
// Undelete
|
||||
let undeletedPost = await removePost(beta, false, betaPost);
|
||||
expect(undeletedPost.post.removed).toBe(false);
|
||||
await delay();
|
||||
|
||||
// Make sure lemmy alpha sees post is undeleted
|
||||
let alphaPost2 = await getPost(alpha, postRes.post.id);
|
||||
expect(alphaPost2.post.removed).toBe(false);
|
||||
});
|
||||
|
||||
test('Search for a post', async () => {
|
||||
let search = await searchForBetaCommunity(alpha);
|
||||
await delay();
|
||||
let postRes = await createPost(alpha, search.communities[0].id);
|
||||
await delay();
|
||||
let searchBeta = await searchPost(beta, postRes.post);
|
||||
|
||||
expect(searchBeta.posts[0].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);
|
||||
await delay();
|
||||
|
||||
let search2 = await searchPost(gamma, postRes.post);
|
||||
expect(search2.posts[0].name).toBeDefined();
|
||||
});
|
80
api_tests/src/private_message.spec.ts
vendored
Normal file
80
api_tests/src/private_message.spec.ts
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
import {
|
||||
alpha,
|
||||
beta,
|
||||
setupLogins,
|
||||
followBeta,
|
||||
createPrivateMessage,
|
||||
updatePrivateMessage,
|
||||
listPrivateMessages,
|
||||
deletePrivateMessage,
|
||||
unfollowRemotes,
|
||||
delay,
|
||||
} from './shared';
|
||||
|
||||
let recipient_id: number;
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupLogins();
|
||||
let follow = await followBeta(alpha);
|
||||
await delay(10000);
|
||||
recipient_id = follow.community.creator_id;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await unfollowRemotes(alpha);
|
||||
});
|
||||
|
||||
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);
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
await delay();
|
||||
|
||||
let betaPms = await listPrivateMessages(beta);
|
||||
expect(betaPms.messages[0].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);
|
||||
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);
|
||||
await delay();
|
||||
|
||||
// Undelete
|
||||
let undeletedPmRes = await deletePrivateMessage(
|
||||
alpha,
|
||||
false,
|
||||
pmRes.message.id
|
||||
);
|
||||
expect(undeletedPmRes.message.deleted).toBe(false);
|
||||
await delay();
|
||||
|
||||
let betaPms3 = await listPrivateMessages(beta);
|
||||
expect(betaPms3.messages.length).toBe(betaPms1.messages.length);
|
||||
});
|
544
api_tests/src/shared.ts
vendored
Normal file
544
api_tests/src/shared.ts
vendored
Normal file
|
@ -0,0 +1,544 @@
|
|||
import {
|
||||
LoginForm,
|
||||
LoginResponse,
|
||||
Post,
|
||||
PostForm,
|
||||
Comment,
|
||||
DeletePostForm,
|
||||
RemovePostForm,
|
||||
StickyPostForm,
|
||||
LockPostForm,
|
||||
PostResponse,
|
||||
SearchResponse,
|
||||
FollowCommunityForm,
|
||||
CommunityResponse,
|
||||
GetFollowedCommunitiesResponse,
|
||||
GetPostResponse,
|
||||
RegisterForm,
|
||||
CommentForm,
|
||||
DeleteCommentForm,
|
||||
RemoveCommentForm,
|
||||
SearchForm,
|
||||
CommentResponse,
|
||||
CommunityForm,
|
||||
DeleteCommunityForm,
|
||||
RemoveCommunityForm,
|
||||
GetUserMentionsForm,
|
||||
CommentLikeForm,
|
||||
CreatePostLikeForm,
|
||||
PrivateMessageForm,
|
||||
EditPrivateMessageForm,
|
||||
DeletePrivateMessageForm,
|
||||
GetFollowedCommunitiesForm,
|
||||
GetPrivateMessagesForm,
|
||||
GetSiteForm,
|
||||
GetPostForm,
|
||||
PrivateMessageResponse,
|
||||
PrivateMessagesResponse,
|
||||
GetUserMentionsResponse,
|
||||
UserSettingsForm,
|
||||
SortType,
|
||||
ListingType,
|
||||
GetSiteResponse,
|
||||
SearchType,
|
||||
LemmyHttp,
|
||||
} from 'lemmy-js-client';
|
||||
|
||||
export interface API {
|
||||
client: LemmyHttp;
|
||||
auth?: string;
|
||||
}
|
||||
|
||||
export let alpha: API = {
|
||||
client: new LemmyHttp('http://localhost:8540/api/v1'),
|
||||
};
|
||||
|
||||
export let beta: API = {
|
||||
client: new LemmyHttp('http://localhost:8550/api/v1'),
|
||||
};
|
||||
|
||||
export let gamma: API = {
|
||||
client: new LemmyHttp('http://localhost:8560/api/v1'),
|
||||
};
|
||||
|
||||
export let delta: API = {
|
||||
client: new LemmyHttp('http://localhost:8570/api/v1'),
|
||||
};
|
||||
|
||||
export let epsilon: API = {
|
||||
client: new LemmyHttp('http://localhost:8580/api/v1'),
|
||||
};
|
||||
|
||||
export async function setupLogins() {
|
||||
let formAlpha: LoginForm = {
|
||||
username_or_email: 'lemmy_alpha',
|
||||
password: 'lemmy',
|
||||
};
|
||||
let resAlpha = alpha.client.login(formAlpha);
|
||||
|
||||
let formBeta = {
|
||||
username_or_email: 'lemmy_beta',
|
||||
password: 'lemmy',
|
||||
};
|
||||
let resBeta = beta.client.login(formBeta);
|
||||
|
||||
let formGamma = {
|
||||
username_or_email: 'lemmy_gamma',
|
||||
password: 'lemmy',
|
||||
};
|
||||
let resGamma = gamma.client.login(formGamma);
|
||||
|
||||
let formDelta = {
|
||||
username_or_email: 'lemmy_delta',
|
||||
password: 'lemmy',
|
||||
};
|
||||
let resDelta = delta.client.login(formDelta);
|
||||
|
||||
let formEpsilon = {
|
||||
username_or_email: 'lemmy_epsilon',
|
||||
password: 'lemmy',
|
||||
};
|
||||
let resEpsilon = epsilon.client.login(formEpsilon);
|
||||
|
||||
let res = await Promise.all([
|
||||
resAlpha,
|
||||
resBeta,
|
||||
resGamma,
|
||||
resDelta,
|
||||
resEpsilon,
|
||||
]);
|
||||
|
||||
alpha.auth = res[0].jwt;
|
||||
beta.auth = res[1].jwt;
|
||||
gamma.auth = res[2].jwt;
|
||||
delta.auth = res[3].jwt;
|
||||
epsilon.auth = res[4].jwt;
|
||||
}
|
||||
|
||||
export async function createPost(
|
||||
api: API,
|
||||
community_id: number
|
||||
): Promise<PostResponse> {
|
||||
let name = 'A jest test post';
|
||||
let form: PostForm = {
|
||||
name,
|
||||
auth: api.auth,
|
||||
community_id,
|
||||
nsfw: false,
|
||||
};
|
||||
return api.client.createPost(form);
|
||||
}
|
||||
|
||||
export async function updatePost(api: API, post: Post): Promise<PostResponse> {
|
||||
let name = 'A jest test federated post, updated';
|
||||
let form: PostForm = {
|
||||
name,
|
||||
edit_id: post.id,
|
||||
auth: api.auth,
|
||||
nsfw: false,
|
||||
};
|
||||
return api.client.editPost(form);
|
||||
}
|
||||
|
||||
export async function deletePost(
|
||||
api: API,
|
||||
deleted: boolean,
|
||||
post: Post
|
||||
): Promise<PostResponse> {
|
||||
let form: DeletePostForm = {
|
||||
edit_id: post.id,
|
||||
deleted: deleted,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.deletePost(form);
|
||||
}
|
||||
|
||||
export async function removePost(
|
||||
api: API,
|
||||
removed: boolean,
|
||||
post: Post
|
||||
): Promise<PostResponse> {
|
||||
let form: RemovePostForm = {
|
||||
edit_id: post.id,
|
||||
removed,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.removePost(form);
|
||||
}
|
||||
|
||||
export async function stickyPost(
|
||||
api: API,
|
||||
stickied: boolean,
|
||||
post: Post
|
||||
): Promise<PostResponse> {
|
||||
let form: StickyPostForm = {
|
||||
edit_id: post.id,
|
||||
stickied,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.stickyPost(form);
|
||||
}
|
||||
|
||||
export async function lockPost(
|
||||
api: API,
|
||||
locked: boolean,
|
||||
post: Post
|
||||
): Promise<PostResponse> {
|
||||
let form: LockPostForm = {
|
||||
edit_id: post.id,
|
||||
locked,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.lockPost(form);
|
||||
}
|
||||
|
||||
export async function searchPost(
|
||||
api: API,
|
||||
post: Post
|
||||
): Promise<SearchResponse> {
|
||||
let form: SearchForm = {
|
||||
q: post.ap_id,
|
||||
type_: SearchType.Posts,
|
||||
sort: SortType.TopAll,
|
||||
};
|
||||
return api.client.search(form);
|
||||
}
|
||||
|
||||
export async function getPost(
|
||||
api: API,
|
||||
post_id: number
|
||||
): Promise<GetPostResponse> {
|
||||
let form: GetPostForm = {
|
||||
id: post_id,
|
||||
};
|
||||
return api.client.getPost(form);
|
||||
}
|
||||
|
||||
export async function searchComment(
|
||||
api: API,
|
||||
comment: Comment
|
||||
): Promise<SearchResponse> {
|
||||
let form: SearchForm = {
|
||||
q: comment.ap_id,
|
||||
type_: SearchType.Comments,
|
||||
sort: SortType.TopAll,
|
||||
};
|
||||
return api.client.search(form);
|
||||
}
|
||||
|
||||
export async function searchForBetaCommunity(
|
||||
api: API
|
||||
): Promise<SearchResponse> {
|
||||
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
||||
// Use short-hand search url
|
||||
let form: SearchForm = {
|
||||
q: '!main@lemmy-beta:8550',
|
||||
type_: SearchType.Communities,
|
||||
sort: SortType.TopAll,
|
||||
};
|
||||
return api.client.search(form);
|
||||
}
|
||||
|
||||
export async function searchForUser(
|
||||
api: API,
|
||||
apShortname: string
|
||||
): Promise<SearchResponse> {
|
||||
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
||||
// Use short-hand search url
|
||||
let form: SearchForm = {
|
||||
q: apShortname,
|
||||
type_: SearchType.Users,
|
||||
sort: SortType.TopAll,
|
||||
};
|
||||
return api.client.search(form);
|
||||
}
|
||||
|
||||
export async function followCommunity(
|
||||
api: API,
|
||||
follow: boolean,
|
||||
community_id: number
|
||||
): Promise<CommunityResponse> {
|
||||
let form: FollowCommunityForm = {
|
||||
community_id,
|
||||
follow,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.followCommunity(form);
|
||||
}
|
||||
|
||||
export async function checkFollowedCommunities(
|
||||
api: API
|
||||
): Promise<GetFollowedCommunitiesResponse> {
|
||||
let form: GetFollowedCommunitiesForm = {
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.getFollowedCommunities(form);
|
||||
}
|
||||
|
||||
export async function likePost(
|
||||
api: API,
|
||||
score: number,
|
||||
post: Post
|
||||
): Promise<PostResponse> {
|
||||
let form: CreatePostLikeForm = {
|
||||
post_id: post.id,
|
||||
score: score,
|
||||
auth: api.auth,
|
||||
};
|
||||
|
||||
return api.client.likePost(form);
|
||||
}
|
||||
|
||||
export async function createComment(
|
||||
api: API,
|
||||
post_id: number,
|
||||
parent_id?: number,
|
||||
content = 'a jest test comment'
|
||||
): Promise<CommentResponse> {
|
||||
let form: CommentForm = {
|
||||
content,
|
||||
post_id,
|
||||
parent_id,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.createComment(form);
|
||||
}
|
||||
|
||||
export async function updateComment(
|
||||
api: API,
|
||||
edit_id: number,
|
||||
content = 'A jest test federated comment update'
|
||||
): Promise<CommentResponse> {
|
||||
let form: CommentForm = {
|
||||
content,
|
||||
edit_id,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.editComment(form);
|
||||
}
|
||||
|
||||
export async function deleteComment(
|
||||
api: API,
|
||||
deleted: boolean,
|
||||
edit_id: number
|
||||
): Promise<CommentResponse> {
|
||||
let form: DeleteCommentForm = {
|
||||
edit_id,
|
||||
deleted,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.deleteComment(form);
|
||||
}
|
||||
|
||||
export async function removeComment(
|
||||
api: API,
|
||||
removed: boolean,
|
||||
edit_id: number
|
||||
): Promise<CommentResponse> {
|
||||
let form: RemoveCommentForm = {
|
||||
edit_id,
|
||||
removed,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.removeComment(form);
|
||||
}
|
||||
|
||||
export async function getMentions(api: API): Promise<GetUserMentionsResponse> {
|
||||
let form: GetUserMentionsForm = {
|
||||
sort: SortType.New,
|
||||
unread_only: false,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.getUserMentions(form);
|
||||
}
|
||||
|
||||
export async function likeComment(
|
||||
api: API,
|
||||
score: number,
|
||||
comment: Comment
|
||||
): Promise<CommentResponse> {
|
||||
let form: CommentLikeForm = {
|
||||
comment_id: comment.id,
|
||||
score,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.likeComment(form);
|
||||
}
|
||||
|
||||
export async function createCommunity(
|
||||
api: API,
|
||||
name_: string = randomString(5)
|
||||
): Promise<CommunityResponse> {
|
||||
let form: CommunityForm = {
|
||||
name: name_,
|
||||
title: name_,
|
||||
category_id: 1,
|
||||
nsfw: false,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.createCommunity(form);
|
||||
}
|
||||
|
||||
export async function deleteCommunity(
|
||||
api: API,
|
||||
deleted: boolean,
|
||||
edit_id: number
|
||||
): Promise<CommunityResponse> {
|
||||
let form: DeleteCommunityForm = {
|
||||
edit_id,
|
||||
deleted,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.deleteCommunity(form);
|
||||
}
|
||||
|
||||
export async function removeCommunity(
|
||||
api: API,
|
||||
removed: boolean,
|
||||
edit_id: number
|
||||
): Promise<CommunityResponse> {
|
||||
let form: RemoveCommunityForm = {
|
||||
edit_id,
|
||||
removed,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.removeCommunity(form);
|
||||
}
|
||||
|
||||
export async function createPrivateMessage(
|
||||
api: API,
|
||||
recipient_id: number
|
||||
): Promise<PrivateMessageResponse> {
|
||||
let content = 'A jest test federated private message';
|
||||
let form: PrivateMessageForm = {
|
||||
content,
|
||||
recipient_id,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.createPrivateMessage(form);
|
||||
}
|
||||
|
||||
export async function updatePrivateMessage(
|
||||
api: API,
|
||||
edit_id: number
|
||||
): Promise<PrivateMessageResponse> {
|
||||
let updatedContent = 'A jest test federated private message edited';
|
||||
let form: EditPrivateMessageForm = {
|
||||
content: updatedContent,
|
||||
edit_id,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.editPrivateMessage(form);
|
||||
}
|
||||
|
||||
export async function deletePrivateMessage(
|
||||
api: API,
|
||||
deleted: boolean,
|
||||
edit_id: number
|
||||
): Promise<PrivateMessageResponse> {
|
||||
let form: DeletePrivateMessageForm = {
|
||||
deleted,
|
||||
edit_id,
|
||||
auth: api.auth,
|
||||
};
|
||||
return api.client.deletePrivateMessage(form);
|
||||
}
|
||||
|
||||
export async function registerUser(
|
||||
api: API,
|
||||
username: string = randomString(5)
|
||||
): Promise<LoginResponse> {
|
||||
let form: RegisterForm = {
|
||||
username,
|
||||
password: 'test',
|
||||
password_verify: 'test',
|
||||
admin: false,
|
||||
show_nsfw: true,
|
||||
};
|
||||
return api.client.register(form);
|
||||
}
|
||||
|
||||
export async function saveUserSettingsBio(
|
||||
api: API,
|
||||
auth: string
|
||||
): Promise<LoginResponse> {
|
||||
let form: UserSettingsForm = {
|
||||
show_nsfw: true,
|
||||
theme: 'darkly',
|
||||
default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
|
||||
default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
|
||||
lang: 'en',
|
||||
show_avatars: true,
|
||||
send_notifications_to_email: false,
|
||||
bio: 'a changed bio',
|
||||
auth,
|
||||
};
|
||||
return api.client.saveUserSettings(form);
|
||||
}
|
||||
|
||||
export async function getSite(
|
||||
api: API,
|
||||
auth: string
|
||||
): Promise<GetSiteResponse> {
|
||||
let form: GetSiteForm = {
|
||||
auth,
|
||||
};
|
||||
return api.client.getSite(form);
|
||||
}
|
||||
|
||||
export async function listPrivateMessages(
|
||||
api: API
|
||||
): Promise<PrivateMessagesResponse> {
|
||||
let form: GetPrivateMessagesForm = {
|
||||
auth: api.auth,
|
||||
unread_only: false,
|
||||
limit: 999,
|
||||
};
|
||||
return api.client.getPrivateMessages(form);
|
||||
}
|
||||
|
||||
export async function unfollowRemotes(
|
||||
api: API
|
||||
): Promise<GetFollowedCommunitiesResponse> {
|
||||
// Unfollow all remote communities
|
||||
let followed = await checkFollowedCommunities(api);
|
||||
let remoteFollowed = followed.communities.filter(
|
||||
c => c.community_local == false
|
||||
);
|
||||
for (let cu of remoteFollowed) {
|
||||
await followCommunity(api, false, cu.community_id);
|
||||
}
|
||||
let followed2 = await checkFollowedCommunities(api);
|
||||
return followed2;
|
||||
}
|
||||
|
||||
export async function followBeta(api: API): Promise<CommunityResponse> {
|
||||
await unfollowRemotes(api);
|
||||
|
||||
// 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);
|
||||
return follow;
|
||||
}
|
||||
}
|
||||
|
||||
export const delay = (millis: number = 1500) =>
|
||||
new Promise((resolve, _reject) => {
|
||||
setTimeout(_ => resolve(), millis);
|
||||
});
|
||||
|
||||
export function wrapper(form: any): string {
|
||||
return JSON.stringify(form);
|
||||
}
|
||||
|
||||
function randomString(length: number): string {
|
||||
var result = '';
|
||||
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789_';
|
||||
var charactersLength = characters.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
return result;
|
||||
}
|
34
api_tests/src/user.spec.ts
vendored
Normal file
34
api_tests/src/user.spec.ts
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
import {
|
||||
alpha,
|
||||
beta,
|
||||
registerUser,
|
||||
searchForUser,
|
||||
saveUserSettingsBio,
|
||||
getSite,
|
||||
} from './shared';
|
||||
|
||||
let auth: string;
|
||||
let apShortname: string;
|
||||
|
||||
test('Create user', async () => {
|
||||
let userRes = await registerUser(alpha);
|
||||
expect(userRes.jwt).toBeDefined();
|
||||
auth = userRes.jwt;
|
||||
|
||||
let site = await getSite(alpha, auth);
|
||||
expect(site.my_user).toBeDefined();
|
||||
apShortname = `@${site.my_user.name}@lemmy-alpha:8540`;
|
||||
});
|
||||
|
||||
test('Save user settings, check changed bio from beta', async () => {
|
||||
let bio = 'a changed bio';
|
||||
let userRes = await saveUserSettingsBio(alpha, auth);
|
||||
expect(userRes.jwt).toBeDefined();
|
||||
|
||||
let site = await getSite(alpha, auth);
|
||||
expect(site.my_user.bio).toBe(bio);
|
||||
|
||||
// Make sure beta sees this bio is changed
|
||||
let search = await searchForUser(beta, apShortname);
|
||||
expect(search.users[0].bio).toBe(bio);
|
||||
});
|
3659
api_tests/yarn.lock
vendored
Normal file
3659
api_tests/yarn.lock
vendored
Normal file
File diff suppressed because it is too large
Load diff
5
docker/travis/docker-compose.yml
vendored
5
docker/travis/docker-compose.yml
vendored
|
@ -35,7 +35,6 @@ services:
|
|||
- LEMMY_HOSTNAME=lemmy-alpha:8540
|
||||
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_alpha:5432/lemmy
|
||||
- LEMMY_JWT_SECRET=changeme
|
||||
- LEMMY_FRONT_END_DIR=/app/dist
|
||||
- LEMMY_FEDERATION__ENABLED=true
|
||||
- LEMMY_FEDERATION__TLS_ENABLED=false
|
||||
- LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta,lemmy-gamma,lemmy-delta,lemmy-epsilon
|
||||
|
@ -65,7 +64,6 @@ services:
|
|||
- LEMMY_HOSTNAME=lemmy-beta:8550
|
||||
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_beta:5432/lemmy
|
||||
- LEMMY_JWT_SECRET=changeme
|
||||
- LEMMY_FRONT_END_DIR=/app/dist
|
||||
- LEMMY_FEDERATION__ENABLED=true
|
||||
- LEMMY_FEDERATION__TLS_ENABLED=false
|
||||
- LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-gamma,lemmy-delta,lemmy-epsilon
|
||||
|
@ -95,7 +93,6 @@ services:
|
|||
- LEMMY_HOSTNAME=lemmy-gamma:8560
|
||||
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_gamma:5432/lemmy
|
||||
- LEMMY_JWT_SECRET=changeme
|
||||
- LEMMY_FRONT_END_DIR=/app/dist
|
||||
- LEMMY_FEDERATION__ENABLED=true
|
||||
- LEMMY_FEDERATION__TLS_ENABLED=false
|
||||
- LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-beta,lemmy-delta,lemmy-epsilon
|
||||
|
@ -126,7 +123,6 @@ services:
|
|||
- LEMMY_HOSTNAME=lemmy-delta:8570
|
||||
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_delta:5432/lemmy
|
||||
- LEMMY_JWT_SECRET=changeme
|
||||
- LEMMY_FRONT_END_DIR=/app/dist
|
||||
- LEMMY_FEDERATION__ENABLED=true
|
||||
- LEMMY_FEDERATION__TLS_ENABLED=false
|
||||
- LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta
|
||||
|
@ -157,7 +153,6 @@ services:
|
|||
- LEMMY_HOSTNAME=lemmy-epsilon:8580
|
||||
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_epsilon:5432/lemmy
|
||||
- LEMMY_JWT_SECRET=changeme
|
||||
- LEMMY_FRONT_END_DIR=/app/dist
|
||||
- LEMMY_FEDERATION__ENABLED=true
|
||||
- LEMMY_FEDERATION__TLS_ENABLED=false
|
||||
- LEMMY_FEDERATION__BLOCKED_INSTANCES=lemmy-alpha
|
||||
|
|
2
docker/travis/run-tests.sh
vendored
2
docker/travis/run-tests.sh
vendored
|
@ -12,7 +12,7 @@ sudo docker build ../../ --file ../prod/Dockerfile --tag dessalines/lemmy:travis
|
|||
|
||||
sudo docker-compose up -d
|
||||
|
||||
pushd ../../ui
|
||||
pushd ../../api_tests
|
||||
echo "Waiting for Lemmy to start..."
|
||||
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8540/api/v1/site')" != "200" ]]; do sleep 1; done
|
||||
while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8550/api/v1/site')" != "200" ]]; do sleep 1; done
|
||||
|
|
Loading…
Reference in a new issue