mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-15 12:13:04 +00:00
Merge pull request #1261 from LemmyNet/more-tests-2
Adding some more integration tests for locked posts and bans.
This commit is contained in:
commit
4a61758bde
@ -21,6 +21,10 @@ import {
|
|||||||
unfollowRemotes,
|
unfollowRemotes,
|
||||||
delay,
|
delay,
|
||||||
longDelay,
|
longDelay,
|
||||||
|
searchForUser,
|
||||||
|
banUserFromSite,
|
||||||
|
searchPostLocal,
|
||||||
|
banUserFromCommunity,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
import {
|
import {
|
||||||
Post,
|
Post,
|
||||||
@ -189,27 +193,22 @@ test('Lock a post', async () => {
|
|||||||
let postRes = await createPost(alpha, search.communities[0].id);
|
let postRes = await createPost(alpha, search.communities[0].id);
|
||||||
await delay();
|
await delay();
|
||||||
|
|
||||||
|
// Lock the post
|
||||||
let lockedPostRes = await lockPost(alpha, true, postRes.post);
|
let lockedPostRes = await lockPost(alpha, true, postRes.post);
|
||||||
expect(lockedPostRes.post.locked).toBe(true);
|
expect(lockedPostRes.post.locked).toBe(true);
|
||||||
await delay();
|
await longDelay();
|
||||||
|
|
||||||
// Make sure that post is locked on beta
|
// Make sure that post is locked on beta
|
||||||
let searchBeta = await searchPost(beta, postRes.post);
|
let searchBeta = await searchPostLocal(beta, postRes.post);
|
||||||
let betaPost = searchBeta.posts[0];
|
let betaPost1 = searchBeta.posts[0];
|
||||||
expect(betaPost.community_local).toBe(true);
|
expect(betaPost1.locked).toBe(true);
|
||||||
expect(betaPost.creator_local).toBe(false);
|
await delay();
|
||||||
expect(betaPost.locked).toBe(true);
|
|
||||||
|
|
||||||
// Try to make a new comment there, on alpha
|
// Try to make a new comment there, on alpha
|
||||||
let comment = await createComment(alpha, postRes.post.id);
|
let comment = await createComment(alpha, postRes.post.id);
|
||||||
expect(comment['error']).toBe('locked');
|
expect(comment['error']).toBe('locked');
|
||||||
await delay();
|
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
|
// Unlock a post
|
||||||
let unlockedPost = await lockPost(alpha, false, postRes.post);
|
let unlockedPost = await lockPost(alpha, false, postRes.post);
|
||||||
expect(unlockedPost.post.locked).toBe(false);
|
expect(unlockedPost.post.locked).toBe(false);
|
||||||
@ -221,6 +220,10 @@ test('Lock a post', async () => {
|
|||||||
expect(betaPost2.community_local).toBe(true);
|
expect(betaPost2.community_local).toBe(true);
|
||||||
expect(betaPost2.creator_local).toBe(false);
|
expect(betaPost2.creator_local).toBe(false);
|
||||||
expect(betaPost2.locked).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 () => {
|
test('Delete a post', async () => {
|
||||||
@ -333,3 +336,70 @@ test('A and G subscribe to B (center) A posts, it gets announced to G', async ()
|
|||||||
let search2 = await searchPost(gamma, postRes.post);
|
let search2 = await searchPost(gamma, postRes.post);
|
||||||
expect(search2.posts[0].name).toBeDefined();
|
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);
|
||||||
|
});
|
||||||
|
@ -43,6 +43,10 @@ import {
|
|||||||
GetSiteResponse,
|
GetSiteResponse,
|
||||||
SearchType,
|
SearchType,
|
||||||
LemmyHttp,
|
LemmyHttp,
|
||||||
|
BanUserResponse,
|
||||||
|
BanUserForm,
|
||||||
|
BanFromCommunityForm,
|
||||||
|
BanFromCommunityResponse,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
|
|
||||||
export interface API {
|
export interface API {
|
||||||
@ -120,8 +124,8 @@ export async function createPost(
|
|||||||
api: API,
|
api: API,
|
||||||
community_id: number
|
community_id: number
|
||||||
): Promise<PostResponse> {
|
): Promise<PostResponse> {
|
||||||
let name = 'A jest test post';
|
let name = randomString(5);
|
||||||
let body = 'Some body';
|
let body = randomString(10);
|
||||||
let url = 'https://google.com/';
|
let url = 'https://google.com/';
|
||||||
let form: PostForm = {
|
let form: PostForm = {
|
||||||
name,
|
name,
|
||||||
@ -209,6 +213,18 @@ export async function searchPost(
|
|||||||
return api.client.search(form);
|
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(
|
export async function getPost(
|
||||||
api: API,
|
api: API,
|
||||||
post_id: number
|
post_id: number
|
||||||
@ -271,6 +287,38 @@ export async function searchForUser(
|
|||||||
return api.client.search(form);
|
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(
|
export async function followCommunity(
|
||||||
api: API,
|
api: API,
|
||||||
follow: boolean,
|
follow: boolean,
|
||||||
|
Loading…
Reference in New Issue
Block a user