From 38d048f6e32f770b47876a21f0b872c10372bdce Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 12 Dec 2024 15:23:45 +0100 Subject: [PATCH] More test coverage for user deletion --- api_tests/src/user.spec.ts | 10 ++++++++++ crates/api_crud/src/user/my_user.rs | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index f7f80aecb..d1d6144f5 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -74,6 +74,9 @@ test("Set some user settings, check that they are federated", async () => { test("Delete user", async () => { let user = await registerUser(alpha, alphaUrl); + let user_profile = await getMyUser(user); + let person_id = user_profile.local_user_view.person.id; + let actor_id = user_profile.local_user_view.person.actor_id; // make a local post and comment let alphaCommunity = (await resolveCommunity(user, "main@lemmy-alpha:8541")) @@ -101,6 +104,10 @@ test("Delete user", async () => { expect(remoteComment).toBeDefined(); await deleteUser(user); + await expect(getMyUser(user)).rejects.toStrictEqual(Error("incorrect_login")); + await expect(getPersonDetails(user, person_id)).rejects.toStrictEqual( + Error("not_found"), + ); // check that posts and comments are marked as deleted on other instances. // use get methods to avoid refetching from origin instance @@ -118,6 +125,9 @@ test("Delete user", async () => { (await getComments(alpha, remoteComment.post_id)).comments[0].comment .deleted, ).toBe(true); + await expect( + getPersonDetails(user, remoteComment.creator_id), + ).rejects.toStrictEqual(Error("not_found")); }); test("Requests with invalid auth should be treated as unauthenticated", async () => { diff --git a/crates/api_crud/src/user/my_user.rs b/crates/api_crud/src/user/my_user.rs index 805c9dabb..f7a92eb99 100644 --- a/crates/api_crud/src/user/my_user.rs +++ b/crates/api_crud/src/user/my_user.rs @@ -1,5 +1,5 @@ use actix_web::web::{Data, Json}; -use lemmy_api_common::{context::LemmyContext, site::MyUserInfo}; +use lemmy_api_common::{context::LemmyContext, site::MyUserInfo, utils::check_user_valid}; use lemmy_db_schema::source::{ actor_language::LocalUserLanguage, community_block::CommunityBlock, @@ -15,6 +15,8 @@ pub async fn get_my_user( local_user_view: LocalUserView, context: Data, ) -> LemmyResult> { + check_user_valid(&local_user_view.person)?; + // Build the local user with parallel queries and add it to site response let person_id = local_user_view.person.id; let local_user_id = local_user_view.local_user.id;