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": "^7.30.0",
"eslint-plugin-jane": "^9.0.3", "eslint-plugin-jane": "^9.0.3",
"jest": "^27.0.6", "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", "node-fetch": "^2.6.1",
"prettier": "^2.3.2", "prettier": "^2.3.2",
"ts-jest": "^27.0.3", "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 () => { 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 // Unfollow all remote communities
let followed = await unfollowRemotes(alpha); let site = await unfollowRemotes(alpha);
expect( expect(
followed.communities.filter(c => c.community.local == false).length site.my_user.follows.filter(c => c.community.local == false).length
).toBe(0); ).toBe(0);
// B creates a post, and two comments, should be invisible to A // B creates a post, and two comments, should be invisible to A

View file

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

View file

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

View file

@ -14,12 +14,11 @@ import {
ListingType, ListingType,
} from 'lemmy-js-client'; } from 'lemmy-js-client';
let auth: string;
let apShortname: string; let apShortname: string;
function assertUserFederation(userOne: PersonViewSafe, userTwo: PersonViewSafe) { function assertUserFederation(userOne: PersonViewSafe, userTwo: PersonViewSafe) {
expect(userOne.person.name).toBe(userTwo.person.name); 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.bio).toBe(userTwo.person.bio);
expect(userOne.person.actor_id).toBe(userTwo.person.actor_id); expect(userOne.person.actor_id).toBe(userTwo.person.actor_id);
expect(userOne.person.avatar).toBe(userTwo.person.avatar); expect(userOne.person.avatar).toBe(userTwo.person.avatar);
@ -30,11 +29,11 @@ function assertUserFederation(userOne: PersonViewSafe, userTwo: PersonViewSafe)
test('Create user', async () => { test('Create user', async () => {
let userRes = await registerUser(alpha); let userRes = await registerUser(alpha);
expect(userRes.jwt).toBeDefined(); 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(); 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 () => { 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: '', lang: '',
avatar, avatar,
banner, banner,
preferred_username: 'user321', display_name: 'user321',
show_avatars: false, show_avatars: false,
send_notifications_to_email: false, send_notifications_to_email: false,
bio, bio,
auth, auth: alpha.auth,
}; };
await saveUserSettings(alpha, form); await saveUserSettings(alpha, form);

View file

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