2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2022-07-30 03:55:59 +00:00
|
|
|
import { CommunityView } from 'lemmy-js-client';
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
beta,
|
|
|
|
setupLogins,
|
2021-08-23 15:25:39 +00:00
|
|
|
resolveCommunity,
|
2020-08-04 14:57:37 +00:00
|
|
|
createCommunity,
|
|
|
|
deleteCommunity,
|
|
|
|
removeCommunity,
|
2020-11-05 20:19:06 +00:00
|
|
|
getCommunity,
|
|
|
|
followCommunity,
|
2020-08-04 14:57:37 +00:00
|
|
|
} from './shared';
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await setupLogins();
|
|
|
|
});
|
|
|
|
|
2020-09-17 15:41:51 +00:00
|
|
|
function assertCommunityFederation(
|
2020-12-20 21:16:57 +00:00
|
|
|
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);
|
2022-07-30 03:55:59 +00:00
|
|
|
expect(communityOne.community.description.unwrapOr("none")).toBe(
|
|
|
|
communityTwo.community.description.unwrapOr("none")
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
2022-07-30 03:55:59 +00:00
|
|
|
expect(communityOne.community.icon.unwrapOr("none")).toBe(communityTwo.community.icon.unwrapOr("none"));
|
|
|
|
expect(communityOne.community.banner.unwrapOr("none")).toBe(communityTwo.community.banner.unwrapOr("none"));
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(communityOne.community.published).toBe(
|
|
|
|
communityTwo.community.published
|
|
|
|
);
|
|
|
|
expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
|
|
|
|
expect(communityOne.community.removed).toBe(communityTwo.community.removed);
|
|
|
|
expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
|
2020-09-17 15:41:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
test('Create community', async () => {
|
|
|
|
let communityRes = await createCommunity(alpha);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(communityRes.community_view.community.name).toBeDefined();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// A dupe check
|
2020-12-20 21:16:57 +00:00
|
|
|
let prevName = communityRes.community_view.community.name;
|
|
|
|
let communityRes2: any = await createCommunity(alpha, prevName);
|
2020-08-04 14:57:37 +00:00
|
|
|
expect(communityRes2['error']).toBe('community_already_exists');
|
2020-09-15 19:26:47 +00:00
|
|
|
|
|
|
|
// Cache the community on beta, make sure it has the other fields
|
|
|
|
let searchShort = `!${prevName}@lemmy-alpha:8541`;
|
2022-07-30 03:55:59 +00:00
|
|
|
let betaCommunity = (await resolveCommunity(beta, searchShort)).community.unwrap();
|
2021-08-23 15:25:39 +00:00
|
|
|
assertCommunityFederation(betaCommunity, communityRes.community_view);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Delete community', async () => {
|
|
|
|
let communityRes = await createCommunity(beta);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Cache the community on Alpha
|
2020-12-20 21:16:57 +00:00
|
|
|
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
2022-07-30 03:55:59 +00:00
|
|
|
let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community.unwrap();
|
2021-08-23 15:25:39 +00:00
|
|
|
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Follow the community from alpha
|
2020-12-20 21:16:57 +00:00
|
|
|
let follow = await followCommunity(
|
|
|
|
alpha,
|
|
|
|
true,
|
2021-08-23 15:25:39 +00:00
|
|
|
alphaCommunity.community.id
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Make sure the follow response went through
|
2022-05-26 15:17:04 +00:00
|
|
|
expect(follow.community_view.community.local).toBe(false);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
let deleteCommunityRes = await deleteCommunity(
|
|
|
|
beta,
|
|
|
|
true,
|
2020-12-20 21:16:57 +00:00
|
|
|
communityRes.community_view.community.id
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
|
2021-10-27 13:34:18 +00:00
|
|
|
expect(deleteCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure it got deleted on A
|
2020-12-20 21:16:57 +00:00
|
|
|
let communityOnAlphaDeleted = await getCommunity(
|
|
|
|
alpha,
|
2021-08-23 15:25:39 +00:00
|
|
|
alphaCommunity.community.id
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Undelete
|
|
|
|
let undeleteCommunityRes = await deleteCommunity(
|
|
|
|
beta,
|
|
|
|
false,
|
2020-12-20 21:16:57 +00:00
|
|
|
communityRes.community_view.community.id
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure it got undeleted on A
|
2020-12-20 21:16:57 +00:00
|
|
|
let communityOnAlphaUnDeleted = await getCommunity(
|
|
|
|
alpha,
|
2021-08-23 15:25:39 +00:00
|
|
|
alphaCommunity.community.id
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
|
|
|
|
false
|
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Remove community', async () => {
|
|
|
|
let communityRes = await createCommunity(beta);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Cache the community on Alpha
|
2020-12-20 21:16:57 +00:00
|
|
|
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
2022-07-30 03:55:59 +00:00
|
|
|
let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community.unwrap();
|
2021-08-23 15:25:39 +00:00
|
|
|
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Follow the community from alpha
|
2020-12-20 21:16:57 +00:00
|
|
|
let follow = await followCommunity(
|
|
|
|
alpha,
|
|
|
|
true,
|
2021-08-23 15:25:39 +00:00
|
|
|
alphaCommunity.community.id
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Make sure the follow response went through
|
2022-05-26 15:17:04 +00:00
|
|
|
expect(follow.community_view.community.local).toBe(false);
|
2020-11-05 20:19:06 +00:00
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
let removeCommunityRes = await removeCommunity(
|
|
|
|
beta,
|
|
|
|
true,
|
2020-12-20 21:16:57 +00:00
|
|
|
communityRes.community_view.community.id
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(removeCommunityRes.community_view.community.removed).toBe(true);
|
2021-10-27 13:34:18 +00:00
|
|
|
expect(removeCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-11-05 20:19:06 +00:00
|
|
|
// Make sure it got Removed on A
|
2020-12-20 21:16:57 +00:00
|
|
|
let communityOnAlphaRemoved = await getCommunity(
|
|
|
|
alpha,
|
2021-08-23 15:25:39 +00:00
|
|
|
alphaCommunity.community.id
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// unremove
|
|
|
|
let unremoveCommunityRes = await removeCommunity(
|
|
|
|
beta,
|
|
|
|
false,
|
2020-12-20 21:16:57 +00:00
|
|
|
communityRes.community_view.community.id
|
2020-08-04 14:57:37 +00:00
|
|
|
);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-11-05 20:19:06 +00:00
|
|
|
// Make sure it got undeleted on A
|
2020-12-20 21:16:57 +00:00
|
|
|
let communityOnAlphaUnRemoved = await getCommunity(
|
|
|
|
alpha,
|
2021-08-23 15:25:39 +00:00
|
|
|
alphaCommunity.community.id
|
2020-12-20 21:16:57 +00:00
|
|
|
);
|
|
|
|
expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
|
|
|
|
false
|
|
|
|
);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Search for beta community', async () => {
|
2020-11-05 20:19:06 +00:00
|
|
|
let communityRes = await createCommunity(beta);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(communityRes.community_view.community.name).toBeDefined();
|
2020-11-05 20:19:06 +00:00
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
2022-07-30 03:55:59 +00:00
|
|
|
let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community.unwrap();
|
2021-08-23 15:25:39 +00:00
|
|
|
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|