]> Untitled Git - lemmy.git/blobdiff - api_tests/src/shared.ts
UI Settings - Blur NSFW & Auto Expand (#3377)
[lemmy.git] / api_tests / src / shared.ts
index b8e97db0d37215979e29c3c33271674bd433bc33..e4306c94c0de6d94b22b83987aa0ffea7e1d64a8 100644 (file)
@@ -1,71 +1,65 @@
-import {
-  Login,
-  LoginResponse,
-  CreatePost,
-  EditPost,
-  CreateComment,
-  DeletePost,
-  RemovePost,
-  LockPost,
-  PostResponse,
-  SearchResponse,
-  FollowCommunity,
-  CommunityResponse,
-  GetPostResponse,
-  Register,
-  Comment,
-  EditComment,
-  DeleteComment,
-  RemoveComment,
-  Search,
-  CommentResponse,
-  GetCommunity,
-  CreateCommunity,
-  DeleteCommunity,
-  RemoveCommunity,
-  GetPersonMentions,
-  CreateCommentLike,
-  CreatePostLike,
-  EditPrivateMessage,
-  DeletePrivateMessage,
-  GetPrivateMessages,
-  GetSite,
-  GetPost,
-  PrivateMessageResponse,
-  PrivateMessagesResponse,
-  GetPersonMentionsResponse,
-  SaveUserSettings,
-  SortType,
-  ListingType,
-  GetSiteResponse,
-  SearchType,
-  LemmyHttp,
-  BanPersonResponse,
-  BanPerson,
-  BanFromCommunity,
-  BanFromCommunityResponse,
-  Post,
-  CreatePrivateMessage,
-  ResolveObjectResponse,
-  ResolveObject,
-  CreatePostReport,
-  ListPostReports,
-  PostReportResponse,
-  ListPostReportsResponse,
-  CreateCommentReport,
-  CommentReportResponse,
-  ListCommentReports,
-  ListCommentReportsResponse,
-  DeleteAccount,
-  DeleteAccountResponse,
-  EditSite,
-  CommentSortType,
-  GetComments,
-  GetCommentsResponse,
-  FeaturePost,
-  PostFeatureType,
-  RegistrationMode,
-} from "lemmy-js-client";
+import { LemmyHttp } from "lemmy-js-client";
+import { CreatePost } from "lemmy-js-client/dist/types/CreatePost";
+import { DeletePost } from "lemmy-js-client/dist/types/DeletePost";
+import { EditPost } from "lemmy-js-client/dist/types/EditPost";
+import { EditSite } from "lemmy-js-client/dist/types/EditSite";
+import { FeaturePost } from "lemmy-js-client/dist/types/FeaturePost";
+import { GetComments } from "lemmy-js-client/dist/types/GetComments";
+import { GetCommentsResponse } from "lemmy-js-client/dist/types/GetCommentsResponse";
+import { GetPost } from "lemmy-js-client/dist/types/GetPost";
+import { GetPostResponse } from "lemmy-js-client/dist/types/GetPostResponse";
+import { LockPost } from "lemmy-js-client/dist/types/LockPost";
+import { Login } from "lemmy-js-client/dist/types/Login";
+import { Post } from "lemmy-js-client/dist/types/Post";
+import { PostResponse } from "lemmy-js-client/dist/types/PostResponse";
+import { RemovePost } from "lemmy-js-client/dist/types/RemovePost";
+import { ResolveObject } from "lemmy-js-client/dist/types/ResolveObject";
+import { ResolveObjectResponse } from "lemmy-js-client/dist/types/ResolveObjectResponse";
+import { Search } from "lemmy-js-client/dist/types/Search";
+import { SearchResponse } from "lemmy-js-client/dist/types/SearchResponse";
+import { Comment } from "lemmy-js-client/dist/types/Comment";
+import { BanPersonResponse } from "lemmy-js-client/dist/types/BanPersonResponse";
+import { BanPerson } from "lemmy-js-client/dist/types/BanPerson";
+import { BanFromCommunityResponse } from "lemmy-js-client/dist/types/BanFromCommunityResponse";
+import { BanFromCommunity } from "lemmy-js-client/dist/types/BanFromCommunity";
+import { CommunityResponse } from "lemmy-js-client/dist/types/CommunityResponse";
+import { FollowCommunity } from "lemmy-js-client/dist/types/FollowCommunity";
+import { CreatePostLike } from "lemmy-js-client/dist/types/CreatePostLike";
+import { CommentResponse } from "lemmy-js-client/dist/types/CommentResponse";
+import { CreateComment } from "lemmy-js-client/dist/types/CreateComment";
+import { EditComment } from "lemmy-js-client/dist/types/EditComment";
+import { DeleteComment } from "lemmy-js-client/dist/types/DeleteComment";
+import { RemoveComment } from "lemmy-js-client/dist/types/RemoveComment";
+import { GetPersonMentionsResponse } from "lemmy-js-client/dist/types/GetPersonMentionsResponse";
+import { GetPersonMentions } from "lemmy-js-client/dist/types/GetPersonMentions";
+import { CreateCommentLike } from "lemmy-js-client/dist/types/CreateCommentLike";
+import { CreateCommunity } from "lemmy-js-client/dist/types/CreateCommunity";
+import { GetCommunity } from "lemmy-js-client/dist/types/GetCommunity";
+import { DeleteCommunity } from "lemmy-js-client/dist/types/DeleteCommunity";
+import { RemoveCommunity } from "lemmy-js-client/dist/types/RemoveCommunity";
+import { PrivateMessageResponse } from "lemmy-js-client/dist/types/PrivateMessageResponse";
+import { CreatePrivateMessage } from "lemmy-js-client/dist/types/CreatePrivateMessage";
+import { EditPrivateMessage } from "lemmy-js-client/dist/types/EditPrivateMessage";
+import { DeletePrivateMessage } from "lemmy-js-client/dist/types/DeletePrivateMessage";
+import { LoginResponse } from "lemmy-js-client/dist/types/LoginResponse";
+import { Register } from "lemmy-js-client/dist/types/Register";
+import { SaveUserSettings } from "lemmy-js-client/dist/types/SaveUserSettings";
+import { DeleteAccount } from "lemmy-js-client/dist/types/DeleteAccount";
+import { GetSiteResponse } from "lemmy-js-client/dist/types/GetSiteResponse";
+import { DeleteAccountResponse } from "lemmy-js-client/dist/types/DeleteAccountResponse";
+import { GetSite } from "lemmy-js-client/dist/types/GetSite";
+import { PrivateMessagesResponse } from "lemmy-js-client/dist/types/PrivateMessagesResponse";
+import { GetPrivateMessages } from "lemmy-js-client/dist/types/GetPrivateMessages";
+import { PostReportResponse } from "lemmy-js-client/dist/types/PostReportResponse";
+import { CreatePostReport } from "lemmy-js-client/dist/types/CreatePostReport";
+import { ListPostReportsResponse } from "lemmy-js-client/dist/types/ListPostReportsResponse";
+import { ListPostReports } from "lemmy-js-client/dist/types/ListPostReports";
+import { CommentReportResponse } from "lemmy-js-client/dist/types/CommentReportResponse";
+import { CreateCommentReport } from "lemmy-js-client/dist/types/CreateCommentReport";
+import { ListCommentReportsResponse } from "lemmy-js-client/dist/types/ListCommentReportsResponse";
+import { ListCommentReports } from "lemmy-js-client/dist/types/ListCommentReports";
+import { GetPersonDetailsResponse } from "lemmy-js-client/dist/types/GetPersonDetailsResponse";
+import { GetPersonDetails } from "lemmy-js-client/dist/types/GetPersonDetails";
 
 export interface API {
   client: LemmyHttp;
@@ -146,7 +140,7 @@ export async function setupLogins() {
 
   // Registration applications are now enabled by default, need to disable them
   let editSiteForm: EditSite = {
-    registration_mode: RegistrationMode.Open,
+    registration_mode: "Open",
     rate_limit_message: 999,
     rate_limit_post: 999,
     rate_limit_register: 999,
@@ -194,13 +188,16 @@ export async function setupLogins() {
   await epsilon.client.editSite(editSiteForm);
 
   // Create the main alpha/beta communities
-  await createCommunity(alpha, "main");
-  await createCommunity(beta, "main");
+  // Ignore thrown errors of duplicates
+  try {
+    await createCommunity(alpha, "main");
+    await createCommunity(beta, "main");
+  } catch (_) {}
 }
 
 export async function createPost(
   api: API,
-  community_id: number
+  community_id: number,
 ): Promise<PostResponse> {
   let name = randomString(5);
   let body = randomString(10);
@@ -228,7 +225,7 @@ export async function editPost(api: API, post: Post): Promise<PostResponse> {
 export async function deletePost(
   api: API,
   deleted: boolean,
-  post: Post
+  post: Post,
 ): Promise<PostResponse> {
   let form: DeletePost = {
     post_id: post.id,
@@ -241,7 +238,7 @@ export async function deletePost(
 export async function removePost(
   api: API,
   removed: boolean,
-  post: Post
+  post: Post,
 ): Promise<PostResponse> {
   let form: RemovePost = {
     post_id: post.id,
@@ -254,12 +251,12 @@ export async function removePost(
 export async function featurePost(
   api: API,
   featured: boolean,
-  post: Post
+  post: Post,
 ): Promise<PostResponse> {
   let form: FeaturePost = {
     post_id: post.id,
     featured,
-    feature_type: PostFeatureType.Community,
+    feature_type: "Community",
     auth: api.auth,
   };
   return api.client.featurePost(form);
@@ -268,7 +265,7 @@ export async function featurePost(
 export async function lockPost(
   api: API,
   locked: boolean,
-  post: Post
+  post: Post,
 ): Promise<PostResponse> {
   let form: LockPost = {
     post_id: post.id,
@@ -280,7 +277,7 @@ export async function lockPost(
 
 export async function resolvePost(
   api: API,
-  post: Post
+  post: Post,
 ): Promise<ResolveObjectResponse> {
   let form: ResolveObject = {
     q: post.ap_id,
@@ -291,12 +288,12 @@ export async function resolvePost(
 
 export async function searchPostLocal(
   api: API,
-  post: Post
+  post: Post,
 ): Promise<SearchResponse> {
   let form: Search = {
     q: post.name,
-    type_: SearchType.Posts,
-    sort: SortType.TopAll,
+    type_: "Posts",
+    sort: "TopAll",
     auth: api.auth,
   };
   return api.client.search(form);
@@ -304,7 +301,7 @@ export async function searchPostLocal(
 
 export async function getPost(
   api: API,
-  post_id: number
+  post_id: number,
 ): Promise<GetPostResponse> {
   let form: GetPost = {
     id: post_id,
@@ -315,12 +312,12 @@ export async function getPost(
 
 export async function getComments(
   api: API,
-  post_id: number
+  post_id: number,
 ): Promise<GetCommentsResponse> {
   let form: GetComments = {
     post_id: post_id,
-    type_: ListingType.All,
-    sort: CommentSortType.New,
+    type_: "All",
+    sort: "New",
     auth: api.auth,
   };
   return api.client.getComments(form);
@@ -328,7 +325,7 @@ export async function getComments(
 
 export async function resolveComment(
   api: API,
-  comment: Comment
+  comment: Comment,
 ): Promise<ResolveObjectResponse> {
   let form: ResolveObject = {
     q: comment.ap_id,
@@ -338,7 +335,7 @@ export async function resolveComment(
 }
 
 export async function resolveBetaCommunity(
-  api: API
+  api: API,
 ): Promise<ResolveObjectResponse> {
   // Use short-hand search url
   let form: ResolveObject = {
@@ -350,7 +347,7 @@ export async function resolveBetaCommunity(
 
 export async function resolveCommunity(
   api: API,
-  q: string
+  q: string,
 ): Promise<ResolveObjectResponse> {
   let form: ResolveObject = {
     q,
@@ -361,7 +358,7 @@ export async function resolveCommunity(
 
 export async function resolvePerson(
   api: API,
-  apShortname: string
+  apShortname: string,
 ): Promise<ResolveObjectResponse> {
   let form: ResolveObject = {
     q: apShortname,
@@ -374,7 +371,7 @@ export async function banPersonFromSite(
   api: API,
   person_id: number,
   ban: boolean,
-  remove_data: boolean
+  remove_data: boolean,
 ): Promise<BanPersonResponse> {
   // Make sure lemmy-beta/c/main is cached on lemmy_alpha
   let form: BanPerson = {
@@ -391,7 +388,7 @@ export async function banPersonFromCommunity(
   person_id: number,
   community_id: number,
   remove_data: boolean,
-  ban: boolean
+  ban: boolean,
 ): Promise<BanFromCommunityResponse> {
   let form: BanFromCommunity = {
     person_id,
@@ -406,7 +403,7 @@ export async function banPersonFromCommunity(
 export async function followCommunity(
   api: API,
   follow: boolean,
-  community_id: number
+  community_id: number,
 ): Promise<CommunityResponse> {
   let form: FollowCommunity = {
     community_id,
@@ -419,7 +416,7 @@ export async function followCommunity(
 export async function likePost(
   api: API,
   score: number,
-  post: Post
+  post: Post,
 ): Promise<PostResponse> {
   let form: CreatePostLike = {
     post_id: post.id,
@@ -434,7 +431,7 @@ export async function createComment(
   api: API,
   post_id: number,
   parent_id?: number,
-  content = "a jest test comment"
+  content = "a jest test comment",
 ): Promise<CommentResponse> {
   let form: CreateComment = {
     content,
@@ -448,7 +445,7 @@ export async function createComment(
 export async function editComment(
   api: API,
   comment_id: number,
-  content = "A jest test federated comment update"
+  content = "A jest test federated comment update",
 ): Promise<CommentResponse> {
   let form: EditComment = {
     content,
@@ -461,7 +458,7 @@ export async function editComment(
 export async function deleteComment(
   api: API,
   deleted: boolean,
-  comment_id: number
+  comment_id: number,
 ): Promise<CommentResponse> {
   let form: DeleteComment = {
     comment_id,
@@ -474,7 +471,7 @@ export async function deleteComment(
 export async function removeComment(
   api: API,
   removed: boolean,
-  comment_id: number
+  comment_id: number,
 ): Promise<CommentResponse> {
   let form: RemoveComment = {
     comment_id,
@@ -485,10 +482,10 @@ export async function removeComment(
 }
 
 export async function getMentions(
-  api: API
+  api: API,
 ): Promise<GetPersonMentionsResponse> {
   let form: GetPersonMentions = {
-    sort: CommentSortType.New,
+    sort: "New",
     unread_only: false,
     auth: api.auth,
   };
@@ -498,7 +495,7 @@ export async function getMentions(
 export async function likeComment(
   api: API,
   score: number,
-  comment: Comment
+  comment: Comment,
 ): Promise<CommentResponse> {
   let form: CreateCommentLike = {
     comment_id: comment.id,
@@ -510,7 +507,7 @@ export async function likeComment(
 
 export async function createCommunity(
   api: API,
-  name_: string = randomString(5)
+  name_: string = randomString(5),
 ): Promise<CommunityResponse> {
   let description = "a sample description";
   let form: CreateCommunity = {
@@ -524,7 +521,7 @@ export async function createCommunity(
 
 export async function getCommunity(
   api: API,
-  id: number
+  id: number,
 ): Promise<CommunityResponse> {
   let form: GetCommunity = {
     id,
@@ -536,7 +533,7 @@ export async function getCommunity(
 export async function deleteCommunity(
   api: API,
   deleted: boolean,
-  community_id: number
+  community_id: number,
 ): Promise<CommunityResponse> {
   let form: DeleteCommunity = {
     community_id,
@@ -549,7 +546,7 @@ export async function deleteCommunity(
 export async function removeCommunity(
   api: API,
   removed: boolean,
-  community_id: number
+  community_id: number,
 ): Promise<CommunityResponse> {
   let form: RemoveCommunity = {
     community_id,
@@ -561,7 +558,7 @@ export async function removeCommunity(
 
 export async function createPrivateMessage(
   api: API,
-  recipient_id: number
+  recipient_id: number,
 ): Promise<PrivateMessageResponse> {
   let content = "A jest test federated private message";
   let form: CreatePrivateMessage = {
@@ -574,7 +571,7 @@ export async function createPrivateMessage(
 
 export async function editPrivateMessage(
   api: API,
-  private_message_id: number
+  private_message_id: number,
 ): Promise<PrivateMessageResponse> {
   let updatedContent = "A jest test federated private message edited";
   let form: EditPrivateMessage = {
@@ -588,7 +585,7 @@ export async function editPrivateMessage(
 export async function deletePrivateMessage(
   api: API,
   deleted: boolean,
-  private_message_id: number
+  private_message_id: number,
 ): Promise<PrivateMessageResponse> {
   let form: DeletePrivateMessage = {
     deleted,
@@ -600,7 +597,7 @@ export async function deletePrivateMessage(
 
 export async function registerUser(
   api: API,
-  username: string = randomString(5)
+  username: string = randomString(5),
 ): Promise<LoginResponse> {
   let form: Register = {
     username,
@@ -614,9 +611,11 @@ export async function registerUser(
 export async function saveUserSettingsBio(api: API): Promise<LoginResponse> {
   let form: SaveUserSettings = {
     show_nsfw: true,
+    blur_nsfw: false,
+    auto_expand: true,
     theme: "darkly",
-    default_sort_type: SortType.Active,
-    default_listing_type: ListingType.All,
+    default_sort_type: "Active",
+    default_listing_type: "All",
     interface_language: "en",
     show_avatars: true,
     send_notifications_to_email: false,
@@ -627,15 +626,17 @@ export async function saveUserSettingsBio(api: API): Promise<LoginResponse> {
 }
 
 export async function saveUserSettingsFederated(
-  api: API
+  api: API,
 ): Promise<LoginResponse> {
   let avatar = "https://image.flaticon.com/icons/png/512/35/35896.png";
   let banner = "https://image.flaticon.com/icons/png/512/36/35896.png";
   let bio = "a changed bio";
   let form: SaveUserSettings = {
     show_nsfw: false,
-    default_sort_type: SortType.Hot,
-    default_listing_type: ListingType.All,
+    blur_nsfw: true,
+    auto_expand: false,
+    default_sort_type: "Hot",
+    default_listing_type: "All",
     interface_language: "",
     avatar,
     banner,
@@ -650,10 +651,20 @@ export async function saveUserSettingsFederated(
 
 export async function saveUserSettings(
   api: API,
-  form: SaveUserSettings
+  form: SaveUserSettings,
 ): Promise<LoginResponse> {
   return api.client.saveUserSettings(form);
 }
+export async function getPersonDetails(
+  api: API,
+  person_id: number,
+): Promise<GetPersonDetailsResponse> {
+  let form: GetPersonDetails = {
+    auth: api.auth,
+    person_id: person_id,
+  };
+  return api.client.getPersonDetails(form);
+}
 
 export async function deleteUser(api: API): Promise<DeleteAccountResponse> {
   let form: DeleteAccount = {
@@ -671,7 +682,7 @@ export async function getSite(api: API): Promise<GetSiteResponse> {
 }
 
 export async function listPrivateMessages(
-  api: API
+  api: API,
 ): Promise<PrivateMessagesResponse> {
   let form: GetPrivateMessages = {
     auth: api.auth,
@@ -705,7 +716,7 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
 export async function reportPost(
   api: API,
   post_id: number,
-  reason: string
+  reason: string,
 ): Promise<PostReportResponse> {
   let form: CreatePostReport = {
     post_id,
@@ -716,7 +727,7 @@ export async function reportPost(
 }
 
 export async function listPostReports(
-  api: API
+  api: API,
 ): Promise<ListPostReportsResponse> {
   let form: ListPostReports = {
     auth: api.auth,
@@ -727,7 +738,7 @@ export async function listPostReports(
 export async function reportComment(
   api: API,
   comment_id: number,
-  reason: string
+  reason: string,
 ): Promise<CommentReportResponse> {
   let form: CreateCommentReport = {
     comment_id,
@@ -738,7 +749,7 @@ export async function reportComment(
 }
 
 export async function listCommentReports(
-  api: API
+  api: API,
 ): Promise<ListCommentReportsResponse> {
   let form: ListCommentReports = {
     auth: api.auth,