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 form: CreateCommunity = {
437 return api.client.createCommunity(form);
440 export async function getCommunity(
443 ): Promise<CommunityResponse> {
444 let form: GetCommunity = {
447 return api.client.getCommunity(form);
450 export async function deleteCommunity(
454 ): Promise<CommunityResponse> {
455 let form: DeleteCommunity = {
460 return api.client.deleteCommunity(form);
463 export async function removeCommunity(
467 ): Promise<CommunityResponse> {
468 let form: RemoveCommunity = {
473 return api.client.removeCommunity(form);
476 export async function createPrivateMessage(
479 ): Promise<PrivateMessageResponse> {
480 let content = 'A jest test federated private message';
481 let form: CreatePrivateMessage = {
486 return api.client.createPrivateMessage(form);
489 export async function editPrivateMessage(
491 private_message_id: number
492 ): Promise<PrivateMessageResponse> {
493 let updatedContent = 'A jest test federated private message edited';
494 let form: EditPrivateMessage = {
495 content: updatedContent,
499 return api.client.editPrivateMessage(form);
502 export async function deletePrivateMessage(
505 private_message_id: number
506 ): Promise<PrivateMessageResponse> {
507 let form: DeletePrivateMessage = {
512 return api.client.deletePrivateMessage(form);
515 export async function registerUser(
517 username: string = randomString(5)
518 ): Promise<LoginResponse> {
519 let form: Register = {
522 password_verify: password,
525 return api.client.register(form);
528 export async function saveUserSettingsBio(
530 ): Promise<LoginResponse> {
531 let form: SaveUserSettings = {
534 default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
535 default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
538 send_notifications_to_email: false,
539 bio: 'a changed bio',
542 return saveUserSettings(api, form);
545 export async function saveUserSettings(
547 form: SaveUserSettings
548 ): Promise<LoginResponse> {
549 return api.client.saveUserSettings(form);
552 export async function getSite(
554 ): Promise<GetSiteResponse> {
555 let form: GetSite = {
558 return api.client.getSite(form);
561 export async function listPrivateMessages(
563 ): Promise<PrivateMessagesResponse> {
564 let form: GetPrivateMessages = {
569 return api.client.getPrivateMessages(form);
572 export async function unfollowRemotes(
574 ): Promise<GetSiteResponse> {
575 // Unfollow all remote communities
576 let site = await getSite(api);
577 let remoteFollowed = site.my_user.follows.filter(
578 c => c.community.local == false
580 for (let cu of remoteFollowed) {
581 await followCommunity(api, false, cu.community.id);
583 let siteRes = await getSite(api);
587 export async function followBeta(api: API): Promise<CommunityResponse> {
588 let betaCommunity = (await resolveBetaCommunity(api)).community;
590 let follow = await followCommunity(api, true, betaCommunity.community.id);
595 export async function reportPost(
599 ): Promise<PostReportResponse> {
600 let form: CreatePostReport = {
605 return api.client.createPostReport(form);
608 export async function listPostReports(api: API): Promise<ListPostReportsResponse> {
609 let form: ListPostReports = {
612 return api.client.listPostReports(form);
615 export async function reportComment(
619 ): Promise<CommentReportResponse> {
620 let form: CreateCommentReport = {
625 return api.client.createCommentReport(form);
628 export async function listCommentReports(api: API): Promise<ListCommentReportsResponse> {
629 let form: ListCommentReports = {
632 return api.client.listCommentReports(form);
635 export function delay(millis: number = 500) {
636 return new Promise(resolve => setTimeout(resolve, millis));
639 export function longDelay() {
643 export function wrapper(form: any): string {
644 return JSON.stringify(form);
647 export function randomString(length: number): string {
649 var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
650 var charactersLength = characters.length;
651 for (var i = 0; i < length; i++) {
652 result += characters.charAt(Math.floor(Math.random() * charactersLength));
657 export async function unfollows() {
658 await unfollowRemotes(alpha);
659 await unfollowRemotes(gamma);
660 await unfollowRemotes(delta);
661 await unfollowRemotes(epsilon);