Remove normalizeCard()

This commit is contained in:
Alex Gleason 2023-05-02 18:33:41 -05:00
parent 54d8d12054
commit 489145ffb8
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
5 changed files with 11 additions and 41 deletions

View file

@ -1,14 +0,0 @@
import { Record as ImmutableRecord } from 'immutable';
import { normalizeCard } from '../card';
describe('normalizeCard()', () => {
it('adds base fields', () => {
const card = {};
const result = normalizeCard(card);
expect(ImmutableRecord.isRecord(result)).toBe(true);
expect(result.type).toEqual('link');
expect(result.url).toEqual('');
});
});

View file

@ -195,7 +195,6 @@ describe('normalizeStatus()', () => {
const result = normalizeStatus(status);
const card = result.card as Card;
expect(ImmutableRecord.isRecord(card)).toBe(true);
expect(card.type).toEqual('link');
expect(card.provider_url).toEqual('https://soapbox.pub');
});

View file

@ -1,25 +0,0 @@
import { cardSchema, type Card } from 'soapbox/schemas/card';
export const normalizeCard = (card: unknown): Card => {
try {
return cardSchema.parse(card);
} catch (_e) {
return {
author_name: '',
author_url: '',
blurhash: null,
description: '',
embed_url: '',
group: null,
height: 0,
html: '',
image: null,
provider_name: '',
provider_url: '',
title: '',
type: 'link',
url: '',
width: 0,
};
}
};

View file

@ -4,7 +4,6 @@ export { AdminReportRecord, normalizeAdminReport } from './admin-report';
export { AnnouncementRecord, normalizeAnnouncement } from './announcement';
export { AnnouncementReactionRecord, normalizeAnnouncementReaction } from './announcement-reaction';
export { AttachmentRecord, normalizeAttachment } from './attachment';
export { normalizeCard } from './card';
export { ChatRecord, normalizeChat } from './chat';
export { ChatMessageRecord, normalizeChatMessage } from './chat-message';
export { EmojiRecord, normalizeEmoji } from './emoji';

View file

@ -0,0 +1,11 @@
import { cardSchema } from '../card';
describe('cardSchema', () => {
it('adds base fields', () => {
const card = { url: 'https://soapbox.test' };
const result = cardSchema.parse(card);
expect(result.type).toEqual('link');
expect(result.url).toEqual(card.url);
});
});