Remove normalizeCard()
This commit is contained in:
parent
54d8d12054
commit
489145ffb8
5 changed files with 11 additions and 41 deletions
|
@ -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('');
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -195,7 +195,6 @@ describe('normalizeStatus()', () => {
|
||||||
const result = normalizeStatus(status);
|
const result = normalizeStatus(status);
|
||||||
const card = result.card as Card;
|
const card = result.card as Card;
|
||||||
|
|
||||||
expect(ImmutableRecord.isRecord(card)).toBe(true);
|
|
||||||
expect(card.type).toEqual('link');
|
expect(card.type).toEqual('link');
|
||||||
expect(card.provider_url).toEqual('https://soapbox.pub');
|
expect(card.provider_url).toEqual('https://soapbox.pub');
|
||||||
});
|
});
|
||||||
|
|
|
@ -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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -4,7 +4,6 @@ export { AdminReportRecord, normalizeAdminReport } from './admin-report';
|
||||||
export { AnnouncementRecord, normalizeAnnouncement } from './announcement';
|
export { AnnouncementRecord, normalizeAnnouncement } from './announcement';
|
||||||
export { AnnouncementReactionRecord, normalizeAnnouncementReaction } from './announcement-reaction';
|
export { AnnouncementReactionRecord, normalizeAnnouncementReaction } from './announcement-reaction';
|
||||||
export { AttachmentRecord, normalizeAttachment } from './attachment';
|
export { AttachmentRecord, normalizeAttachment } from './attachment';
|
||||||
export { normalizeCard } from './card';
|
|
||||||
export { ChatRecord, normalizeChat } from './chat';
|
export { ChatRecord, normalizeChat } from './chat';
|
||||||
export { ChatMessageRecord, normalizeChatMessage } from './chat-message';
|
export { ChatMessageRecord, normalizeChatMessage } from './chat-message';
|
||||||
export { EmojiRecord, normalizeEmoji } from './emoji';
|
export { EmojiRecord, normalizeEmoji } from './emoji';
|
||||||
|
|
11
app/soapbox/schemas/__tests__/card.test.ts
Normal file
11
app/soapbox/schemas/__tests__/card.test.ts
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue