2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2020-08-04 15:06:27 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
beta,
|
|
|
|
registerUser,
|
|
|
|
searchForUser,
|
|
|
|
saveUserSettingsBio,
|
2020-09-17 15:41:51 +00:00
|
|
|
saveUserSettings,
|
2020-08-04 15:06:27 +00:00
|
|
|
getSite,
|
|
|
|
} from './shared';
|
2020-09-17 15:41:51 +00:00
|
|
|
import {
|
|
|
|
UserView,
|
|
|
|
UserSettingsForm,
|
|
|
|
} from 'lemmy-js-client';
|
2020-08-04 15:06:27 +00:00
|
|
|
|
|
|
|
let auth: string;
|
|
|
|
let apShortname: string;
|
|
|
|
|
2020-09-17 15:41:51 +00:00
|
|
|
function assertUserFederation(
|
|
|
|
userOne: UserView,
|
|
|
|
userTwo: UserView) {
|
|
|
|
expect(userOne.name).toBe(userTwo.name);
|
|
|
|
expect(userOne.preferred_username).toBe(userTwo.preferred_username);
|
|
|
|
expect(userOne.bio).toBe(userTwo.bio);
|
|
|
|
expect(userOne.actor_id).toBe(userTwo.actor_id);
|
|
|
|
expect(userOne.avatar).toBe(userTwo.avatar);
|
|
|
|
expect(userOne.banner).toBe(userTwo.banner);
|
|
|
|
}
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
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();
|
2020-09-15 19:26:47 +00:00
|
|
|
apShortname = `@${site.my_user.name}@lemmy-alpha:8541`;
|
2020-08-04 15:06:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2020-09-17 15:41:51 +00:00
|
|
|
let searchAlpha = await searchForUser(alpha, site.my_user.actor_id);
|
2020-08-04 15:06:27 +00:00
|
|
|
|
|
|
|
// Make sure beta sees this bio is changed
|
2020-09-17 15:41:51 +00:00
|
|
|
let searchBeta = await searchForUser(beta, apShortname);
|
|
|
|
assertUserFederation(searchAlpha.users[0], searchBeta.users[0]);
|
2020-08-04 15:06:27 +00:00
|
|
|
});
|
2020-09-17 15:41:51 +00:00
|
|
|
|
|
|
|
test('Set avatar and banner, check that they are federated', async () => {
|
|
|
|
let avatar = 'https://image.flaticon.com/icons/png/512/35/35896.png';
|
|
|
|
let banner = 'https://image.flaticon.com/icons/png/512/36/35896.png';
|
|
|
|
let form: UserSettingsForm = {
|
|
|
|
show_nsfw: false,
|
|
|
|
theme: "",
|
|
|
|
default_sort_type: 0,
|
|
|
|
default_listing_type: 0,
|
|
|
|
lang: "",
|
|
|
|
avatar,
|
|
|
|
banner,
|
|
|
|
preferred_username: "user321",
|
|
|
|
show_avatars: false,
|
|
|
|
send_notifications_to_email: false,
|
|
|
|
auth,
|
|
|
|
}
|
|
|
|
let settingsRes = await saveUserSettings(alpha, form);
|
|
|
|
|
|
|
|
let searchAlpha = await searchForUser(beta, apShortname);
|
|
|
|
let userOnAlpha = searchAlpha.users[0];
|
|
|
|
let searchBeta = await searchForUser(beta, apShortname);
|
|
|
|
let userOnBeta = searchBeta.users[0];
|
|
|
|
assertUserFederation(userOnAlpha, userOnBeta);
|
|
|
|
});
|