Account normalizer: use '' as default birthday
This commit is contained in:
parent
d168302e72
commit
cef4b16a69
|
@ -47,6 +47,13 @@ describe('normalizeAccount()', () => {
|
|||
expect(result.birthday).toEqual('1993-07-03');
|
||||
});
|
||||
|
||||
it('normalizes undefined birthday to empty string', () => {
|
||||
const account = require('soapbox/__fixtures__/mastodon-account.json');
|
||||
const result = normalizeAccount(account);
|
||||
|
||||
expect(result.birthday).toEqual('');
|
||||
});
|
||||
|
||||
it('normalizes Pleroma legacy fields', () => {
|
||||
const account = require('soapbox/__fixtures__/pleroma-2.2.2-account.json');
|
||||
const result = normalizeAccount(account);
|
||||
|
|
|
@ -24,7 +24,7 @@ export const AccountRecord = ImmutableRecord({
|
|||
acct: '',
|
||||
avatar: '',
|
||||
avatar_static: '',
|
||||
birthday: undefined as string | undefined,
|
||||
birthday: '',
|
||||
bot: false,
|
||||
created_at: new Date(),
|
||||
discoverable: false,
|
||||
|
@ -261,6 +261,12 @@ const normalizeDiscoverable = (account: ImmutableMap<string, any>) => {
|
|||
return account.set('discoverable', discoverable);
|
||||
};
|
||||
|
||||
/** Normalize undefined/null birthday to empty string. */
|
||||
const fixBirthday = (account: ImmutableMap<string, any>) => {
|
||||
const birthday = account.get('birthday');
|
||||
return account.set('birthday', birthday || '');
|
||||
};
|
||||
|
||||
export const normalizeAccount = (account: Record<string, any>) => {
|
||||
return AccountRecord(
|
||||
ImmutableMap(fromJS(account)).withMutations(account => {
|
||||
|
@ -280,6 +286,7 @@ export const normalizeAccount = (account: Record<string, any>) => {
|
|||
addStaffFields(account);
|
||||
fixUsername(account);
|
||||
fixDisplayName(account);
|
||||
fixBirthday(account);
|
||||
addInternalFields(account);
|
||||
}),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue