Normalizers: fix tests
This commit is contained in:
parent
7a18f8b9c8
commit
10116a312a
4 changed files with 22 additions and 3 deletions
|
@ -11,6 +11,13 @@ const makeEmojiMap = record => record.emojis.reduce((obj, emoji) => {
|
||||||
export function normalizeAccount(account) {
|
export function normalizeAccount(account) {
|
||||||
account = { ...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 emojiMap = makeEmojiMap(account);
|
||||||
const displayName = account.display_name.trim().length === 0 ? account.username : account.display_name;
|
const displayName = account.display_name.trim().length === 0 ? account.username : account.display_name;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,19 @@ describe('normalizeInstance()', () => {
|
||||||
fedibird_capabilities: [],
|
fedibird_capabilities: [],
|
||||||
invites_enabled: false,
|
invites_enabled: false,
|
||||||
languages: [],
|
languages: [],
|
||||||
pleroma: {},
|
pleroma: {
|
||||||
|
metadata: {
|
||||||
|
account_activation_required: false,
|
||||||
|
birthday_min_age: 0,
|
||||||
|
birthday_required: false,
|
||||||
|
features: [],
|
||||||
|
federation: {
|
||||||
|
enabled: true,
|
||||||
|
exclusions: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
stats: {},
|
||||||
|
},
|
||||||
registrations: false,
|
registrations: false,
|
||||||
rules: [],
|
rules: [],
|
||||||
short_description: '',
|
short_description: '',
|
||||||
|
|
|
@ -8,6 +8,7 @@ const StatusRecord = Record({
|
||||||
application: null,
|
application: null,
|
||||||
bookmarked: false,
|
bookmarked: false,
|
||||||
card: null,
|
card: null,
|
||||||
|
content: '',
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
emojis: ImmutableList(),
|
emojis: ImmutableList(),
|
||||||
favourited: false,
|
favourited: false,
|
||||||
|
|
|
@ -89,8 +89,7 @@ const fixQuote = (status, oldStatus) => {
|
||||||
const fixStatus = (state, status, expandSpoilers) => {
|
const fixStatus = (state, status, expandSpoilers) => {
|
||||||
const oldStatus = state.get(status.get('id'));
|
const oldStatus = state.get(status.get('id'));
|
||||||
|
|
||||||
return status.withMutations(status => {
|
return normalizeStatus(status).withMutations(status => {
|
||||||
normalizeStatus(status);
|
|
||||||
fixQuote(status, oldStatus);
|
fixQuote(status, oldStatus);
|
||||||
calculateStatus(status, oldStatus, expandSpoilers);
|
calculateStatus(status, oldStatus, expandSpoilers);
|
||||||
minifyStatus(status);
|
minifyStatus(status);
|
||||||
|
|
Loading…
Reference in a new issue