Fixing tests.

This commit is contained in:
Dessalines 2021-08-11 14:33:50 -04:00
parent 3ccd860f51
commit fef2fff034
6 changed files with 28 additions and 42 deletions

View file

@ -16,7 +16,7 @@
"eslint": "^7.30.0",
"eslint-plugin-jane": "^9.0.3",
"jest": "^27.0.6",
"lemmy-js-client": "0.11.0-rc.3",
"lemmy-js-client": "0.11.4-rc.8",
"node-fetch": "^2.6.1",
"prettier": "^2.3.2",
"ts-jest": "^27.0.3",

View file

@ -332,9 +332,9 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t
test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedded comments, A subs to B, B updates the lowest level comment, A fetches both the post and all the inreplyto comments for that post.', async () => {
// Unfollow all remote communities
let followed = await unfollowRemotes(alpha);
let site = await unfollowRemotes(alpha);
expect(
followed.communities.filter(c => c.community.local == false).length
site.my_user.follows.filter(c => c.community.local == false).length
).toBe(0);
// B creates a post, and two comments, should be invisible to A

View file

@ -4,8 +4,8 @@ import {
setupLogins,
searchForBetaCommunity,
followCommunity,
checkFollowedCommunities,
unfollowRemotes,
getSite,
} from './shared';
beforeAll(async () => {
@ -29,8 +29,8 @@ test('Follow federated community', async () => {
expect(follow.community_view.community.name).toBe('main');
// Check it from local
let followCheck = await checkFollowedCommunities(alpha);
let remoteCommunityId = followCheck.communities.find(
let site = await getSite(alpha);
let remoteCommunityId = site.my_user.follows.find(
c => c.community.local == false
).community.id;
expect(remoteCommunityId).toBeDefined();
@ -40,6 +40,6 @@ test('Follow federated community', async () => {
expect(unfollow.community_view.community.local).toBe(false);
// Make sure you are unsubbed locally
let unfollowCheck = await checkFollowedCommunities(alpha);
expect(unfollowCheck.communities.length).toBeGreaterThanOrEqual(1);
let siteUnfollowCheck = await getSite(alpha);
expect(siteUnfollowCheck.my_user.follows.length).toBeGreaterThanOrEqual(1);
});

View file

@ -12,7 +12,6 @@ import {
SearchResponse,
FollowCommunity,
CommunityResponse,
GetFollowedCommunitiesResponse,
GetPostResponse,
Register,
Comment,
@ -30,7 +29,6 @@ import {
CreatePostLike,
EditPrivateMessage,
DeletePrivateMessage,
GetFollowedCommunities,
GetPrivateMessages,
GetSite,
GetPost,
@ -336,15 +334,6 @@ export async function followCommunity(
return api.client.followCommunity(form);
}
export async function checkFollowedCommunities(
api: API
): Promise<GetFollowedCommunitiesResponse> {
let form: GetFollowedCommunities = {
auth: api.auth,
};
return api.client.getFollowedCommunities(form);
}
export async function likePost(
api: API,
score: number,
@ -543,8 +532,7 @@ export async function registerUser(
}
export async function saveUserSettingsBio(
api: API,
auth: string
api: API
): Promise<LoginResponse> {
let form: SaveUserSettings = {
show_nsfw: true,
@ -555,7 +543,7 @@ export async function saveUserSettingsBio(
show_avatars: true,
send_notifications_to_email: false,
bio: 'a changed bio',
auth,
auth: api.auth,
};
return saveUserSettings(api, form);
}
@ -568,11 +556,10 @@ export async function saveUserSettings(
}
export async function getSite(
api: API,
auth: string
api: API
): Promise<GetSiteResponse> {
let form: GetSite = {
auth,
auth: api.auth,
};
return api.client.getSite(form);
}
@ -590,17 +577,17 @@ export async function listPrivateMessages(
export async function unfollowRemotes(
api: API
): Promise<GetFollowedCommunitiesResponse> {
): Promise<GetSiteResponse> {
// Unfollow all remote communities
let followed = await checkFollowedCommunities(api);
let remoteFollowed = followed.communities.filter(
let site = await getSite(api);
let remoteFollowed = site.my_user.follows.filter(
c => c.community.local == false
);
for (let cu of remoteFollowed) {
await followCommunity(api, false, cu.community.id);
}
let followed2 = await checkFollowedCommunities(api);
return followed2;
let siteRes = await getSite(api);
return siteRes;
}
export async function followBeta(api: API): Promise<CommunityResponse> {

View file

@ -14,12 +14,11 @@ import {
ListingType,
} from 'lemmy-js-client';
let auth: string;
let apShortname: string;
function assertUserFederation(userOne: PersonViewSafe, userTwo: PersonViewSafe) {
expect(userOne.person.name).toBe(userTwo.person.name);
expect(userOne.person.preferred_username).toBe(userTwo.person.preferred_username);
expect(userOne.person.display_name).toBe(userTwo.person.display_name);
expect(userOne.person.bio).toBe(userTwo.person.bio);
expect(userOne.person.actor_id).toBe(userTwo.person.actor_id);
expect(userOne.person.avatar).toBe(userTwo.person.avatar);
@ -30,11 +29,11 @@ function assertUserFederation(userOne: PersonViewSafe, userTwo: PersonViewSafe)
test('Create user', async () => {
let userRes = await registerUser(alpha);
expect(userRes.jwt).toBeDefined();
auth = userRes.jwt;
alpha.auth = userRes.jwt;
let site = await getSite(alpha, auth);
let site = await getSite(alpha);
expect(site.my_user).toBeDefined();
apShortname = `@${site.my_user.person.name}@lemmy-alpha:8541`;
apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
});
test('Set some user settings, check that they are federated', async () => {
@ -49,11 +48,11 @@ test('Set some user settings, check that they are federated', async () => {
lang: '',
avatar,
banner,
preferred_username: 'user321',
display_name: 'user321',
show_avatars: false,
send_notifications_to_email: false,
bio,
auth,
auth: alpha.auth,
};
await saveUserSettings(alpha, form);

View file

@ -3076,10 +3076,10 @@ language-tags@^1.0.5:
dependencies:
language-subtag-registry "~0.3.2"
lemmy-js-client@0.11.0-rc.3:
version "0.11.0-rc.3"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.0-rc.3.tgz#dd4727ca4d16fe9593368725aacfd9e7a8d52548"
integrity sha512-16mgl+TS1+0UHiY+ZKPuqHfbrn93h8K8tJ+kKJ1pjT2WhG23o0B8dLahG1jDQPG+dkXpR6PZxYudMYjuO8WvjQ==
lemmy-js-client@0.11.4-rc.8:
version "0.11.4-rc.8"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.11.4-rc.8.tgz#c333fbd5e46fe76b0d029f3effb9e539ad00160f"
integrity sha512-cDOlaX0nUtXFwJoz0SLxbkHXeFb6Uu4jomTBk6drpmJbvmWY4WuUtnZPiIUIsE00U/3KbpgsKc2Qm7XL9bb6Ng==
leven@^3.1.0:
version "3.1.0"