2022-03-12 13:10:46 -08:00
import { Record as ImmutableRecord , fromJS } from 'immutable' ;
2022-02-27 12:42:42 -08:00
import { normalizeAccount } from '../account' ;
2022-03-12 13:10:46 -08:00
const AVATAR _MISSING = require ( 'images/avatar-missing.png' ) ;
2022-02-27 12:42:42 -08:00
describe ( 'normalizeAccount()' , ( ) => {
2022-03-12 13:10:46 -08:00
it ( 'adds base fields' , ( ) => {
const account = fromJS ( { } ) ;
const result = normalizeAccount ( account ) ;
2022-03-12 12:19:34 -08:00
2022-03-12 13:10:46 -08:00
expect ( ImmutableRecord . isRecord ( result ) ) . toBe ( true ) ;
expect ( result . acct ) . toEqual ( '' ) ;
expect ( result . note ) . toEqual ( '' ) ;
expect ( result . avatar ) . toEqual ( AVATAR _MISSING ) ;
} ) ;
it ( 'normalizes a mention' , ( ) => {
2022-03-11 18:48:00 -08:00
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' ) ;
2022-03-12 13:10:46 -08:00
expect ( result . avatar ) . toEqual ( AVATAR _MISSING ) ;
expect ( result . avatar _static ) . toEqual ( AVATAR _MISSING ) ;
2022-03-11 18:48:00 -08:00
expect ( result . verified ) . toBe ( false ) ;
} ) ;
2022-02-27 12:42:42 -08:00
it ( 'normalizes Fedibird birthday' , ( ) => {
const account = fromJS ( require ( 'soapbox/__fixtures__/fedibird-account.json' ) ) ;
const result = normalizeAccount ( account ) ;
2022-03-12 12:19:34 -08:00
expect ( result . birthday ) . toEqual ( '1993-07-03' ) ;
2022-02-27 12:42:42 -08:00
} ) ;
it ( 'normalizes Pleroma birthday' , ( ) => {
const account = fromJS ( require ( 'soapbox/__fixtures__/pleroma-account.json' ) ) ;
const result = normalizeAccount ( account ) ;
2022-03-12 12:19:34 -08:00
expect ( result . birthday ) . toEqual ( '1993-07-03' ) ;
2022-02-27 12:42:42 -08:00
} ) ;
2022-02-27 18:21:39 -08:00
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 ) ;
} ) ;
2022-02-27 20:22:08 -08:00
it ( 'normalizes a verified Pleroma user' , ( ) => {
const account = fromJS ( require ( 'soapbox/__fixtures__/mk.json' ) ) ;
const result = normalizeAccount ( account ) ;
2022-03-12 12:19:34 -08:00
expect ( result . verified ) . toBe ( true ) ;
2022-02-27 20:22:08 -08:00
} ) ;
it ( 'normalizes an unverified Pleroma user' , ( ) => {
const account = fromJS ( require ( 'soapbox/__fixtures__/pleroma-account.json' ) ) ;
const result = normalizeAccount ( account ) ;
2022-03-12 12:19:34 -08:00
expect ( result . verified ) . toBe ( false ) ;
2022-02-27 20:22:08 -08:00
} ) ;
it ( 'normalizes a verified Truth Social user' , ( ) => {
const account = fromJS ( require ( 'soapbox/__fixtures__/realDonaldTrump.json' ) ) ;
const result = normalizeAccount ( account ) ;
2022-03-12 12:19:34 -08:00
expect ( result . verified ) . toBe ( true ) ;
2022-02-27 20:22:08 -08:00
} ) ;
2022-02-28 15:25:20 -08:00
it ( 'normalizes Fedibird location' , ( ) => {
const account = fromJS ( require ( 'soapbox/__fixtures__/fedibird-account.json' ) ) ;
const result = normalizeAccount ( account ) ;
2022-03-12 12:19:34 -08:00
expect ( result . location ) . toBe ( 'Texas, USA' ) ;
2022-02-28 15:25:20 -08:00
} ) ;
it ( 'normalizes Truth Social location' , ( ) => {
const account = fromJS ( require ( 'soapbox/__fixtures__/truthsocial-account.json' ) ) ;
const result = normalizeAccount ( account ) ;
2022-03-12 12:19:34 -08:00
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 <img draggable="false" class="emojione" alt="😂" title=":joy:" src="/packs/emoji/1f602.svg" /> <img draggable="false" class="emojione" alt=":soapbox:" title=":soapbox:" src="https://gleasonator.com/emoji/Gleasonator/soapbox.png" /> <img draggable="false" class="emojione" alt=":ablobcatrainbow:" title=":ablobcatrainbow:" src="https://gleasonator.com/emoji/blobcat/ablobcatrainbow.png" />' ;
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. <img draggable="false" class="emojione" alt=":soapbox:" title=":soapbox:" src="https://gleasonator.com/emoji/Gleasonator/soapbox.png" /><br/><br/>I'm vegan btw<br/><br/>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 <img draggable="false" class="emojione" alt=":ablobcatrainbow:" title=":ablobcatrainbow:" src="https://gleasonator.com/emoji/blobcat/ablobcatrainbow.png" />' ) ;
expect ( field . value _emojified ) . toBe ( '<a href="https://soapbox.pub" rel="ugc">https://soapbox.pub</a> <img draggable="false" class="emojione" alt=":soapbox:" title=":soapbox:" src="https://gleasonator.com/emoji/Gleasonator/soapbox.png" />' ) ;
expect ( field . value _plain ) . toBe ( 'https://soapbox.pub :soapbox:' ) ;
2022-02-28 15:25:20 -08:00
} ) ;
2022-02-27 12:42:42 -08:00
} ) ;