Normalizers: fix tests

This commit is contained in:
Alex Gleason 2022-03-08 23:47:30 -06:00
parent 7a18f8b9c8
commit 10116a312a
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 22 additions and 3 deletions

View file

@ -11,6 +11,13 @@ const makeEmojiMap = record => record.emojis.reduce((obj, emoji) => {
export function normalizeAccount(account) {
account = { ...account };
// Some backends can return null, or omit these required fields
if (!account.emojis) account.emojis = [];
if (!account.display_name) account.display_name = '';
if (!account.note) account.note = '';
if (!account.avatar) account.avatar = account.avatar_static || require('images/avatar-missing.png');
if (!account.avatar_static) account.avatar_static = account.avatar;
const emojiMap = makeEmojiMap(account);
const displayName = account.display_name.trim().length === 0 ? account.username : account.display_name;

View file

@ -32,7 +32,19 @@ describe('normalizeInstance()', () => {
fedibird_capabilities: [],
invites_enabled: false,
languages: [],
pleroma: {},
pleroma: {
metadata: {
account_activation_required: false,
birthday_min_age: 0,
birthday_required: false,
features: [],
federation: {
enabled: true,
exclusions: false,
},
},
stats: {},
},
registrations: false,
rules: [],
short_description: '',

View file

@ -8,6 +8,7 @@ const StatusRecord = Record({
application: null,
bookmarked: false,
card: null,
content: '',
created_at: new Date(),
emojis: ImmutableList(),
favourited: false,

View file

@ -89,8 +89,7 @@ const fixQuote = (status, oldStatus) => {
const fixStatus = (state, status, expandSpoilers) => {
const oldStatus = state.get(status.get('id'));
return status.withMutations(status => {
normalizeStatus(status);
return normalizeStatus(status).withMutations(status => {
fixQuote(status, oldStatus);
calculateStatus(status, oldStatus, expandSpoilers);
minifyStatus(status);