Normalize mentions, add tests
This commit is contained in:
parent
02f05abeaa
commit
331b239cc9
|
@ -8,10 +8,7 @@ const getAccount = makeGetAccount();
|
|||
|
||||
const buildMentions = pendingStatus => {
|
||||
if (pendingStatus.get('in_reply_to_id')) {
|
||||
return ImmutableList(pendingStatus.get('to') || []).map(acct => ImmutableMap({
|
||||
acct,
|
||||
username: acct.split('@')[0],
|
||||
}));
|
||||
return ImmutableList(pendingStatus.get('to') || []).map(acct => ImmutableMap({ acct }));
|
||||
} else {
|
||||
return ImmutableList();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,18 @@ import { fromJS } from 'immutable';
|
|||
import { normalizeStatus } from '../status';
|
||||
|
||||
describe('normalizeStatus', () => {
|
||||
it('adds base fields', () => {
|
||||
const status = fromJS({});
|
||||
const result = normalizeStatus(status);
|
||||
|
||||
expect(result.get('emojis')).toEqual(fromJS([]));
|
||||
expect(result.get('favourites_count')).toBe(0);
|
||||
expect(result.get('mentions')).toEqual(fromJS([]));
|
||||
expect(result.get('reblog')).toBe(null);
|
||||
expect(result.get('uri')).toBe('');
|
||||
expect(result.get('visibility')).toBe('public');
|
||||
});
|
||||
|
||||
it('fixes the order of mentions', () => {
|
||||
const status = fromJS(require('soapbox/__fixtures__/status-unordered-mentions.json'));
|
||||
|
||||
|
@ -31,6 +43,20 @@ describe('normalizeStatus', () => {
|
|||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('normalizes mentions with only acct', () => {
|
||||
const status = fromJS({ mentions: [{ acct: 'alex@gleasonator.com' }] });
|
||||
|
||||
const expected = fromJS([{
|
||||
acct: 'alex@gleasonator.com',
|
||||
username: 'alex',
|
||||
url: '',
|
||||
}]);
|
||||
|
||||
const result = normalizeStatus(status).get('mentions');
|
||||
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('normalizes Mitra attachments', () => {
|
||||
const status = fromJS(require('soapbox/__fixtures__/mitra-status-with-attachments.json'));
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ const baseStatus = ImmutableMap({
|
|||
const mergeDefined = (oldVal, newVal) => oldVal === undefined ? newVal : oldVal;
|
||||
|
||||
// Merge base status
|
||||
const setRequiredFields = status => {
|
||||
const mergeBase = status => {
|
||||
return status.mergeDeepWith(mergeDefined, baseStatus);
|
||||
};
|
||||
|
||||
|
@ -121,7 +121,7 @@ const fixQuote = status => {
|
|||
|
||||
export const normalizeStatus = status => {
|
||||
return status.withMutations(status => {
|
||||
setRequiredFields(status);
|
||||
mergeBase(status);
|
||||
normalizeAttachments(status);
|
||||
normalizeMentions(status);
|
||||
fixMentionsOrder(status);
|
||||
|
|
Loading…
Reference in New Issue