- LEMMY_SETUP__SITE_NAME=lemmy-alpha
- LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999
+ - LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1
- RUST_LOG=debug
depends_on:
- LEMMY_SETUP__SITE_NAME=lemmy-beta
- LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999
+ - LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1
- RUST_LOG=debug
depends_on:
- LEMMY_SETUP__SITE_NAME=lemmy-gamma
- LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999
+ - LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1
- RUST_LOG=debug
depends_on:
- LEMMY_SETUP__SITE_NAME=lemmy-alpha
- LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999
+ - LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1
- RUST_LOG=debug
depends_on:
- LEMMY_SETUP__SITE_NAME=lemmy-beta
- LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999
+ - LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1
- RUST_LOG=debug
depends_on:
- LEMMY_SETUP__SITE_NAME=lemmy-gamma
- LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999
+ - LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1
- RUST_LOG=debug
depends_on:
CommunityResponse,
GetFollowedCommunitiesResponse,
GetPostResponse,
+ RegisterForm,
CommentForm,
DeleteCommentForm,
RemoveCommentForm,
PrivateMessageResponse,
PrivateMessagesResponse,
GetUserMentionsResponse,
+ UserSettingsForm,
+ SortType,
+ ListingType,
+ GetSiteResponse,
} from '../interfaces';
export interface API {
return searchResponse;
}
+export async function searchForUser(
+ api: API,
+ apShortname: string
+): Promise<SearchResponse> {
+ // Make sure lemmy-beta/c/main is cached on lemmy_alpha
+ // Use short-hand search url
+ let searchUrl = `${apiUrl(
+ api
+ )}/search?q=${apShortname}&type_=All&sort=TopAll`;
+
+ let searchResponse: SearchResponse = await fetch(searchUrl, {
+ method: 'GET',
+ }).then(d => d.json());
+ return searchResponse;
+}
+
export async function followCommunity(
api: API,
follow: boolean,
return deleteRes;
}
+export async function registerUser(
+ api: API,
+ username: string = randomString(5)
+): Promise<LoginResponse> {
+ let registerForm: RegisterForm = {
+ username,
+ password: 'test',
+ password_verify: 'test',
+ admin: false,
+ show_nsfw: true,
+ };
+
+ let registerRes: Promise<LoginResponse> = fetch(
+ `${apiUrl(api)}/user/register`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: wrapper(registerForm),
+ }
+ ).then(d => d.json());
+
+ return registerRes;
+}
+
+export async function saveUserSettingsBio(
+ api: API,
+ auth: string
+): Promise<LoginResponse> {
+ let form: UserSettingsForm = {
+ show_nsfw: true,
+ theme: 'darkly',
+ default_sort_type: SortType.Hot,
+ default_listing_type: ListingType.All,
+ lang: 'en',
+ show_avatars: true,
+ send_notifications_to_email: false,
+ bio: 'a changed bio',
+ auth,
+ };
+
+ let res: Promise<LoginResponse> = fetch(
+ `${apiUrl(api)}/user/save_user_settings`,
+ {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: wrapper(form),
+ }
+ ).then(d => d.json());
+ return res;
+}
+
+export async function getSite(
+ api: API,
+ auth: string
+): Promise<GetSiteResponse> {
+ let siteUrl = `${apiUrl(api)}/site?auth=${auth}`;
+
+ let res: GetSiteResponse = await fetch(siteUrl, {
+ method: 'GET',
+ }).then(d => d.json());
+ return res;
+}
+
export async function listPrivateMessages(
api: API
): Promise<PrivateMessagesResponse> {
// Cache it
let search = await searchForBetaCommunity(api);
-
- // Unfollow first
- let follow = await followCommunity(
- api,
- true,
- search.communities.filter(c => c.local == false)[0].id
- );
- return follow;
+ let com = search.communities.filter(c => c.local == false);
+ if (com[0]) {
+ let follow = await followCommunity(api, true, com[0].id);
+ return follow;
+ }
}
export function wrapper(form: any): string {
--- /dev/null
+import {
+ alpha,
+ beta,
+ registerUser,
+ searchForUser,
+ saveUserSettingsBio,
+ getSite,
+} from './shared';
+
+let auth: string;
+let apShortname: string;
+
+test('Create user', async () => {
+ let userRes = await registerUser(alpha);
+ expect(userRes.jwt).toBeDefined();
+ auth = userRes.jwt;
+
+ let site = await getSite(alpha, auth);
+ expect(site.my_user).toBeDefined();
+ apShortname = `@${site.my_user.name}@lemmy-alpha:8540`;
+});
+
+test('Save user settings, check changed bio from beta', async () => {
+ let bio = 'a changed bio';
+ let userRes = await saveUserSettingsBio(alpha, auth);
+ expect(userRes.jwt).toBeDefined();
+
+ let site = await getSite(alpha, auth);
+ expect(site.my_user.bio).toBe(bio);
+
+ // Make sure beta sees this bio is changed
+ let search = await searchForUser(beta, apShortname);
+ expect(search.users[0].bio).toBe(bio);
+});