import {
- LoginForm,
+ Login,
LoginResponse,
- Post,
- PostForm,
- Comment,
- DeletePostForm,
- RemovePostForm,
- StickyPostForm,
- LockPostForm,
+ CreatePost,
+ EditPost,
+ CreateComment,
+ DeletePost,
+ RemovePost,
+ StickyPost,
+ LockPost,
PostResponse,
SearchResponse,
- FollowCommunityForm,
+ FollowCommunity,
CommunityResponse,
- GetFollowedCommunitiesResponse,
GetPostResponse,
- RegisterForm,
- CommentForm,
- DeleteCommentForm,
- RemoveCommentForm,
- SearchForm,
+ Register,
+ Comment,
+ EditComment,
+ DeleteComment,
+ RemoveComment,
+ Search,
CommentResponse,
- GetCommunityForm,
- CommunityForm,
- DeleteCommunityForm,
- RemoveCommunityForm,
- GetUserMentionsForm,
- CommentLikeForm,
- CreatePostLikeForm,
- PrivateMessageForm,
- EditPrivateMessageForm,
- DeletePrivateMessageForm,
- GetFollowedCommunitiesForm,
- GetPrivateMessagesForm,
- GetSiteForm,
- GetPostForm,
+ GetCommunity,
+ CreateCommunity,
+ DeleteCommunity,
+ RemoveCommunity,
+ GetPersonMentions,
+ CreateCommentLike,
+ CreatePostLike,
+ EditPrivateMessage,
+ DeletePrivateMessage,
+ GetPrivateMessages,
+ GetSite,
+ GetPost,
PrivateMessageResponse,
PrivateMessagesResponse,
- GetUserMentionsResponse,
- UserSettingsForm,
+ GetPersonMentionsResponse,
+ SaveUserSettings,
SortType,
ListingType,
GetSiteResponse,
SearchType,
LemmyHttp,
- BanUserResponse,
- BanUserForm,
- BanFromCommunityForm,
+ BanPersonResponse,
+ BanPerson,
+ BanFromCommunity,
BanFromCommunityResponse,
+ Post,
+ CreatePrivateMessage,
+ ResolveObjectResponse,
+ ResolveObject,
+ CreatePostReport,
+ ListPostReports,
+ PostReportResponse,
+ ListPostReportsResponse,
+ CreateCommentReport,
+ CommentReportResponse,
+ ListCommentReports,
+ ListCommentReportsResponse,
+ DeleteAccount,
+ DeleteAccountResponse
} from 'lemmy-js-client';
export interface API {
}
export let alpha: API = {
- client: new LemmyHttp('http://localhost:8541/api/v1'),
+ client: new LemmyHttp('http://127.0.0.1:8541'),
};
export let beta: API = {
- client: new LemmyHttp('http://localhost:8551/api/v1'),
+ client: new LemmyHttp('http://127.0.0.1:8551'),
};
export let gamma: API = {
- client: new LemmyHttp('http://localhost:8561/api/v1'),
+ client: new LemmyHttp('http://127.0.0.1:8561'),
};
export let delta: API = {
- client: new LemmyHttp('http://localhost:8571/api/v1'),
+ client: new LemmyHttp('http://127.0.0.1:8571'),
};
export let epsilon: API = {
- client: new LemmyHttp('http://localhost:8581/api/v1'),
+ client: new LemmyHttp('http://127.0.0.1:8581'),
};
+const password = 'lemmylemmy'
+
export async function setupLogins() {
- let formAlpha: LoginForm = {
+ let formAlpha: Login = {
username_or_email: 'lemmy_alpha',
- password: 'lemmy',
+ password,
};
let resAlpha = alpha.client.login(formAlpha);
let formBeta = {
username_or_email: 'lemmy_beta',
- password: 'lemmy',
+ password,
};
let resBeta = beta.client.login(formBeta);
let formGamma = {
username_or_email: 'lemmy_gamma',
- password: 'lemmy',
+ password,
};
let resGamma = gamma.client.login(formGamma);
let formDelta = {
username_or_email: 'lemmy_delta',
- password: 'lemmy',
+ password,
};
let resDelta = delta.client.login(formDelta);
let formEpsilon = {
username_or_email: 'lemmy_epsilon',
- password: 'lemmy',
+ password,
};
let resEpsilon = epsilon.client.login(formEpsilon);
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(
let name = randomString(5);
let body = randomString(10);
let url = 'https://google.com/';
- let form: PostForm = {
+ let form: CreatePost = {
name,
url,
body,
return api.client.createPost(form);
}
-export async function updatePost(api: API, post: Post): Promise<PostResponse> {
+export async function editPost(api: API, post: Post): Promise<PostResponse> {
let name = 'A jest test federated post, updated';
- let form: PostForm = {
+ let form: EditPost = {
name,
- edit_id: post.id,
+ post_id: post.id,
auth: api.auth,
nsfw: false,
};
deleted: boolean,
post: Post
): Promise<PostResponse> {
- let form: DeletePostForm = {
- edit_id: post.id,
+ let form: DeletePost = {
+ post_id: post.id,
deleted: deleted,
auth: api.auth,
};
removed: boolean,
post: Post
): Promise<PostResponse> {
- let form: RemovePostForm = {
- edit_id: post.id,
+ let form: RemovePost = {
+ post_id: post.id,
removed,
auth: api.auth,
};
stickied: boolean,
post: Post
): Promise<PostResponse> {
- let form: StickyPostForm = {
- edit_id: post.id,
+ let form: StickyPost = {
+ post_id: post.id,
stickied,
auth: api.auth,
};
locked: boolean,
post: Post
): Promise<PostResponse> {
- let form: LockPostForm = {
- edit_id: post.id,
+ let form: LockPost = {
+ post_id: post.id,
locked,
auth: api.auth,
};
return api.client.lockPost(form);
}
-export async function searchPost(
+export async function resolvePost(
api: API,
post: Post
-): Promise<SearchResponse> {
- let form: SearchForm = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q: post.ap_id,
- type_: SearchType.Posts,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
export async function searchPostLocal(
api: API,
post: Post
): Promise<SearchResponse> {
- let form: SearchForm = {
+ let form: Search = {
q: post.name,
type_: SearchType.Posts,
sort: SortType.TopAll,
api: API,
post_id: number
): Promise<GetPostResponse> {
- let form: GetPostForm = {
+ let form: GetPost = {
id: post_id,
};
return api.client.getPost(form);
}
-export async function searchComment(
+export async function resolveComment(
api: API,
comment: Comment
-): Promise<SearchResponse> {
- let form: SearchForm = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q: comment.ap_id,
- type_: SearchType.Comments,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function searchForBetaCommunity(
+export async function resolveBetaCommunity(
api: API
-): Promise<SearchResponse> {
- // Make sure lemmy-beta/c/main is cached on lemmy_alpha
+): Promise<ResolveObjectResponse> {
// Use short-hand search url
- let form: SearchForm = {
+ let form: ResolveObject = {
q: '!main@lemmy-beta:8551',
- type_: SearchType.Communities,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function searchForCommunity(
+export async function resolveCommunity(
api: API,
- q: string,
-): Promise<SearchResponse> {
- // Use short-hand search url
- let form: SearchForm = {
+ q: string
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q,
- type_: SearchType.Communities,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function searchForUser(
+export async function resolvePerson(
api: API,
apShortname: string
-): Promise<SearchResponse> {
- // Make sure lemmy-beta/c/main is cached on lemmy_alpha
- // Use short-hand search url
- let form: SearchForm = {
+): Promise<ResolveObjectResponse> {
+ let form: ResolveObject = {
q: apShortname,
- type_: SearchType.Users,
- sort: SortType.TopAll,
};
- return api.client.search(form);
+ return api.client.resolveObject(form);
}
-export async function banUserFromSite(
+export async function banPersonFromSite(
api: API,
- user_id: number,
+ person_id: number,
ban: boolean,
-): Promise<BanUserResponse> {
+ remove_data: boolean,
+): Promise<BanPersonResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
- // Use short-hand search url
- let form: BanUserForm = {
- user_id,
+ let form: BanPerson = {
+ person_id,
ban,
+ remove_data,
auth: api.auth,
};
- return api.client.banUser(form);
+ return api.client.banPerson(form);
}
-export async function banUserFromCommunity(
+export async function banPersonFromCommunity(
api: API,
- user_id: number,
+ person_id: number,
community_id: number,
- ban: boolean,
+ remove_data: boolean,
+ ban: boolean
): Promise<BanFromCommunityResponse> {
- // Make sure lemmy-beta/c/main is cached on lemmy_alpha
- // Use short-hand search url
- let form: BanFromCommunityForm = {
- user_id,
+ let form: BanFromCommunity = {
+ person_id,
community_id,
+ remove_data,
ban,
auth: api.auth,
};
follow: boolean,
community_id: number
): Promise<CommunityResponse> {
- let form: FollowCommunityForm = {
+ let form: FollowCommunity = {
community_id,
follow,
auth: api.auth,
return api.client.followCommunity(form);
}
-export async function checkFollowedCommunities(
- api: API
-): Promise<GetFollowedCommunitiesResponse> {
- let form: GetFollowedCommunitiesForm = {
- auth: api.auth,
- };
- return api.client.getFollowedCommunities(form);
-}
-
export async function likePost(
api: API,
score: number,
post: Post
): Promise<PostResponse> {
- let form: CreatePostLikeForm = {
+ let form: CreatePostLike = {
post_id: post.id,
score: score,
auth: api.auth,
parent_id?: number,
content = 'a jest test comment'
): Promise<CommentResponse> {
- let form: CommentForm = {
+ let form: CreateComment = {
content,
post_id,
parent_id,
return api.client.createComment(form);
}
-export async function updateComment(
+export async function editComment(
api: API,
- edit_id: number,
+ comment_id: number,
content = 'A jest test federated comment update'
): Promise<CommentResponse> {
- let form: CommentForm = {
+ let form: EditComment = {
content,
- edit_id,
+ comment_id,
auth: api.auth,
};
return api.client.editComment(form);
export async function deleteComment(
api: API,
deleted: boolean,
- edit_id: number
+ comment_id: number
): Promise<CommentResponse> {
- let form: DeleteCommentForm = {
- edit_id,
+ let form: DeleteComment = {
+ comment_id,
deleted,
auth: api.auth,
};
export async function removeComment(
api: API,
removed: boolean,
- edit_id: number
+ comment_id: number
): Promise<CommentResponse> {
- let form: RemoveCommentForm = {
- edit_id,
+ let form: RemoveComment = {
+ comment_id,
removed,
auth: api.auth,
};
return api.client.removeComment(form);
}
-export async function getMentions(api: API): Promise<GetUserMentionsResponse> {
- let form: GetUserMentionsForm = {
+export async function getMentions(api: API): Promise<GetPersonMentionsResponse> {
+ let form: GetPersonMentions = {
sort: SortType.New,
unread_only: false,
auth: api.auth,
};
- return api.client.getUserMentions(form);
+ return api.client.getPersonMentions(form);
}
export async function likeComment(
score: number,
comment: Comment
): Promise<CommentResponse> {
- let form: CommentLikeForm = {
+ let form: CreateCommentLike = {
comment_id: comment.id,
score,
auth: api.auth,
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: CommunityForm = {
+ let form: CreateCommunity = {
name: name_,
title: name_,
description,
- icon,
- banner,
- category_id: 1,
nsfw: false,
auth: api.auth,
};
export async function getCommunity(
api: API,
- id: number,
+ id: number
): Promise<CommunityResponse> {
- let form: GetCommunityForm = {
+ let form: GetCommunity = {
id,
};
return api.client.getCommunity(form);
export async function deleteCommunity(
api: API,
deleted: boolean,
- edit_id: number
+ community_id: number
): Promise<CommunityResponse> {
- let form: DeleteCommunityForm = {
- edit_id,
+ let form: DeleteCommunity = {
+ community_id,
deleted,
auth: api.auth,
};
export async function removeCommunity(
api: API,
removed: boolean,
- edit_id: number
+ community_id: number
): Promise<CommunityResponse> {
- let form: RemoveCommunityForm = {
- edit_id,
+ let form: RemoveCommunity = {
+ community_id,
removed,
auth: api.auth,
};
recipient_id: number
): Promise<PrivateMessageResponse> {
let content = 'A jest test federated private message';
- let form: PrivateMessageForm = {
+ let form: CreatePrivateMessage = {
content,
recipient_id,
auth: api.auth,
return api.client.createPrivateMessage(form);
}
-export async function updatePrivateMessage(
+export async function editPrivateMessage(
api: API,
- edit_id: number
+ private_message_id: number
): Promise<PrivateMessageResponse> {
let updatedContent = 'A jest test federated private message edited';
- let form: EditPrivateMessageForm = {
+ let form: EditPrivateMessage = {
content: updatedContent,
- edit_id,
+ private_message_id,
auth: api.auth,
};
return api.client.editPrivateMessage(form);
export async function deletePrivateMessage(
api: API,
deleted: boolean,
- edit_id: number
+ private_message_id: number
): Promise<PrivateMessageResponse> {
- let form: DeletePrivateMessageForm = {
+ let form: DeletePrivateMessage = {
deleted,
- edit_id,
+ private_message_id,
auth: api.auth,
};
return api.client.deletePrivateMessage(form);
api: API,
username: string = randomString(5)
): Promise<LoginResponse> {
- let form: RegisterForm = {
+ let form: Register = {
username,
- password: 'test',
- password_verify: 'test',
- admin: false,
+ password,
+ password_verify: password,
show_nsfw: true,
};
return api.client.register(form);
}
export async function saveUserSettingsBio(
- api: API,
- auth: string
+ api: API
): Promise<LoginResponse> {
- let form: UserSettingsForm = {
+ let form: SaveUserSettings = {
show_nsfw: true,
theme: 'darkly',
default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
show_avatars: true,
send_notifications_to_email: false,
bio: 'a changed bio',
- auth,
+ auth: api.auth,
};
return saveUserSettings(api, form);
}
export async function saveUserSettings(
api: API,
- form: UserSettingsForm
+ form: SaveUserSettings
): Promise<LoginResponse> {
return api.client.saveUserSettings(form);
}
-export async function getSite(
+export async function deleteUser(
api: API,
- auth: string
+): Promise<DeleteAccountResponse> {
+ let form: DeleteAccount = {
+ auth: api.auth,
+ password
+ };
+ return api.client.deleteAccount(form);
+}
+
+export async function getSite(
+ api: API
): Promise<GetSiteResponse> {
- let form: GetSiteForm = {
- auth,
+ let form: GetSite = {
+ auth: api.auth,
};
return api.client.getSite(form);
}
export async function listPrivateMessages(
api: API
): Promise<PrivateMessagesResponse> {
- let form: GetPrivateMessagesForm = {
+ let form: GetPrivateMessages = {
auth: api.auth,
unread_only: false,
limit: 999,
export async function unfollowRemotes(
api: API
-): Promise<GetFollowedCommunitiesResponse> {
+): Promise<GetSiteResponse> {
// Unfollow all remote communities
- let followed = await checkFollowedCommunities(api);
- let remoteFollowed = followed.communities.filter(
- c => c.community_local == false
+ let site = await getSite(api);
+ let remoteFollowed = site.my_user.follows.filter(
+ c => c.community.local == false
);
for (let cu of remoteFollowed) {
- await followCommunity(api, false, cu.community_id);
+ await followCommunity(api, false, cu.community.id);
}
- let followed2 = await checkFollowedCommunities(api);
- return followed2;
+ let siteRes = await getSite(api);
+ return siteRes;
}
export async function followBeta(api: API): Promise<CommunityResponse> {
- await unfollowRemotes(api);
-
- // Cache it
- let search = await searchForBetaCommunity(api);
- let com = search.communities.filter(c => c.local == false);
- if (com[0]) {
- let follow = await followCommunity(api, true, com[0].id);
+ let betaCommunity = (await resolveBetaCommunity(api)).community;
+ if (betaCommunity) {
+ let follow = await followCommunity(api, true, betaCommunity.community.id);
return follow;
}
}
-export function delay(millis: number = 2000) {
- return new Promise((resolve, _reject) => {
- setTimeout(_ => resolve(), millis);
- });
+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));
}
export function longDelay() {
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);
+}