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