import { Record as ImmutableRecord, fromJS } from 'immutable'; import { normalizeAccount } from '../account'; const AVATAR_MISSING = require('images/avatar-missing.png'); describe('normalizeAccount()', () => { it('adds base fields', () => { const account = fromJS({}); const result = normalizeAccount(account); expect(ImmutableRecord.isRecord(result)).toBe(true); expect(result.acct).toEqual(''); expect(result.note).toEqual(''); expect(result.avatar).toEqual(AVATAR_MISSING); }); it('normalizes a mention', () => { const mention = fromJS({ acct: 'NEETzsche@iddqd.social', id: '9v5bw7hEGBPc9nrpzc', url: 'https://iddqd.social/users/NEETzsche', username: 'NEETzsche', }); const result = normalizeAccount(mention); expect(result.emojis).toEqual(fromJS([])); expect(result.display_name).toEqual('NEETzsche'); expect(result.avatar).toEqual(AVATAR_MISSING); expect(result.avatar_static).toEqual(AVATAR_MISSING); expect(result.verified).toBe(false); }); it('normalizes Fedibird birthday', () => { const account = fromJS(require('soapbox/__fixtures__/fedibird-account.json')); const result = normalizeAccount(account); expect(result.birthday).toEqual('1993-07-03'); }); it('normalizes Pleroma birthday', () => { const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json')); const result = normalizeAccount(account); expect(result.birthday).toEqual('1993-07-03'); }); it('normalizes Pleroma legacy fields', () => { const account = fromJS(require('soapbox/__fixtures__/pleroma-2.2.2-account.json')); const result = normalizeAccount(account); expect(result.getIn(['pleroma', 'is_active'])).toBe(true); expect(result.getIn(['pleroma', 'is_confirmed'])).toBe(true); expect(result.getIn(['pleroma', 'is_approved'])).toBe(true); expect(result.hasIn(['pleroma', 'confirmation_pending'])).toBe(false); }); it('prefers new Pleroma fields', () => { const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json')); const result = normalizeAccount(account); expect(result.getIn(['pleroma', 'is_active'])).toBe(true); expect(result.getIn(['pleroma', 'is_confirmed'])).toBe(true); expect(result.getIn(['pleroma', 'is_approved'])).toBe(true); }); it('normalizes a verified Pleroma user', () => { const account = fromJS(require('soapbox/__fixtures__/mk.json')); const result = normalizeAccount(account); expect(result.verified).toBe(true); }); it('normalizes an unverified Pleroma user', () => { const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json')); const result = normalizeAccount(account); expect(result.verified).toBe(false); }); it('normalizes a verified Truth Social user', () => { const account = fromJS(require('soapbox/__fixtures__/realDonaldTrump.json')); const result = normalizeAccount(account); expect(result.verified).toBe(true); }); it('normalizes Fedibird location', () => { const account = fromJS(require('soapbox/__fixtures__/fedibird-account.json')); const result = normalizeAccount(account); expect(result.location).toBe('Texas, USA'); }); it('normalizes Truth Social location', () => { const account = fromJS(require('soapbox/__fixtures__/truthsocial-account.json')); const result = normalizeAccount(account); expect(result.location).toBe('Texas'); }); it('sets display_name from username', () => { const account = fromJS({ username: 'alex' }); const result = normalizeAccount(account); expect(result.display_name).toBe('alex'); }); it('sets display_name from acct', () => { const account = fromJS({ acct: 'alex@gleasonator.com' }); const result = normalizeAccount(account); expect(result.display_name).toBe('alex'); }); it('overrides a whitespace display_name', () => { const account = fromJS({ username: 'alex', display_name: ' ' }); const result = normalizeAccount(account); expect(result.display_name).toBe('alex'); }); it('emojifies display name as `display_name_html`', () => { const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json')); const result = normalizeAccount(account); const expected = 'Alex Gleason 😂 :soapbox: :ablobcatrainbow:'; expect(result.display_name_html).toBe(expected); }); it('emojifies note as `note_emojified`', () => { const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json')); const result = normalizeAccount(account); const expected = 'I create Fediverse software that empowers people online. :soapbox:

I'm vegan btw

Note: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.'; expect(result.note_emojified).toBe(expected); }); it('unescapes HTML note as `note_plain`', () => { const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json')); const result = normalizeAccount(account); const expected = 'I create Fediverse software that empowers people online. :soapbox:\n\nI\'m vegan btw\n\nNote: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.'; expect(result.note_plain).toBe(expected); }); it('emojifies custom profile field', () => { const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json')); const result = normalizeAccount(account); const field = result.fields.get(1); expect(field.name_emojified).toBe('Soapbox :ablobcatrainbow:'); expect(field.value_emojified).toBe('https://soapbox.pub :soapbox:'); expect(field.value_plain).toBe('https://soapbox.pub :soapbox:'); }); });