import { describe, expect, it } from 'vitest' import { optimizeMessagingAttachmentUrl } from './cdnImageUrl' describe('optimizeMessagingAttachmentUrl', () => { it('optimizes Linktree-owned asset hosts', () => { expect( optimizeMessagingAttachmentUrl('https://assets.linktr.ee/photo.jpg') ).toBe( 'https://assets.linktr.ee/photo.jpg?io=true&size=messaging-attachment-v1_0' ) }) it('does not optimize unrelated CloudFront hosts', () => { expect( optimizeMessagingAttachmentUrl( 'https://d111111abcdef8.cloudfront.net/photo.jpg' ) ).toBe('https://d111111abcdef8.cloudfront.net/photo.jpg') }) it('does not optimize unrelated Cloudinary hosts', () => { expect( optimizeMessagingAttachmentUrl( 'https://res.cloudinary.com/demo/image/upload/sample.jpg' ) ).toBe('https://res.cloudinary.com/demo/image/upload/sample.jpg') }) it('does not append the preset twice', () => { expect( optimizeMessagingAttachmentUrl( 'https://ugc.production.linktr.ee/photo.jpg?io=true&size=messaging-attachment-v1_0' ) ).toBe( 'https://ugc.production.linktr.ee/photo.jpg?io=true&size=messaging-attachment-v1_0' ) }) it('replaces a different optimized size preset on Linktree hosts', () => { expect( optimizeMessagingAttachmentUrl( 'https://ugc.production.linktr.ee/photo.jpg?io=true&size=avatar-v1_0' ) ).toBe( 'https://ugc.production.linktr.ee/photo.jpg?io=true&size=messaging-attachment-v1_0' ) }) it('preserves unrelated query params when replacing an existing size preset', () => { expect( optimizeMessagingAttachmentUrl( 'https://ugc.production.linktr.ee/photo.jpg?token=abc&size=preview-v2_0&io=true' ) ).toBe( 'https://ugc.production.linktr.ee/photo.jpg?token=abc&size=messaging-attachment-v1_0&io=true' ) }) })