58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { CategoryIconViewDataBuilder } from './CategoryIconViewDataBuilder';
|
|
import type { GetMediaOutputDTO } from '@/lib/types/generated/GetMediaOutputDTO';
|
|
|
|
describe('CategoryIconViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform binary data to CategoryIconViewData correctly', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto = {
|
|
id: '1',
|
|
url: 'http://example.com/icon.png',
|
|
type: 'image/png',
|
|
uploadedAt: new Date().toISOString(),
|
|
buffer: buffer.buffer,
|
|
} as unknown as GetMediaOutputDTO;
|
|
|
|
const result = CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle SVG icons', () => {
|
|
const buffer = new TextEncoder().encode('<svg xmlns="http://www.w3.org/2000/svg"><circle cx="10" cy="10" r="5"/></svg>');
|
|
const mediaDto = {
|
|
id: '2',
|
|
url: 'http://example.com/icon.svg',
|
|
type: 'image/svg+xml',
|
|
uploadedAt: new Date().toISOString(),
|
|
buffer: buffer.buffer,
|
|
} as unknown as GetMediaOutputDTO;
|
|
|
|
const result = CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/svg+xml');
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty buffer', () => {
|
|
const buffer = new Uint8Array([]);
|
|
const mediaDto = {
|
|
id: '3',
|
|
url: 'http://example.com/icon.png',
|
|
type: 'image/png',
|
|
uploadedAt: new Date().toISOString(),
|
|
buffer: buffer.buffer,
|
|
} as unknown as GetMediaOutputDTO;
|
|
|
|
const result = CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe('');
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
});
|
|
});
|