import { DenormalizedExpandedLinkAttachmentResource } from '../../types/resources/denormalized_attachment_resource' import { DenormalizedMessageAttachmentResourceForCreate, DenormalizedGiphyAttachmentResourceForCreate, } from '../../types/resources/denormalized_attachment_resource_for_create' import { convertAttachmentsForCreate } from '../convert_attachments_for_create' describe('convertAttachmentsForCreate', () => { it('converts MessageAttachment correctly', () => { const messageAttachment: DenormalizedMessageAttachmentResourceForCreate = { type: 'MessageAttachment', id: 'test-id', file: { uri: 'file://test.jpg', name: 'test.jpg', type: 'image/jpeg', size: 1024, width: 100, height: 200, }, } const result = convertAttachmentsForCreate([messageAttachment]) expect(result).toHaveLength(1) expect(result[0]).toEqual({ type: 'MessageAttachment', id: 'test-id', attributes: { filename: 'test.jpg', key: '', contentType: 'image/jpeg', byteSize: 1024, checksum: '', url: 'file://test.jpg', metadata: { width: 100, height: 200, analyzed: false, identified: false, }, }, }) }) it('converts GiphyAttachment correctly', () => { const giphyAttachment: DenormalizedGiphyAttachmentResourceForCreate = { type: 'giphy', id: 'giphy-id', title: 'Test GIF', original_giphy_title: 'Original Test GIF', title_link: 'https://giphy.com/test', thumb_url: 'https://giphy.com/thumb.gif', giphy: { original: { url: 'https://giphy.com/original.gif', width: '480', height: '360', size: '1000000', frames: '50', }, fixed_height: { url: 'https://giphy.com/fixed_height.gif', width: '267', height: '200', size: '500000', frames: '50', }, fixed_height_still: { url: 'https://giphy.com/fixed_height_still.gif', width: '267', height: '200', size: '100000', frames: '1', }, fixed_height_downsampled: { url: 'https://giphy.com/fixed_height_downsampled.gif', width: '267', height: '200', size: '300000', frames: '25', }, fixed_width: { url: 'https://giphy.com/fixed_width.gif', width: '200', height: '150', size: '400000', frames: '50', }, fixed_width_still: { url: 'https://giphy.com/fixed_width_still.gif', width: '200', height: '150', size: '80000', frames: '1', }, fixed_width_downsampled: { url: 'https://giphy.com/fixed_width_downsampled.gif', width: '200', height: '150', size: '200000', frames: '25', }, }, } const result = convertAttachmentsForCreate([giphyAttachment]) expect(result).toHaveLength(1) expect(result[0]).toEqual({ type: 'giphy', id: 'giphy-id', title: 'Test GIF', originalGiphyTitle: 'Original Test GIF', titleLink: 'https://giphy.com/test', thumbUrl: 'https://giphy.com/thumb.gif', giphy: { original: giphyAttachment.giphy.original, fixedHeight: giphyAttachment.giphy.fixed_height, fixedHeightStill: giphyAttachment.giphy.fixed_height_still, fixedHeightDownsampled: giphyAttachment.giphy.fixed_height_downsampled, fixedWidth: giphyAttachment.giphy.fixed_width, fixedWidthStill: giphyAttachment.giphy.fixed_width_still, fixedWidthDownsampled: giphyAttachment.giphy.fixed_width_downsampled, }, }) }) it('converts ExpandedLinkAttachment correctly', () => { const expandedLinkAttachment: DenormalizedExpandedLinkAttachmentResource = { type: 'ExpandedLink', attributes: { url: 'https://example.com', title: 'Example Link', description: 'This is an example link', imageUrl: 'https://example.com/image.jpg', imageHeight: 300, imageWidth: 400, }, } const result = convertAttachmentsForCreate([expandedLinkAttachment]) expect(result).toHaveLength(1) expect(result[0]).toEqual(expandedLinkAttachment) }) it('converts mixed attachment types correctly', () => { const messageAttachment: DenormalizedMessageAttachmentResourceForCreate = { type: 'MessageAttachment', id: 'msg-id', file: { uri: 'file://test.jpg', name: 'test.jpg', type: 'image/jpeg', size: 1024, }, } const expandedLinkAttachment: DenormalizedExpandedLinkAttachmentResource = { type: 'ExpandedLink', attributes: { url: 'https://example.com', title: 'Example Link', }, } const result = convertAttachmentsForCreate([messageAttachment, expandedLinkAttachment]) expect(result).toHaveLength(2) expect(result[0].type).toBe('MessageAttachment') expect(result[1].type).toBe('ExpandedLink') expect(result[1]).toEqual(expandedLinkAttachment) }) })