2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2020-08-04 14:57:37 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
beta,
|
|
|
|
setupLogins,
|
|
|
|
searchForBetaCommunity,
|
2020-09-15 19:26:47 +00:00
|
|
|
searchForCommunity,
|
2020-08-04 14:57:37 +00:00
|
|
|
createCommunity,
|
|
|
|
deleteCommunity,
|
|
|
|
removeCommunity,
|
2020-11-05 20:19:06 +00:00
|
|
|
getCommunity,
|
|
|
|
followCommunity,
|
2020-08-31 13:48:02 +00:00
|
|
|
delay,
|
2020-11-05 20:19:06 +00:00
|
|
|
longDelay,
|
2020-08-04 14:57:37 +00:00
|
|
|
} from './shared';
|
2020-09-17 15:41:51 +00:00
|
|
|
import {
|
|
|
|
Community,
|
|
|
|
} from 'lemmy-js-client';
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await setupLogins();
|
|
|
|
});
|
|
|
|
|
2020-09-17 15:41:51 +00:00
|
|
|
function assertCommunityFederation(
|
|
|
|
communityOne: Community,
|
|
|
|
communityTwo: Community) {
|
|
|
|
expect(communityOne.actor_id).toBe(communityTwo.actor_id);
|
|
|
|
expect(communityOne.name).toBe(communityTwo.name);
|
|
|
|
expect(communityOne.title).toBe(communityTwo.title);
|
|
|
|
expect(communityOne.description).toBe(communityTwo.description);
|
|
|
|
expect(communityOne.icon).toBe(communityTwo.icon);
|
|
|
|
expect(communityOne.banner).toBe(communityTwo.banner);
|
|
|
|
expect(communityOne.published).toBe(communityTwo.published);
|
|
|
|
expect(communityOne.creator_actor_id).toBe(communityTwo.creator_actor_id);
|
|
|
|
expect(communityOne.nsfw).toBe(communityTwo.nsfw);
|
|
|
|
expect(communityOne.category_id).toBe(communityTwo.category_id);
|
|
|
|
expect(communityOne.removed).toBe(communityTwo.removed);
|
|
|
|
expect(communityOne.deleted).toBe(communityTwo.deleted);
|
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
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');
|
2020-09-15 19:26:47 +00:00
|
|
|
await delay();
|
|
|
|
|
|
|
|
// Cache the community on beta, make sure it has the other fields
|
|
|
|
let searchShort = `!${prevName}@lemmy-alpha:8541`;
|
|
|
|
let search = await searchForCommunity(beta, searchShort);
|
|
|
|
let communityOnBeta = search.communities[0];
|
2020-09-17 15:41:51 +00:00
|
|
|
assertCommunityFederation(communityOnBeta, communityRes.community);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Delete community', async () => {
|
|
|
|
let communityRes = await createCommunity(beta);
|
2020-08-31 13:48:02 +00:00
|
|
|
await delay();
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Cache the community on Alpha
|
|
|
|
let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
|
|
|
|
let search = await searchForCommunity(alpha, searchShort);
|
|
|
|
let communityOnAlpha = search.communities[0];
|
|
|
|
assertCommunityFederation(communityOnAlpha, communityRes.community);
|
|
|
|
await delay();
|
|
|
|
|
|
|
|
// Follow the community from alpha
|
|
|
|
let follow = await followCommunity(alpha, true, communityOnAlpha.id);
|
|
|
|
|
|
|
|
// Make sure the follow response went through
|
|
|
|
expect(follow.community.local).toBe(false);
|
|
|
|
await delay();
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
let deleteCommunityRes = await deleteCommunity(
|
|
|
|
beta,
|
|
|
|
true,
|
|
|
|
communityRes.community.id
|
|
|
|
);
|
|
|
|
expect(deleteCommunityRes.community.deleted).toBe(true);
|
2020-08-31 13:48:02 +00:00
|
|
|
await delay();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure it got deleted on A
|
2020-11-05 20:19:06 +00:00
|
|
|
let communityOnAlphaDeleted = await getCommunity(alpha, communityOnAlpha.id);
|
|
|
|
expect(communityOnAlphaDeleted.community.deleted).toBe(true);
|
|
|
|
await delay();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Undelete
|
|
|
|
let undeleteCommunityRes = await deleteCommunity(
|
|
|
|
beta,
|
|
|
|
false,
|
|
|
|
communityRes.community.id
|
|
|
|
);
|
|
|
|
expect(undeleteCommunityRes.community.deleted).toBe(false);
|
2020-08-31 13:48:02 +00:00
|
|
|
await delay();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure it got undeleted on A
|
2020-11-05 20:19:06 +00:00
|
|
|
let communityOnAlphaUnDeleted = await getCommunity(alpha, communityOnAlpha.id);
|
|
|
|
expect(communityOnAlphaUnDeleted.community.deleted).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Remove community', async () => {
|
|
|
|
let communityRes = await createCommunity(beta);
|
2020-08-31 13:48:02 +00:00
|
|
|
await delay();
|
2020-11-05 20:19:06 +00:00
|
|
|
|
|
|
|
// Cache the community on Alpha
|
|
|
|
let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
|
|
|
|
let search = await searchForCommunity(alpha, searchShort);
|
|
|
|
let communityOnAlpha = search.communities[0];
|
|
|
|
assertCommunityFederation(communityOnAlpha, communityRes.community);
|
|
|
|
await delay();
|
|
|
|
|
|
|
|
// Follow the community from alpha
|
|
|
|
let follow = await followCommunity(alpha, true, communityOnAlpha.id);
|
|
|
|
|
|
|
|
// Make sure the follow response went through
|
|
|
|
expect(follow.community.local).toBe(false);
|
|
|
|
await delay();
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
let removeCommunityRes = await removeCommunity(
|
|
|
|
beta,
|
|
|
|
true,
|
|
|
|
communityRes.community.id
|
|
|
|
);
|
|
|
|
expect(removeCommunityRes.community.removed).toBe(true);
|
2020-11-05 20:19:06 +00:00
|
|
|
await delay();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-11-05 20:19:06 +00:00
|
|
|
// Make sure it got Removed on A
|
|
|
|
let communityOnAlphaRemoved = await getCommunity(alpha, communityOnAlpha.id);
|
|
|
|
expect(communityOnAlphaRemoved.community.removed).toBe(true);
|
2020-08-31 13:48:02 +00:00
|
|
|
await delay();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// unremove
|
|
|
|
let unremoveCommunityRes = await removeCommunity(
|
|
|
|
beta,
|
|
|
|
false,
|
|
|
|
communityRes.community.id
|
|
|
|
);
|
|
|
|
expect(unremoveCommunityRes.community.removed).toBe(false);
|
2020-08-31 13:48:02 +00:00
|
|
|
await delay();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-11-05 20:19:06 +00:00
|
|
|
// Make sure it got undeleted on A
|
|
|
|
let communityOnAlphaUnRemoved = await getCommunity(alpha, communityOnAlpha.id);
|
|
|
|
expect(communityOnAlphaUnRemoved.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);
|
|
|
|
expect(communityRes.community.name).toBeDefined();
|
|
|
|
await delay();
|
|
|
|
|
|
|
|
let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`;
|
|
|
|
let search = await searchForCommunity(alpha, searchShort);
|
|
|
|
let communityOnAlpha = search.communities[0];
|
|
|
|
assertCommunityFederation(communityOnAlpha, communityRes.community);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|