]> Untitled Git - lemmy.git/blobdiff - api_tests/src/shared.ts
Revert "Add pending, and change use specific API response for FollowCommunity…" ...
[lemmy.git] / api_tests / src / shared.ts
index 8c7a793313d92d50b4c0c905b495734b1dc2f951..d5be61ac3f66e4164fd05cd780a5a01838170378 100644 (file)
@@ -49,6 +49,16 @@ import {
   CreatePrivateMessage,
   ResolveObjectResponse,
   ResolveObject,
+  CreatePostReport,
+  ListPostReports,
+  PostReportResponse,
+  ListPostReportsResponse,
+  CreateCommentReport,
+  CommentReportResponse,
+  ListCommentReports,
+  ListCommentReportsResponse,
+  DeleteAccount,
+  DeleteAccountResponse
 } from 'lemmy-js-client';
 
 export interface API {
@@ -57,23 +67,23 @@ export interface API {
 }
 
 export let alpha: API = {
-  client: new LemmyHttp('http://localhost:8541'),
+  client: new LemmyHttp('http://127.0.0.1:8541'),
 };
 
 export let beta: API = {
-  client: new LemmyHttp('http://localhost:8551'),
+  client: new LemmyHttp('http://127.0.0.1:8551'),
 };
 
 export let gamma: API = {
-  client: new LemmyHttp('http://localhost:8561'),
+  client: new LemmyHttp('http://127.0.0.1:8561'),
 };
 
 export let delta: API = {
-  client: new LemmyHttp('http://localhost:8571'),
+  client: new LemmyHttp('http://127.0.0.1:8571'),
 };
 
 export let epsilon: API = {
-  client: new LemmyHttp('http://localhost:8581'),
+  client: new LemmyHttp('http://127.0.0.1:8581'),
 };
 
 const password = 'lemmylemmy'
@@ -122,6 +132,13 @@ export async function setupLogins() {
   gamma.auth = res[2].jwt;
   delta.auth = res[3].jwt;
   epsilon.auth = res[4].jwt;
+
+  // regstration applications are now enabled by default, need to disable them
+  await alpha.client.editSite({ require_application: false, auth: alpha.auth});
+  await beta.client.editSite({ require_application: false, auth: beta.auth});
+  await gamma.client.editSite({ require_application: false, auth: gamma.auth});
+  await delta.client.editSite({ require_application: false, auth: delta.auth});
+  await epsilon.client.editSite({ require_application: false, auth: epsilon.auth});
 }
 
 export async function createPost(
@@ -280,13 +297,14 @@ export async function resolvePerson(
 export async function banPersonFromSite(
   api: API,
   person_id: number,
-  ban: boolean
+  ban: boolean,
+  remove_data: boolean,
 ): Promise<BanPersonResponse> {
   // Make sure lemmy-beta/c/main is cached on lemmy_alpha
   let form: BanPerson = {
     person_id,
     ban,
-    remove_data: false,
+    remove_data,
     auth: api.auth,
   };
   return api.client.banPerson(form);
@@ -296,13 +314,13 @@ export async function banPersonFromCommunity(
   api: API,
   person_id: number,
   community_id: number,
+  remove_data: boolean,
   ban: boolean
 ): Promise<BanFromCommunityResponse> {
-  // Make sure lemmy-beta/c/main is cached on lemmy_alpha
   let form: BanFromCommunity = {
     person_id,
     community_id,
-    remove_data: false,
+    remove_data,
     ban,
     auth: api.auth,
   };
@@ -417,14 +435,10 @@ export async function createCommunity(
   name_: string = randomString(5)
 ): Promise<CommunityResponse> {
   let description = 'a sample description';
-  let icon = 'https://image.flaticon.com/icons/png/512/35/35896.png';
-  let banner = 'https://image.flaticon.com/icons/png/512/35/35896.png';
   let form: CreateCommunity = {
     name: name_,
     title: name_,
     description,
-    icon,
-    banner,
     nsfw: false,
     auth: api.auth,
   };
@@ -543,6 +557,16 @@ export async function saveUserSettings(
   return api.client.saveUserSettings(form);
 }
 
+export async function deleteUser(
+  api: API,
+): Promise<DeleteAccountResponse> {
+  let form: DeleteAccount = {
+    auth: api.auth,
+    password
+  };
+  return api.client.deleteAccount(form);
+}
+
 export async function getSite(
   api: API
 ): Promise<GetSiteResponse> {
@@ -586,6 +610,46 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
   }
 }
 
+export async function reportPost(
+  api: API,
+  post_id: number,
+  reason: string,
+): Promise<PostReportResponse> {
+  let form: CreatePostReport = {
+    post_id,
+    reason,
+    auth: api.auth,
+  };
+  return api.client.createPostReport(form);
+}
+
+export async function listPostReports(api: API): Promise<ListPostReportsResponse> {
+  let form: ListPostReports = {
+    auth: api.auth,
+  };
+  return api.client.listPostReports(form);
+}
+
+export async function reportComment(
+  api: API,
+  comment_id: number,
+  reason: string,
+): Promise<CommentReportResponse> {
+  let form: CreateCommentReport = {
+    comment_id,
+    reason,
+    auth: api.auth,
+  };
+  return api.client.createCommentReport(form);
+}
+
+export async function listCommentReports(api: API): Promise<ListCommentReportsResponse> {
+  let form: ListCommentReports = {
+    auth: api.auth,
+  };
+  return api.client.listCommentReports(form);
+}
+
 export function delay(millis: number = 500) {
   return new Promise(resolve => setTimeout(resolve, millis));
 }
@@ -598,12 +662,19 @@ export function wrapper(form: any): string {
   return JSON.stringify(form);
 }
 
-function randomString(length: number): string {
+export function randomString(length: number): string {
   var result = '';
-  var characters = 'abcdefghijklmnopqrstuvwxyz0123456789_';
+  var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
   var charactersLength = characters.length;
   for (var i = 0; i < length; i++) {
     result += characters.charAt(Math.floor(Math.random() * charactersLength));
   }
   return result;
 }
+
+export async function unfollows() {
+  await unfollowRemotes(alpha);
+  await unfollowRemotes(gamma);
+  await unfollowRemotes(delta);
+  await unfollowRemotes(epsilon);
+}