unfollowRemotes,
delay,
longDelay,
+ searchForUser,
+ banUserFromSite,
+ searchPostLocal,
+ banUserFromCommunity,
} from './shared';
import {
Post,
let postRes = await createPost(alpha, search.communities[0].id);
await delay();
+ // Lock the post
let lockedPostRes = await lockPost(alpha, true, postRes.post);
expect(lockedPostRes.post.locked).toBe(true);
- await delay();
+ await longDelay();
// 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);
+ let searchBeta = await searchPostLocal(beta, postRes.post);
+ let betaPost1 = searchBeta.posts[0];
+ expect(betaPost1.locked).toBe(true);
+ await delay();
// 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);
expect(betaPost2.community_local).toBe(true);
expect(betaPost2.creator_local).toBe(false);
expect(betaPost2.locked).toBe(false);
+
+ // Try to create a new comment, on beta
+ let commentBeta = await createComment(beta, betaPost2.id);
+ expect(commentBeta).toBeDefined();
});
test('Delete a post', async () => {
let search2 = await searchPost(gamma, postRes.post);
expect(search2.posts[0].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];
+ expect(alphaUser).toBeDefined();
+ await delay();
+
+ // ban alpha from beta site
+ let banAlpha = await banUserFromSite(beta, alphaUser.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);
+ await longDelay();
+
+ // Make sure that post doesn't make it to beta
+ let searchBeta = await searchPostLocal(beta, postRes.post);
+ let betaPost = searchBeta.posts[0];
+ expect(betaPost).toBeUndefined();
+ await delay();
+
+ // Unban alpha
+ let unBanAlpha = await banUserFromSite(beta, alphaUser.id, false);
+ expect(unBanAlpha.banned).toBe(false);
+});
+
+test('Enforce community ban for federated user', async () => {
+ let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
+ let userSearch = await searchForUser(beta, alphaShortname);
+ let alphaUser = userSearch.users[0];
+ expect(alphaUser).toBeDefined();
+ await delay();
+
+ // ban alpha from beta site
+ await banUserFromCommunity(beta, alphaUser.id, 2, false);
+ let banAlpha = await banUserFromCommunity(beta, alphaUser.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);
+ await longDelay();
+
+ // Make sure that post doesn't make it to beta community
+ let searchBeta = await searchPostLocal(beta, postRes.post);
+ let betaPost = searchBeta.posts[0];
+ expect(betaPost).toBeUndefined();
+
+ // Unban alpha
+ let unBanAlpha = await banUserFromCommunity(beta, alphaUser.id, 2, false);
+ expect(unBanAlpha.banned).toBe(false);
+});
GetSiteResponse,
SearchType,
LemmyHttp,
+ BanUserResponse,
+ BanUserForm,
+ BanFromCommunityForm,
+ BanFromCommunityResponse,
} from 'lemmy-js-client';
export interface API {
api: API,
community_id: number
): Promise<PostResponse> {
- let name = 'A jest test post';
- let body = 'Some body';
+ let name = randomString(5);
+ let body = randomString(10);
let url = 'https://google.com/';
let form: PostForm = {
name,
return api.client.search(form);
}
+export async function searchPostLocal(
+ api: API,
+ post: Post
+): Promise<SearchResponse> {
+ let form: SearchForm = {
+ q: post.name,
+ type_: SearchType.Posts,
+ sort: SortType.TopAll,
+ };
+ return api.client.search(form);
+}
+
export async function getPost(
api: API,
post_id: number
return api.client.search(form);
}
+export async function banUserFromSite(
+ api: API,
+ user_id: number,
+ ban: boolean,
+): Promise<BanUserResponse> {
+ // Make sure lemmy-beta/c/main is cached on lemmy_alpha
+ // Use short-hand search url
+ let form: BanUserForm = {
+ user_id,
+ ban,
+ auth: api.auth,
+ };
+ return api.client.banUser(form);
+}
+
+export async function banUserFromCommunity(
+ api: API,
+ user_id: number,
+ community_id: number,
+ ban: boolean,
+): Promise<BanFromCommunityResponse> {
+ // Make sure lemmy-beta/c/main is cached on lemmy_alpha
+ // Use short-hand search url
+ let form: BanFromCommunityForm = {
+ user_id,
+ community_id,
+ ban,
+ auth: api.auth,
+ };
+ return api.client.banFromCommunity(form);
+}
+
export async function followCommunity(
api: API,
follow: boolean,