Skip to content

Commit

Permalink
Fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Aug 11, 2021
1 parent 0a5b025 commit 724624a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 42 deletions.
2 changes: 1 addition & 1 deletion api_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions api_tests/src/comment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions api_tests/src/follow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
setupLogins,
searchForBetaCommunity,
followCommunity,
checkFollowedCommunities,
unfollowRemotes,
getSite,
} from './shared';

beforeAll(async () => {
Expand All @@ -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();
Expand All @@ -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);
});
31 changes: 9 additions & 22 deletions api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
SearchResponse,
FollowCommunity,
CommunityResponse,
GetFollowedCommunitiesResponse,
GetPostResponse,
Register,
Comment,
Expand All @@ -30,7 +29,6 @@ import {
CreatePostLike,
EditPrivateMessage,
DeletePrivateMessage,
GetFollowedCommunities,
GetPrivateMessages,
GetSite,
GetPost,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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> {
Expand Down
15 changes: 7 additions & 8 deletions api_tests/src/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

let site = await getSite(alpha, auth);
alpha.auth = userRes.jwt;
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 () => {
Expand All @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions api_tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 724624a

Please sign in to comment.