diff --git a/api_tests/package.json b/api_tests/package.json index 90e63a1e7..dffa7d44f 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -28,7 +28,7 @@ "eslint": "^9.14.0", "eslint-plugin-prettier": "^5.1.3", "jest": "^29.5.0", - "lemmy-js-client": "0.20.0-api-v4.0", + "lemmy-js-client": "0.20.0-api-v4.5", "prettier": "^3.2.5", "ts-jest": "^29.1.0", "typescript": "^5.5.4", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index 2ecf2a221..a7d8690ec 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^29.5.0 version: 29.7.0(@types/node@22.9.0) lemmy-js-client: - specifier: 0.20.0-api-v4.0 - version: 0.20.0-api-v4.0 + specifier: 0.20.0-api-v4.5 + version: 0.20.0-api-v4.5 prettier: specifier: ^3.2.5 version: 3.3.3 @@ -1167,8 +1167,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@0.20.0-api-v4.0: - resolution: {integrity: sha512-oS02mNzLYWcDIk3FJj1YvBmgpZJQWr34uuxharPd5jQyU8/Yub4XNHrQnjPX5wrXEC6am5ebR8iQmRuQsPQDmw==} + lemmy-js-client@0.20.0-api-v4.5: + resolution: {integrity: sha512-8Zdjb+oIYMUa5/hvS2zeGoIPLdjM+BODUCvP3/jAA/ipqEiSerJ9BdfIB61cnDE9gXnmjYvEtxnfqRZLlwdLfQ==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -3077,7 +3077,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@0.20.0-api-v4.0: {} + lemmy-js-client@0.20.0-api-v4.5: {} leven@3.1.0: {} diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index c3f4b3efe..6c8595db6 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -702,9 +702,9 @@ test("Check that activity from another instance is sent to third instance", asyn 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 site = await unfollowRemotes(alpha); + let my_user = await unfollowRemotes(alpha); expect( - site.my_user?.follows.filter(c => c.community.local == false).length, + my_user.follows.filter(c => c.community.local == false).length, ).toBe(0); // B creates a post, and two comments, should be invisible to A diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index 77b68e2fc..9ccfb92a0 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -34,6 +34,7 @@ import { longDelay, editCommunity, unfollows, + getMyUser, } from "./shared"; import { EditCommunity, EditSite } from "lemmy-js-client"; @@ -226,7 +227,7 @@ test("Admin actions in remote community are not federated to origin", async () = if (!betaCommunity) { throw "Missing beta community"; } - let bannedUserInfo1 = (await getSite(gamma)).my_user?.local_user_view.person; + let bannedUserInfo1 = (await getMyUser(gamma)).local_user_view.person; if (!bannedUserInfo1) { throw "Missing banned user 1"; } diff --git a/api_tests/src/follow.spec.ts b/api_tests/src/follow.spec.ts index 22fdfa305..936ce2606 100644 --- a/api_tests/src/follow.spec.ts +++ b/api_tests/src/follow.spec.ts @@ -12,6 +12,7 @@ import { registerUser, unfollows, delay, + getMyUser, } from "./shared"; beforeAll(setupLogins); @@ -85,8 +86,8 @@ test("Follow federated community", async () => { ); // Check it from local - let site = await getSite(alpha); - let remoteCommunityId = site.my_user?.follows.find( + let my_user = await getMyUser(alpha); + let remoteCommunityId = my_user?.follows.find( c => c.community.local == false && c.community.id === betaCommunityInitial.community.id, @@ -102,9 +103,9 @@ test("Follow federated community", async () => { expect(unfollow.community_view.subscribed).toBe("NotSubscribed"); // Make sure you are unsubbed locally - let siteUnfollowCheck = await getSite(alpha); + let siteUnfollowCheck = await getMyUser(alpha); expect( - siteUnfollowCheck.my_user?.follows.find( + siteUnfollowCheck.follows.find( c => c.community.id === betaCommunityInitial.community.id, ), ).toBe(undefined); diff --git a/api_tests/src/image.spec.ts b/api_tests/src/image.spec.ts index ede04294d..a3478081a 100644 --- a/api_tests/src/image.spec.ts +++ b/api_tests/src/image.spec.ts @@ -32,6 +32,7 @@ import { createPostWithThumbnail, sampleImage, sampleSite, + getMyUser, } from "./shared"; beforeAll(setupLogins); @@ -129,9 +130,9 @@ test("Purge user, uploaded image removed", async () => { expect(content.length).toBeGreaterThan(0); // purge user - let site = await getSite(user); + let my_user = await getMyUser(user); const purgeForm: PurgePerson = { - person_id: site.my_user!.local_user_view.person.id, + person_id: my_user.local_user_view.person.id, }; const delete_ = await alphaImage.purgePerson(purgeForm); expect(delete_.success).toBe(true); diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 59e3d774e..ce8c0ae93 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -38,6 +38,7 @@ import { alphaUrl, loginUser, createCommunity, + getMyUser, } from "./shared"; import { PostView } from "lemmy-js-client/dist/types/PostView"; import { EditSite, ResolveObject } from "lemmy-js-client"; @@ -452,7 +453,7 @@ test("Enforce site ban federation for local user", async () => { // create a test user let alphaUserHttp = await registerUser(alpha, alphaUrl); - let alphaUserPerson = (await getSite(alphaUserHttp)).my_user?.local_user_view + let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view .person; let alphaUserActorId = alphaUserPerson?.actor_id; if (!alphaUserActorId) { @@ -533,7 +534,7 @@ test("Enforce site ban federation for federated user", async () => { // create a test user let alphaUserHttp = await registerUser(alpha, alphaUrl); - let alphaUserPerson = (await getSite(alphaUserHttp)).my_user?.local_user_view + let alphaUserPerson = (await getMyUser(alphaUserHttp)).local_user_view .person; let alphaUserActorId = alphaUserPerson?.actor_id; if (!alphaUserActorId) { @@ -564,7 +565,7 @@ test("Enforce site ban federation for federated user", async () => { expect(banAlphaOnBeta.banned).toBe(true); // The beta site ban should NOT be federated to alpha - let alphaPerson2 = (await getSite(alphaUserHttp)).my_user!.local_user_view + let alphaPerson2 = (await getMyUser(alphaUserHttp)).local_user_view .person; expect(alphaPerson2.banned).toBe(false); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 0b0a9862c..f7b0acd5e 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -17,6 +17,7 @@ import { LemmyHttp, ListCommunityPendingFollows, ListCommunityPendingFollowsResponse, + MyUserInfo, PersonId, PostView, PrivateMessageReportResponse, @@ -757,6 +758,10 @@ export async function getSite(api: LemmyHttp): Promise { return api.getSite(); } +export async function getMyUser(api: LemmyHttp): Promise { + return api.getMyUser(); +} + export async function listPrivateMessages( api: LemmyHttp, ): Promise { @@ -768,17 +773,16 @@ export async function listPrivateMessages( export async function unfollowRemotes( api: LemmyHttp, -): Promise { +): Promise { // Unfollow all remote communities - let site = await getSite(api); + let my_user = await getMyUser(api); let remoteFollowed = - site.my_user?.follows.filter(c => c.community.local == false) ?? []; + my_user.follows.filter(c => c.community.local == false) ?? []; await Promise.all( remoteFollowed.map(cu => followCommunity(api, false, cu.community.id)), ); - let siteRes = await getSite(api); - return siteRes; + return await getMyUser(api); } export async function followBeta(api: LemmyHttp): Promise { diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 2edcf54ea..944764ef1 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -22,6 +22,7 @@ import { alphaImage, unfollows, saveUserSettingsBio, + getMyUser, } from "./shared"; import { LemmyHttp, SaveUserSettings, UploadImage } from "lemmy-js-client"; import { GetPosts } from "lemmy-js-client/dist/types/GetPosts"; @@ -44,12 +45,9 @@ function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) { test("Create user", async () => { let user = await registerUser(alpha, alphaUrl); - let site = await getSite(user); - expect(site.my_user).toBeDefined(); - if (!site.my_user) { - throw "Missing site user"; - } - apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`; + let my_user = await getMyUser(user); + expect(my_user).toBeDefined(); + apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`; }); test("Set some user settings, check that they are federated", async () => { @@ -64,8 +62,8 @@ test("Set some user settings, check that they are federated", async () => { }; await saveUserSettings(beta, form); - let site = await getSite(beta); - expect(site.my_user?.local_user_view.local_user.theme).toBe("test"); + let my_user = await getMyUser(beta); + expect(my_user.local_user_view.local_user.theme).toBe("test"); }); test("Delete user", async () => { @@ -121,8 +119,9 @@ test("Requests with invalid auth should be treated as unauthenticated", async () headers: { Authorization: "Bearer foobar" }, fetchFunction, }); + let my_user = await getMyUser(invalid_auth); + expect(my_user).toBeUndefined(); let site = await getSite(invalid_auth); - expect(site.my_user).toBeUndefined(); expect(site.site_view).toBeDefined(); let form: GetPosts = {}; @@ -137,12 +136,9 @@ test("Create user with Arabic name", async () => { "تجريب" + Math.random().toString().slice(2, 10), // less than actor_name_max_length ); - let site = await getSite(user); - expect(site.my_user).toBeDefined(); - if (!site.my_user) { - throw "Missing site user"; - } - apShortname = `${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`; + let my_user = await getMyUser(user); + expect(my_user).toBeDefined(); + apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`; let alphaPerson = (await resolvePerson(alpha, apShortname)).person; expect(alphaPerson).toBeDefined(); @@ -155,13 +151,14 @@ test("Create user with accept-language", async () => { }); let user = await registerUser(lemmy_http, alphaUrl); - let site = await getSite(user); - expect(site.my_user).toBeDefined(); - expect(site.my_user?.local_user_view.local_user.interface_language).toBe( + let my_user = await getMyUser(user); + expect(my_user).toBeDefined(); + expect(my_user?.local_user_view.local_user.interface_language).toBe( "fr", ); + let site = await getSite(user); let langs = site.all_languages - .filter(a => site.my_user?.discussion_languages.includes(a.id)) + .filter(a => my_user.discussion_languages.includes(a.id)) .map(l => l.code); // should have languages from accept header, as well as "undetermined" // which is automatically enabled by backend @@ -207,8 +204,8 @@ test("Set a new avatar, old avatar is deleted", async () => { // Now try to save a user settings, with the icon missing, // and make sure it doesn't clear the data, or delete the image await saveUserSettingsBio(alpha); - let site = await getSite(alpha); - expect(site.my_user?.local_user_view.person.avatar).toBe(upload2.url); + let my_user = await getMyUser(alpha); + expect(my_user.local_user_view.person.avatar).toBe(upload2.url); // make sure only the new avatar is kept const listMediaRes4 = await alphaImage.listMedia(); diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 68aedc49e..84d5c4e34 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -448,7 +448,7 @@ pub struct GetSiteResponse { pub site_view: SiteView, pub admins: Vec, pub version: String, - #[cfg_attr(feature = "full", ts(optional))] + #[cfg_attr(feature = "full", ts(skip))] pub my_user: Option, pub all_languages: Vec, pub discussion_languages: Vec,