From 434fb53dd1d6d09a3be912bc05465b970f6402b6 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 12 Mar 2021 14:09:03 -0500 Subject: [PATCH] Trying to fix API tests. --- api_tests/package.json | 2 +- api_tests/src/community.spec.ts | 3 --- api_tests/src/post.spec.ts | 16 ++++++++-------- api_tests/src/shared.ts | 33 ++++++++++++++++----------------- api_tests/src/user.spec.ts | 20 ++++++++++---------- api_tests/yarn.lock | 8 ++++---- 6 files changed, 39 insertions(+), 43 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index e2c4f37a0..d4232ed53 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -16,7 +16,7 @@ "eslint": "^7.18.0", "eslint-plugin-jane": "^9.0.3", "jest": "^26.6.3", - "lemmy-js-client": "0.9.1-rc.1", + "lemmy-js-client": "0.10.0-rc.4", "node-fetch": "^2.6.1", "prettier": "^2.1.2", "ts-jest": "^26.4.4", diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index 25d8109c3..7be6f4c59 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -33,9 +33,6 @@ function assertCommunityFederation( ); expect(communityOne.creator.actor_id).toBe(communityTwo.creator.actor_id); expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw); - expect(communityOne.community.category_id).toBe( - communityTwo.community.category_id - ); expect(communityOne.community.removed).toBe(communityTwo.community.removed); expect(communityOne.community.deleted).toBe(communityTwo.community.deleted); } diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 01befa60c..a79ee198b 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -20,9 +20,9 @@ import { getPost, unfollowRemotes, searchForUser, - banUserFromSite, + banPersonFromSite, searchPostLocal, - banUserFromCommunity, + banPersonFromCommunity, } from './shared'; import { PostView, CommunityView } from 'lemmy-js-client'; @@ -305,7 +305,7 @@ test('Enforce site ban for federated user', async () => { expect(alphaUser).toBeDefined(); // ban alpha from beta site - let banAlpha = await banUserFromSite(beta, alphaUser.user.id, true); + let banAlpha = await banPersonFromSite(beta, alphaUser.person.id, true); expect(banAlpha.banned).toBe(true); // Alpha makes post on beta @@ -321,7 +321,7 @@ test('Enforce site ban for federated user', async () => { expect(betaPost).toBeUndefined(); // Unban alpha - let unBanAlpha = await banUserFromSite(beta, alphaUser.user.id, false); + let unBanAlpha = await banPersonFromSite(beta, alphaUser.person.id, false); expect(unBanAlpha.banned).toBe(false); }); @@ -332,8 +332,8 @@ test('Enforce community ban for federated user', async () => { expect(alphaUser).toBeDefined(); // ban alpha from beta site - await banUserFromCommunity(beta, alphaUser.user.id, 2, false); - let banAlpha = await banUserFromCommunity(beta, alphaUser.user.id, 2, true); + await banPersonFromCommunity(beta, alphaUser.person.id, 2, false); + let banAlpha = await banPersonFromCommunity(beta, alphaUser.person.id, 2, true); expect(banAlpha.banned).toBe(true); // Alpha makes post on beta @@ -349,9 +349,9 @@ test('Enforce community ban for federated user', async () => { expect(betaPost).toBeUndefined(); // Unban alpha - let unBanAlpha = await banUserFromCommunity( + let unBanAlpha = await banPersonFromCommunity( beta, - alphaUser.user.id, + alphaUser.person.id, 2, false ); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 0c12d29c0..c11fa3b0e 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -25,7 +25,7 @@ import { CreateCommunity, DeleteCommunity, RemoveCommunity, - GetUserMentions, + GetPersonMentions, CreateCommentLike, CreatePostLike, EditPrivateMessage, @@ -36,15 +36,15 @@ import { GetPost, PrivateMessageResponse, PrivateMessagesResponse, - GetUserMentionsResponse, + GetPersonMentionsResponse, SaveUserSettings, SortType, ListingType, GetSiteResponse, SearchType, LemmyHttp, - BanUserResponse, - BanUser, + BanPersonResponse, + BanPerson, BanFromCommunity, BanFromCommunityResponse, Post, @@ -289,32 +289,32 @@ export async function searchForUser( return api.client.search(form); } -export async function banUserFromSite( +export async function banPersonFromSite( api: API, - user_id: number, + person_id: number, ban: boolean -): Promise { +): Promise { // Make sure lemmy-beta/c/main is cached on lemmy_alpha // Use short-hand search url - let form: BanUser = { - user_id, + let form: BanPerson = { + person_id, ban, remove_data: false, auth: api.auth, }; - return api.client.banUser(form); + return api.client.banPerson(form); } -export async function banUserFromCommunity( +export async function banPersonFromCommunity( api: API, - user_id: number, + person_id: number, community_id: number, ban: boolean ): Promise { // Make sure lemmy-beta/c/main is cached on lemmy_alpha // Use short-hand search url let form: BanFromCommunity = { - user_id, + person_id, community_id, remove_data: false, ban, @@ -413,13 +413,13 @@ export async function removeComment( return api.client.removeComment(form); } -export async function getMentions(api: API): Promise { - let form: GetUserMentions = { +export async function getMentions(api: API): Promise { + let form: GetPersonMentions = { sort: SortType.New, unread_only: false, auth: api.auth, }; - return api.client.getUserMentions(form); + return api.client.getPersonMentions(form); } export async function likeComment( @@ -448,7 +448,6 @@ export async function createCommunity( description, icon, banner, - category_id: 1, nsfw: false, auth: api.auth, }; diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 4352aa423..a10876cf5 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -8,7 +8,7 @@ import { getSite, } from './shared'; import { - UserViewSafe, + PersonViewSafe, SaveUserSettings, SortType, ListingType, @@ -17,14 +17,14 @@ import { let auth: string; let apShortname: string; -function assertUserFederation(userOne: UserViewSafe, userTwo: UserViewSafe) { - expect(userOne.user.name).toBe(userTwo.user.name); - expect(userOne.user.preferred_username).toBe(userTwo.user.preferred_username); - expect(userOne.user.bio).toBe(userTwo.user.bio); - expect(userOne.user.actor_id).toBe(userTwo.user.actor_id); - expect(userOne.user.avatar).toBe(userTwo.user.avatar); - expect(userOne.user.banner).toBe(userTwo.user.banner); - expect(userOne.user.published).toBe(userTwo.user.published); +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.bio).toBe(userTwo.person.bio); + expect(userOne.person.actor_id).toBe(userTwo.person.actor_id); + expect(userOne.person.avatar).toBe(userTwo.person.avatar); + expect(userOne.person.banner).toBe(userTwo.person.banner); + expect(userOne.person.published).toBe(userTwo.person.published); } test('Create user', async () => { @@ -34,7 +34,7 @@ test('Create user', async () => { let site = await getSite(alpha, auth); expect(site.my_user).toBeDefined(); - apShortname = `@${site.my_user.name}@lemmy-alpha:8541`; + apShortname = `@${site.my_user.person.name}@lemmy-alpha:8541`; }); test('Set some user settings, check that they are federated', async () => { diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index 8e29aa041..a6d1be5a3 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -3233,10 +3233,10 @@ language-tags@^1.0.5: dependencies: language-subtag-registry "~0.3.2" -lemmy-js-client@0.9.1-rc.1: - version "0.9.1-rc.1" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.9.1-rc.1.tgz#afe3cb0d4852f849dd087a4756a3771bc920a907" - integrity sha512-aVvo4IeJvIPUvypipk4GnyLB6nVQVLfB0arYrMkVV4L7zrZ/0pGtpkMDLaOAj/KpA6O0u9eLmaou5RberZQolA== +lemmy-js-client@0.10.0-rc.4: + version "0.10.0-rc.4" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.10.0-rc.4.tgz#ac6fe6940fc5f73260ddb166ce0ef3c0520901fc" + integrity sha512-yJPnvGaWneOOwjKEqb4qXtQk+4DbRgO+hEzSin2GgUgnxluY43gemwiCPt6EnV+j4ueKoi0+QORVg2RuRC2PaQ== leven@^3.1.0: version "3.1.0"