35 PrivateMessageResponse,
36 PrivateMessagesResponse,
37 GetPersonMentionsResponse,
47 BanFromCommunityResponse,
50 ResolveObjectResponse,
56 ListPostReportsResponse,
58 CommentReportResponse,
60 ListCommentReportsResponse,
61 } from 'lemmy-js-client';
63 export interface API {
68 export let alpha: API = {
69 client: new LemmyHttp('http://127.0.0.1:8541'),
72 export let beta: API = {
73 client: new LemmyHttp('http://127.0.0.1:8551'),
76 export let gamma: API = {
77 client: new LemmyHttp('http://127.0.0.1:8561'),
80 export let delta: API = {
81 client: new LemmyHttp('http://127.0.0.1:8571'),
84 export let epsilon: API = {
85 client: new LemmyHttp('http://127.0.0.1:8581'),
88 const password = 'lemmylemmy'
90 export async function setupLogins() {
91 let formAlpha: Login = {
92 username_or_email: 'lemmy_alpha',
95 let resAlpha = alpha.client.login(formAlpha);
98 username_or_email: 'lemmy_beta',
101 let resBeta = beta.client.login(formBeta);
104 username_or_email: 'lemmy_gamma',
107 let resGamma = gamma.client.login(formGamma);
110 username_or_email: 'lemmy_delta',
113 let resDelta = delta.client.login(formDelta);
116 username_or_email: 'lemmy_epsilon',
119 let resEpsilon = epsilon.client.login(formEpsilon);
121 let res = await Promise.all([
129 alpha.auth = res[0].jwt;
130 beta.auth = res[1].jwt;
131 gamma.auth = res[2].jwt;
132 delta.auth = res[3].jwt;
133 epsilon.auth = res[4].jwt;
136 export async function createPost(
139 ): Promise<PostResponse> {
140 let name = randomString(5);
141 let body = randomString(10);
142 let url = 'https://google.com/';
143 let form: CreatePost = {
151 return api.client.createPost(form);
154 export async function editPost(api: API, post: Post): Promise<PostResponse> {
155 let name = 'A jest test federated post, updated';
156 let form: EditPost = {
162 return api.client.editPost(form);
165 export async function deletePost(
169 ): Promise<PostResponse> {
170 let form: DeletePost = {
175 return api.client.deletePost(form);
178 export async function removePost(
182 ): Promise<PostResponse> {
183 let form: RemovePost = {
188 return api.client.removePost(form);
191 export async function stickyPost(
195 ): Promise<PostResponse> {
196 let form: StickyPost = {
201 return api.client.stickyPost(form);
204 export async function lockPost(
208 ): Promise<PostResponse> {
209 let form: LockPost = {
214 return api.client.lockPost(form);
217 export async function resolvePost(
220 ): Promise<ResolveObjectResponse> {
221 let form: ResolveObject = {
224 return api.client.resolveObject(form);
227 export async function searchPostLocal(
230 ): Promise<SearchResponse> {
233 type_: SearchType.Posts,
234 sort: SortType.TopAll,
236 return api.client.search(form);
239 export async function getPost(
242 ): Promise<GetPostResponse> {
243 let form: GetPost = {
246 return api.client.getPost(form);
249 export async function resolveComment(
252 ): Promise<ResolveObjectResponse> {
253 let form: ResolveObject = {
256 return api.client.resolveObject(form);
259 export async function resolveBetaCommunity(
261 ): Promise<ResolveObjectResponse> {
262 // Use short-hand search url
263 let form: ResolveObject = {
264 q: '!main@lemmy-beta:8551',
266 return api.client.resolveObject(form);
269 export async function resolveCommunity(
272 ): Promise<ResolveObjectResponse> {
273 let form: ResolveObject = {
276 return api.client.resolveObject(form);
279 export async function resolvePerson(
282 ): Promise<ResolveObjectResponse> {
283 let form: ResolveObject = {
286 return api.client.resolveObject(form);
289 export async function banPersonFromSite(
293 remove_data: boolean,
294 ): Promise<BanPersonResponse> {
295 // Make sure lemmy-beta/c/main is cached on lemmy_alpha
296 let form: BanPerson = {
302 return api.client.banPerson(form);
305 export async function banPersonFromCommunity(
308 community_id: number,
309 remove_data: boolean,
311 ): Promise<BanFromCommunityResponse> {
312 let form: BanFromCommunity = {
319 return api.client.banFromCommunity(form);
322 export async function followCommunity(
326 ): Promise<CommunityResponse> {
327 let form: FollowCommunity = {
332 return api.client.followCommunity(form);
335 export async function likePost(
339 ): Promise<PostResponse> {
340 let form: CreatePostLike = {
346 return api.client.likePost(form);
349 export async function createComment(
353 content = 'a jest test comment'
354 ): Promise<CommentResponse> {
355 let form: CreateComment = {
361 return api.client.createComment(form);
364 export async function editComment(
367 content = 'A jest test federated comment update'
368 ): Promise<CommentResponse> {
369 let form: EditComment = {
374 return api.client.editComment(form);
377 export async function deleteComment(
381 ): Promise<CommentResponse> {
382 let form: DeleteComment = {
387 return api.client.deleteComment(form);
390 export async function removeComment(
394 ): Promise<CommentResponse> {
395 let form: RemoveComment = {
400 return api.client.removeComment(form);
403 export async function getMentions(api: API): Promise<GetPersonMentionsResponse> {
404 let form: GetPersonMentions = {
409 return api.client.getPersonMentions(form);
412 export async function likeComment(
416 ): Promise<CommentResponse> {
417 let form: CreateCommentLike = {
418 comment_id: comment.id,
422 return api.client.likeComment(form);
425 export async function createCommunity(
427 name_: string = randomString(5)
428 ): Promise<CommunityResponse> {
429 let description = 'a sample description';
430 let icon = 'https://image.flaticon.com/icons/png/512/35/35896.png';
431 let banner = 'https://image.flaticon.com/icons/png/512/35/35896.png';
432 let form: CreateCommunity = {
441 return api.client.createCommunity(form);
444 export async function getCommunity(
447 ): Promise<CommunityResponse> {
448 let form: GetCommunity = {
451 return api.client.getCommunity(form);
454 export async function deleteCommunity(
458 ): Promise<CommunityResponse> {
459 let form: DeleteCommunity = {
464 return api.client.deleteCommunity(form);
467 export async function removeCommunity(
471 ): Promise<CommunityResponse> {
472 let form: RemoveCommunity = {
477 return api.client.removeCommunity(form);
480 export async function createPrivateMessage(
483 ): Promise<PrivateMessageResponse> {
484 let content = 'A jest test federated private message';
485 let form: CreatePrivateMessage = {
490 return api.client.createPrivateMessage(form);
493 export async function editPrivateMessage(
495 private_message_id: number
496 ): Promise<PrivateMessageResponse> {
497 let updatedContent = 'A jest test federated private message edited';
498 let form: EditPrivateMessage = {
499 content: updatedContent,
503 return api.client.editPrivateMessage(form);
506 export async function deletePrivateMessage(
509 private_message_id: number
510 ): Promise<PrivateMessageResponse> {
511 let form: DeletePrivateMessage = {
516 return api.client.deletePrivateMessage(form);
519 export async function registerUser(
521 username: string = randomString(5)
522 ): Promise<LoginResponse> {
523 let form: Register = {
526 password_verify: password,
529 return api.client.register(form);
532 export async function saveUserSettingsBio(
534 ): Promise<LoginResponse> {
535 let form: SaveUserSettings = {
538 default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
539 default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
542 send_notifications_to_email: false,
543 bio: 'a changed bio',
546 return saveUserSettings(api, form);
549 export async function saveUserSettings(
551 form: SaveUserSettings
552 ): Promise<LoginResponse> {
553 return api.client.saveUserSettings(form);
556 export async function getSite(
558 ): Promise<GetSiteResponse> {
559 let form: GetSite = {
562 return api.client.getSite(form);
565 export async function listPrivateMessages(
567 ): Promise<PrivateMessagesResponse> {
568 let form: GetPrivateMessages = {
573 return api.client.getPrivateMessages(form);
576 export async function unfollowRemotes(
578 ): Promise<GetSiteResponse> {
579 // Unfollow all remote communities
580 let site = await getSite(api);
581 let remoteFollowed = site.my_user.follows.filter(
582 c => c.community.local == false
584 for (let cu of remoteFollowed) {
585 await followCommunity(api, false, cu.community.id);
587 let siteRes = await getSite(api);
591 export async function followBeta(api: API): Promise<CommunityResponse> {
592 let betaCommunity = (await resolveBetaCommunity(api)).community;
594 let follow = await followCommunity(api, true, betaCommunity.community.id);
599 export async function reportPost(
603 ): Promise<PostReportResponse> {
604 let form: CreatePostReport = {
609 return api.client.createPostReport(form);
612 export async function listPostReports(api: API): Promise<ListPostReportsResponse> {
613 let form: ListPostReports = {
616 return api.client.listPostReports(form);
619 export async function reportComment(
623 ): Promise<CommentReportResponse> {
624 let form: CreateCommentReport = {
629 return api.client.createCommentReport(form);
632 export async function listCommentReports(api: API): Promise<ListCommentReportsResponse> {
633 let form: ListCommentReports = {
636 return api.client.listCommentReports(form);
639 export function delay(millis: number = 500) {
640 return new Promise(resolve => setTimeout(resolve, millis));
643 export function longDelay() {
647 export function wrapper(form: any): string {
648 return JSON.stringify(form);
651 export function randomString(length: number): string {
653 var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
654 var charactersLength = characters.length;
655 for (var i = 0; i < length; i++) {
656 result += characters.charAt(Math.floor(Math.random() * charactersLength));