35 PrivateMessageResponse,
36 PrivateMessagesResponse,
37 GetPersonMentionsResponse,
47 BanFromCommunityResponse,
50 ResolveObjectResponse,
56 ListPostReportsResponse,
58 CommentReportResponse,
60 ListCommentReportsResponse,
62 } from 'lemmy-js-client';
64 export interface API {
69 export let alpha: API = {
70 client: new LemmyHttp('http://127.0.0.1:8541'),
73 export let beta: API = {
74 client: new LemmyHttp('http://127.0.0.1:8551'),
77 export let gamma: API = {
78 client: new LemmyHttp('http://127.0.0.1:8561'),
81 export let delta: API = {
82 client: new LemmyHttp('http://127.0.0.1:8571'),
85 export let epsilon: API = {
86 client: new LemmyHttp('http://127.0.0.1:8581'),
89 const password = 'lemmylemmy'
91 export async function setupLogins() {
92 let formAlpha: Login = {
93 username_or_email: 'lemmy_alpha',
96 let resAlpha = alpha.client.login(formAlpha);
99 username_or_email: 'lemmy_beta',
102 let resBeta = beta.client.login(formBeta);
105 username_or_email: 'lemmy_gamma',
108 let resGamma = gamma.client.login(formGamma);
111 username_or_email: 'lemmy_delta',
114 let resDelta = delta.client.login(formDelta);
117 username_or_email: 'lemmy_epsilon',
120 let resEpsilon = epsilon.client.login(formEpsilon);
122 let res = await Promise.all([
130 alpha.auth = res[0].jwt;
131 beta.auth = res[1].jwt;
132 gamma.auth = res[2].jwt;
133 delta.auth = res[3].jwt;
134 epsilon.auth = res[4].jwt;
137 export async function createPost(
140 ): Promise<PostResponse> {
141 let name = randomString(5);
142 let body = randomString(10);
143 let url = 'https://google.com/';
144 let form: CreatePost = {
152 return api.client.createPost(form);
155 export async function editPost(api: API, post: Post): Promise<PostResponse> {
156 let name = 'A jest test federated post, updated';
157 let form: EditPost = {
163 return api.client.editPost(form);
166 export async function deletePost(
170 ): Promise<PostResponse> {
171 let form: DeletePost = {
176 return api.client.deletePost(form);
179 export async function removePost(
183 ): Promise<PostResponse> {
184 let form: RemovePost = {
189 return api.client.removePost(form);
192 export async function stickyPost(
196 ): Promise<PostResponse> {
197 let form: StickyPost = {
202 return api.client.stickyPost(form);
205 export async function lockPost(
209 ): Promise<PostResponse> {
210 let form: LockPost = {
215 return api.client.lockPost(form);
218 export async function resolvePost(
221 ): Promise<ResolveObjectResponse> {
222 let form: ResolveObject = {
225 return api.client.resolveObject(form);
228 export async function searchPostLocal(
231 ): Promise<SearchResponse> {
234 type_: SearchType.Posts,
235 sort: SortType.TopAll,
237 return api.client.search(form);
240 export async function getPost(
243 ): Promise<GetPostResponse> {
244 let form: GetPost = {
247 return api.client.getPost(form);
250 export async function resolveComment(
253 ): Promise<ResolveObjectResponse> {
254 let form: ResolveObject = {
257 return api.client.resolveObject(form);
260 export async function resolveBetaCommunity(
262 ): Promise<ResolveObjectResponse> {
263 // Use short-hand search url
264 let form: ResolveObject = {
265 q: '!main@lemmy-beta:8551',
267 return api.client.resolveObject(form);
270 export async function resolveCommunity(
273 ): Promise<ResolveObjectResponse> {
274 let form: ResolveObject = {
277 return api.client.resolveObject(form);
280 export async function resolvePerson(
283 ): Promise<ResolveObjectResponse> {
284 let form: ResolveObject = {
287 return api.client.resolveObject(form);
290 export async function banPersonFromSite(
294 remove_data: boolean,
295 ): Promise<BanPersonResponse> {
296 // Make sure lemmy-beta/c/main is cached on lemmy_alpha
297 let form: BanPerson = {
303 return api.client.banPerson(form);
306 export async function banPersonFromCommunity(
309 community_id: number,
310 remove_data: boolean,
312 ): Promise<BanFromCommunityResponse> {
313 let form: BanFromCommunity = {
320 return api.client.banFromCommunity(form);
323 export async function followCommunity(
327 ): Promise<CommunityResponse> {
328 let form: FollowCommunity = {
333 return api.client.followCommunity(form);
336 export async function likePost(
340 ): Promise<PostResponse> {
341 let form: CreatePostLike = {
347 return api.client.likePost(form);
350 export async function createComment(
354 content = 'a jest test comment'
355 ): Promise<CommentResponse> {
356 let form: CreateComment = {
362 return api.client.createComment(form);
365 export async function editComment(
368 content = 'A jest test federated comment update'
369 ): Promise<CommentResponse> {
370 let form: EditComment = {
375 return api.client.editComment(form);
378 export async function deleteComment(
382 ): Promise<CommentResponse> {
383 let form: DeleteComment = {
388 return api.client.deleteComment(form);
391 export async function removeComment(
395 ): Promise<CommentResponse> {
396 let form: RemoveComment = {
401 return api.client.removeComment(form);
404 export async function getMentions(api: API): Promise<GetPersonMentionsResponse> {
405 let form: GetPersonMentions = {
410 return api.client.getPersonMentions(form);
413 export async function likeComment(
417 ): Promise<CommentResponse> {
418 let form: CreateCommentLike = {
419 comment_id: comment.id,
423 return api.client.likeComment(form);
426 export async function createCommunity(
428 name_: string = randomString(5)
429 ): Promise<CommunityResponse> {
430 let description = 'a sample description';
431 let form: CreateCommunity = {
438 return api.client.createCommunity(form);
441 export async function getCommunity(
444 ): Promise<CommunityResponse> {
445 let form: GetCommunity = {
448 return api.client.getCommunity(form);
451 export async function deleteCommunity(
455 ): Promise<CommunityResponse> {
456 let form: DeleteCommunity = {
461 return api.client.deleteCommunity(form);
464 export async function removeCommunity(
468 ): Promise<CommunityResponse> {
469 let form: RemoveCommunity = {
474 return api.client.removeCommunity(form);
477 export async function createPrivateMessage(
480 ): Promise<PrivateMessageResponse> {
481 let content = 'A jest test federated private message';
482 let form: CreatePrivateMessage = {
487 return api.client.createPrivateMessage(form);
490 export async function editPrivateMessage(
492 private_message_id: number
493 ): Promise<PrivateMessageResponse> {
494 let updatedContent = 'A jest test federated private message edited';
495 let form: EditPrivateMessage = {
496 content: updatedContent,
500 return api.client.editPrivateMessage(form);
503 export async function deletePrivateMessage(
506 private_message_id: number
507 ): Promise<PrivateMessageResponse> {
508 let form: DeletePrivateMessage = {
513 return api.client.deletePrivateMessage(form);
516 export async function registerUser(
518 username: string = randomString(5)
519 ): Promise<LoginResponse> {
520 let form: Register = {
523 password_verify: password,
526 return api.client.register(form);
529 export async function saveUserSettingsBio(
531 ): Promise<LoginResponse> {
532 let form: SaveUserSettings = {
535 default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
536 default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
539 send_notifications_to_email: false,
540 bio: 'a changed bio',
543 return saveUserSettings(api, form);
546 export async function saveUserSettings(
548 form: SaveUserSettings
549 ): Promise<LoginResponse> {
550 return api.client.saveUserSettings(form);
553 export async function deleteUser(
555 ): Promise<LoginResponse> {
556 let form: DeleteAccount = {
560 return api.client.deleteAccount(form);
563 export async function getSite(
565 ): Promise<GetSiteResponse> {
566 let form: GetSite = {
569 return api.client.getSite(form);
572 export async function listPrivateMessages(
574 ): Promise<PrivateMessagesResponse> {
575 let form: GetPrivateMessages = {
580 return api.client.getPrivateMessages(form);
583 export async function unfollowRemotes(
585 ): Promise<GetSiteResponse> {
586 // Unfollow all remote communities
587 let site = await getSite(api);
588 let remoteFollowed = site.my_user.follows.filter(
589 c => c.community.local == false
591 for (let cu of remoteFollowed) {
592 await followCommunity(api, false, cu.community.id);
594 let siteRes = await getSite(api);
598 export async function followBeta(api: API): Promise<CommunityResponse> {
599 let betaCommunity = (await resolveBetaCommunity(api)).community;
601 let follow = await followCommunity(api, true, betaCommunity.community.id);
606 export async function reportPost(
610 ): Promise<PostReportResponse> {
611 let form: CreatePostReport = {
616 return api.client.createPostReport(form);
619 export async function listPostReports(api: API): Promise<ListPostReportsResponse> {
620 let form: ListPostReports = {
623 return api.client.listPostReports(form);
626 export async function reportComment(
630 ): Promise<CommentReportResponse> {
631 let form: CreateCommentReport = {
636 return api.client.createCommentReport(form);
639 export async function listCommentReports(api: API): Promise<ListCommentReportsResponse> {
640 let form: ListCommentReports = {
643 return api.client.listCommentReports(form);
646 export function delay(millis: number = 500) {
647 return new Promise(resolve => setTimeout(resolve, millis));
650 export function longDelay() {
654 export function wrapper(form: any): string {
655 return JSON.stringify(form);
658 export function randomString(length: number): string {
660 var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
661 var charactersLength = characters.length;
662 for (var i = 0; i < length; i++) {
663 result += characters.charAt(Math.floor(Math.random() * charactersLength));
668 export async function unfollows() {
669 await unfollowRemotes(alpha);
670 await unfollowRemotes(gamma);
671 await unfollowRemotes(delta);
672 await unfollowRemotes(epsilon);