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');
|
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', () => {
|
it('normalizes Pleroma legacy fields', () => {
|
||||||
const account = require('soapbox/__fixtures__/pleroma-2.2.2-account.json');
|
const account = require('soapbox/__fixtures__/pleroma-2.2.2-account.json');
|
||||||
const result = normalizeAccount(account);
|
const result = normalizeAccount(account);
|
||||||
|
|
|
@ -24,7 +24,7 @@ export const AccountRecord = ImmutableRecord({
|
||||||
acct: '',
|
acct: '',
|
||||||
avatar: '',
|
avatar: '',
|
||||||
avatar_static: '',
|
avatar_static: '',
|
||||||
birthday: undefined as string | undefined,
|
birthday: '',
|
||||||
bot: false,
|
bot: false,
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
discoverable: false,
|
discoverable: false,
|
||||||
|
@ -261,6 +261,12 @@ const normalizeDiscoverable = (account: ImmutableMap<string, any>) => {
|
||||||
return account.set('discoverable', discoverable);
|
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>) => {
|
export const normalizeAccount = (account: Record<string, any>) => {
|
||||||
return AccountRecord(
|
return AccountRecord(
|
||||||
ImmutableMap(fromJS(account)).withMutations(account => {
|
ImmutableMap(fromJS(account)).withMutations(account => {
|
||||||
|
@ -280,6 +286,7 @@ export const normalizeAccount = (account: Record<string, any>) => {
|
||||||
addStaffFields(account);
|
addStaffFields(account);
|
||||||
fixUsername(account);
|
fixUsername(account);
|
||||||
fixDisplayName(account);
|
fixDisplayName(account);
|
||||||
|
fixBirthday(account);
|
||||||
addInternalFields(account);
|
addInternalFields(account);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue