mirror of https://github.com/LemmyNet/lemmy.git
fix api test
parent
d206e8acfb
commit
3da2804d4b
|
@ -27,6 +27,9 @@ import {
|
||||||
reportPost,
|
reportPost,
|
||||||
listPostReports,
|
listPostReports,
|
||||||
randomString,
|
randomString,
|
||||||
|
registerUser,
|
||||||
|
API,
|
||||||
|
getSite
|
||||||
} from './shared';
|
} from './shared';
|
||||||
import { PostView, CommunityView } from 'lemmy-js-client';
|
import { PostView, CommunityView } from 'lemmy-js-client';
|
||||||
|
|
||||||
|
@ -297,43 +300,45 @@ test('A and G subscribe to B (center) A posts, it gets announced to G', async ()
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Enforce site ban for federated user', async () => {
|
test('Enforce site ban for federated user', async () => {
|
||||||
let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
|
// create a test user
|
||||||
let alphaPerson = (await resolvePerson(alpha, alphaShortname)).person;
|
let alphaUserJwt = await registerUser(alpha);
|
||||||
|
expect(alphaUserJwt).toBeDefined();
|
||||||
|
let alphaUser: API = {
|
||||||
|
client: alpha.client,
|
||||||
|
auth: alphaUserJwt.jwt,
|
||||||
|
};
|
||||||
|
let alphaUserActorId = (await getSite(alphaUser)).my_user.local_user_view.person.actor_id;
|
||||||
|
expect(alphaUserActorId).toBeDefined();
|
||||||
|
let alphaPerson = (await resolvePerson(alphaUser, alphaUserActorId)).person;
|
||||||
expect(alphaPerson).toBeDefined();
|
expect(alphaPerson).toBeDefined();
|
||||||
|
|
||||||
let postRes1 = await createPost(alpha, betaCommunity.community.id);
|
// alpha makes post in beta community, it federates to beta instance
|
||||||
|
let postRes1 = await createPost(alphaUser, betaCommunity.community.id);
|
||||||
let searchBeta1 = await searchPostLocal(beta, postRes1.post_view.post);
|
let searchBeta1 = await searchPostLocal(beta, postRes1.post_view.post);
|
||||||
expect(searchBeta1.posts[0]).toBeDefined();
|
expect(searchBeta1.posts[0]).toBeDefined();
|
||||||
|
|
||||||
// ban alpha from site
|
// ban alpha from its instance
|
||||||
let banAlpha = await banPersonFromSite(alpha, alphaPerson.person.id, true, true);
|
let banAlpha = await banPersonFromSite(alpha, alphaPerson.person.id, true, true);
|
||||||
expect(banAlpha.banned).toBe(true);
|
expect(banAlpha.banned).toBe(true);
|
||||||
|
|
||||||
// alpha ban should be federated to beta
|
// alpha ban should be federated to beta
|
||||||
let alphaUserOnBeta1 = await resolvePerson(beta, alphaPerson.person.actor_id);
|
let alphaUserOnBeta1 = await resolvePerson(beta, alphaUserActorId);
|
||||||
console.debug(alphaUserOnBeta1);
|
|
||||||
expect(alphaUserOnBeta1.person.person.banned).toBe(true);
|
expect(alphaUserOnBeta1.person.person.banned).toBe(true);
|
||||||
|
|
||||||
// post should be removed
|
// existing alpha post should be removed on beta
|
||||||
let searchBeta2 = await searchPostLocal(beta, postRes1.post_view.post);
|
let searchBeta2 = await searchPostLocal(beta, postRes1.post_view.post);
|
||||||
expect(searchBeta2.posts[0]).toBeUndefined();
|
expect(searchBeta2.posts[0]).toBeUndefined();
|
||||||
|
|
||||||
// Alpha makes new post on beta
|
|
||||||
let postRes2 = await createPost(alpha, betaCommunity.community.id);
|
|
||||||
expect(postRes2.post_view.post).toBeDefined();
|
|
||||||
expect(postRes2.post_view.community.local).toBe(false);
|
|
||||||
expect(postRes2.post_view.creator.local).toBe(true);
|
|
||||||
expect(postRes2.post_view.counts.score).toBe(1);
|
|
||||||
|
|
||||||
// Make sure that post doesn't make it to beta
|
|
||||||
let searchBeta = await searchPostLocal(beta, postRes2.post_view.post);
|
|
||||||
expect(searchBeta.posts[0]).toBeUndefined();
|
|
||||||
|
|
||||||
// Unban alpha
|
// Unban alpha
|
||||||
let unBanAlpha = await banPersonFromSite(alpha, alphaPerson.person.id, false, false);
|
let unBanAlpha = await banPersonFromSite(alpha, alphaPerson.person.id, false, false);
|
||||||
expect(unBanAlpha.banned).toBe(false);
|
expect(unBanAlpha.banned).toBe(false);
|
||||||
|
|
||||||
let alphaUserOnBeta2 = await resolvePerson(beta, alphaPerson.person.actor_id)
|
// alpha makes new post in beta community, it federates
|
||||||
|
let postRes2 = await createPost(alphaUser, betaCommunity.community.id);
|
||||||
|
let searchBeta3 = await searchPostLocal(beta, postRes2.post_view.post);
|
||||||
|
expect(searchBeta3.posts[0]).toBeDefined();
|
||||||
|
|
||||||
|
let alphaUserOnBeta2 = await resolvePerson(beta, alphaUserActorId)
|
||||||
expect(alphaUserOnBeta2.person.person.banned).toBe(false);
|
expect(alphaUserOnBeta2.person.person.banned).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue