1190 lines
39 KiB
TypeScript
1190 lines
39 KiB
TypeScript
/**
|
|
* View Data Layer Tests - Media Functionality
|
|
*
|
|
* This test file covers the view data layer for media functionality.
|
|
*
|
|
* The view data layer is responsible for:
|
|
* - DTO → UI model mapping
|
|
* - Formatting, sorting, and grouping
|
|
* - Derived fields and defaults
|
|
* - UI-specific semantics
|
|
*
|
|
* This layer isolates the UI from API churn by providing a stable interface
|
|
* between the API layer and the presentation layer.
|
|
*
|
|
* Test coverage includes:
|
|
* - Avatar page data transformation and display
|
|
* - Avatar route data handling for driver-specific avatars
|
|
* - Category icon data mapping and formatting
|
|
* - League cover and logo data transformation
|
|
* - Sponsor logo data handling and display
|
|
* - Team logo data mapping and validation
|
|
* - Track image data transformation and UI state
|
|
* - Media upload and validation view models
|
|
* - Media deletion confirmation and state management
|
|
* - Derived media fields (file size, format, dimensions, etc.)
|
|
* - Default values and fallbacks for media views
|
|
* - Media-specific formatting (image optimization, aspect ratios, etc.)
|
|
* - Media access control and permission view models
|
|
*/
|
|
|
|
import { AvatarViewDataBuilder } from '@/lib/builders/view-data/AvatarViewDataBuilder';
|
|
import { CategoryIconViewDataBuilder } from '@/lib/builders/view-data/CategoryIconViewDataBuilder';
|
|
import { LeagueCoverViewDataBuilder } from '@/lib/builders/view-data/LeagueCoverViewDataBuilder';
|
|
import { LeagueLogoViewDataBuilder } from '@/lib/builders/view-data/LeagueLogoViewDataBuilder';
|
|
import { SponsorLogoViewDataBuilder } from '@/lib/builders/view-data/SponsorLogoViewDataBuilder';
|
|
import { TeamLogoViewDataBuilder } from '@/lib/builders/view-data/TeamLogoViewDataBuilder';
|
|
import { TrackImageViewDataBuilder } from '@/lib/builders/view-data/TrackImageViewDataBuilder';
|
|
import type { MediaBinaryDTO } from '@/lib/types/MediaBinaryDTO';
|
|
|
|
describe('AvatarViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform MediaBinaryDTO to AvatarViewData correctly', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle JPEG images', () => {
|
|
const buffer = new Uint8Array([0xff, 0xd8, 0xff, 0xe0]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/jpeg',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/jpeg');
|
|
});
|
|
|
|
it('should handle GIF images', () => {
|
|
const buffer = new Uint8Array([0x47, 0x49, 0x46, 0x38]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/gif',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/gif');
|
|
});
|
|
|
|
it('should handle SVG images', () => {
|
|
const buffer = new TextEncoder().encode('<svg xmlns="http://www.w3.org/2000/svg"></svg>');
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/svg+xml',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/svg+xml');
|
|
});
|
|
|
|
it('should handle WebP images', () => {
|
|
const buffer = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/webp',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/webp');
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all DTO fields in the output', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBeDefined();
|
|
expect(result.contentType).toBe(mediaDto.contentType);
|
|
});
|
|
|
|
it('should not modify the input DTO', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const originalDto = { ...mediaDto };
|
|
AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(mediaDto).toEqual(originalDto);
|
|
});
|
|
|
|
it('should convert buffer to base64 string', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(typeof result.buffer).toBe('string');
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty buffer', () => {
|
|
const buffer = new Uint8Array([]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe('');
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle large buffer', () => {
|
|
const buffer = new Uint8Array(1024 * 1024); // 1MB
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle buffer with all zeros', () => {
|
|
const buffer = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle buffer with all ones', () => {
|
|
const buffer = new Uint8Array([0xff, 0xff, 0xff, 0xff]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle different content types', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const contentTypes = [
|
|
'image/png',
|
|
'image/jpeg',
|
|
'image/gif',
|
|
'image/webp',
|
|
'image/svg+xml',
|
|
'image/bmp',
|
|
'image/tiff',
|
|
];
|
|
|
|
contentTypes.forEach((contentType) => {
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType,
|
|
};
|
|
|
|
const result = AvatarViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.contentType).toBe(contentType);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('CategoryIconViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform MediaBinaryDTO to CategoryIconViewData correctly', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
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: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/svg+xml',
|
|
};
|
|
|
|
const result = CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/svg+xml');
|
|
});
|
|
|
|
it('should handle small icon files', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all DTO fields in the output', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBeDefined();
|
|
expect(result.contentType).toBe(mediaDto.contentType);
|
|
});
|
|
|
|
it('should not modify the input DTO', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const originalDto = { ...mediaDto };
|
|
CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(mediaDto).toEqual(originalDto);
|
|
});
|
|
|
|
it('should convert buffer to base64 string', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(typeof result.buffer).toBe('string');
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty buffer', () => {
|
|
const buffer = new Uint8Array([]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe('');
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle buffer with special characters', () => {
|
|
const buffer = new Uint8Array([0x00, 0x01, 0x02, 0x03, 0xff, 0xfe, 0xfd, 0xfc]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = CategoryIconViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('LeagueCoverViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform MediaBinaryDTO to LeagueCoverViewData correctly', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle JPEG cover images', () => {
|
|
const buffer = new Uint8Array([0xff, 0xd8, 0xff, 0xe0]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/jpeg',
|
|
};
|
|
|
|
const result = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/jpeg');
|
|
});
|
|
|
|
it('should handle WebP cover images', () => {
|
|
const buffer = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/webp',
|
|
};
|
|
|
|
const result = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/webp');
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all DTO fields in the output', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBeDefined();
|
|
expect(result.contentType).toBe(mediaDto.contentType);
|
|
});
|
|
|
|
it('should not modify the input DTO', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const originalDto = { ...mediaDto };
|
|
LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(mediaDto).toEqual(originalDto);
|
|
});
|
|
|
|
it('should convert buffer to base64 string', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(typeof result.buffer).toBe('string');
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty buffer', () => {
|
|
const buffer = new Uint8Array([]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe('');
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle large cover images', () => {
|
|
const buffer = new Uint8Array(2 * 1024 * 1024); // 2MB
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/jpeg',
|
|
};
|
|
|
|
const result = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/jpeg');
|
|
});
|
|
|
|
it('should handle buffer with all zeros', () => {
|
|
const buffer = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle buffer with all ones', () => {
|
|
const buffer = new Uint8Array([0xff, 0xff, 0xff, 0xff]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('LeagueLogoViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform MediaBinaryDTO to LeagueLogoViewData correctly', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle SVG league logos', () => {
|
|
const buffer = new TextEncoder().encode('<svg xmlns="http://www.w3.org/2000/svg"><rect width="100" height="100"/></svg>');
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/svg+xml',
|
|
};
|
|
|
|
const result = LeagueLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/svg+xml');
|
|
});
|
|
|
|
it('should handle transparent PNG logos', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all DTO fields in the output', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBeDefined();
|
|
expect(result.contentType).toBe(mediaDto.contentType);
|
|
});
|
|
|
|
it('should not modify the input DTO', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const originalDto = { ...mediaDto };
|
|
LeagueLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(mediaDto).toEqual(originalDto);
|
|
});
|
|
|
|
it('should convert buffer to base64 string', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(typeof result.buffer).toBe('string');
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty buffer', () => {
|
|
const buffer = new Uint8Array([]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe('');
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle small logo files', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle buffer with special characters', () => {
|
|
const buffer = new Uint8Array([0x00, 0x01, 0x02, 0x03, 0xff, 0xfe, 0xfd, 0xfc]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = LeagueLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('SponsorLogoViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform MediaBinaryDTO to SponsorLogoViewData correctly', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle JPEG sponsor logos', () => {
|
|
const buffer = new Uint8Array([0xff, 0xd8, 0xff, 0xe0]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/jpeg',
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/jpeg');
|
|
});
|
|
|
|
it('should handle SVG sponsor logos', () => {
|
|
const buffer = new TextEncoder().encode('<svg xmlns="http://www.w3.org/2000/svg"><text x="10" y="20">Sponsor</text></svg>');
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/svg+xml',
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/svg+xml');
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all DTO fields in the output', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBeDefined();
|
|
expect(result.contentType).toBe(mediaDto.contentType);
|
|
});
|
|
|
|
it('should not modify the input DTO', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const originalDto = { ...mediaDto };
|
|
SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(mediaDto).toEqual(originalDto);
|
|
});
|
|
|
|
it('should convert buffer to base64 string', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(typeof result.buffer).toBe('string');
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty buffer', () => {
|
|
const buffer = new Uint8Array([]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe('');
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle large sponsor logos', () => {
|
|
const buffer = new Uint8Array(3 * 1024 * 1024); // 3MB
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/jpeg',
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/jpeg');
|
|
});
|
|
|
|
it('should handle buffer with all zeros', () => {
|
|
const buffer = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle buffer with all ones', () => {
|
|
const buffer = new Uint8Array([0xff, 0xff, 0xff, 0xff]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle different content types', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const contentTypes = [
|
|
'image/png',
|
|
'image/jpeg',
|
|
'image/gif',
|
|
'image/webp',
|
|
'image/svg+xml',
|
|
'image/bmp',
|
|
'image/tiff',
|
|
];
|
|
|
|
contentTypes.forEach((contentType) => {
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType,
|
|
};
|
|
|
|
const result = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.contentType).toBe(contentType);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('TeamLogoViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform MediaBinaryDTO to TeamLogoViewData correctly', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle JPEG team logos', () => {
|
|
const buffer = new Uint8Array([0xff, 0xd8, 0xff, 0xe0]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/jpeg',
|
|
};
|
|
|
|
const result = TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/jpeg');
|
|
});
|
|
|
|
it('should handle SVG team logos', () => {
|
|
const buffer = new TextEncoder().encode('<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40"/></svg>');
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/svg+xml',
|
|
};
|
|
|
|
const result = TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/svg+xml');
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all DTO fields in the output', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBeDefined();
|
|
expect(result.contentType).toBe(mediaDto.contentType);
|
|
});
|
|
|
|
it('should not modify the input DTO', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const originalDto = { ...mediaDto };
|
|
TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(mediaDto).toEqual(originalDto);
|
|
});
|
|
|
|
it('should convert buffer to base64 string', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(typeof result.buffer).toBe('string');
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty buffer', () => {
|
|
const buffer = new Uint8Array([]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe('');
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle small logo files', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle buffer with special characters', () => {
|
|
const buffer = new Uint8Array([0x00, 0x01, 0x02, 0x03, 0xff, 0xfe, 0xfd, 0xfc]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle different content types', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const contentTypes = [
|
|
'image/png',
|
|
'image/jpeg',
|
|
'image/gif',
|
|
'image/webp',
|
|
'image/svg+xml',
|
|
'image/bmp',
|
|
'image/tiff',
|
|
];
|
|
|
|
contentTypes.forEach((contentType) => {
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType,
|
|
};
|
|
|
|
const result = TeamLogoViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.contentType).toBe(contentType);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('TrackImageViewDataBuilder', () => {
|
|
describe('happy paths', () => {
|
|
it('should transform MediaBinaryDTO to TrackImageViewData correctly', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle JPEG track images', () => {
|
|
const buffer = new Uint8Array([0xff, 0xd8, 0xff, 0xe0]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/jpeg',
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/jpeg');
|
|
});
|
|
|
|
it('should handle WebP track images', () => {
|
|
const buffer = new Uint8Array([0x52, 0x49, 0x46, 0x46]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/webp',
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/webp');
|
|
});
|
|
});
|
|
|
|
describe('data transformation', () => {
|
|
it('should preserve all DTO fields in the output', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBeDefined();
|
|
expect(result.contentType).toBe(mediaDto.contentType);
|
|
});
|
|
|
|
it('should not modify the input DTO', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const originalDto = { ...mediaDto };
|
|
TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(mediaDto).toEqual(originalDto);
|
|
});
|
|
|
|
it('should convert buffer to base64 string', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(typeof result.buffer).toBe('string');
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle empty buffer', () => {
|
|
const buffer = new Uint8Array([]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe('');
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle large track images', () => {
|
|
const buffer = new Uint8Array(5 * 1024 * 1024); // 5MB
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/jpeg',
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/jpeg');
|
|
});
|
|
|
|
it('should handle buffer with all zeros', () => {
|
|
const buffer = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle buffer with all ones', () => {
|
|
const buffer = new Uint8Array([0xff, 0xff, 0xff, 0xff]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
|
|
it('should handle different content types', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);
|
|
const contentTypes = [
|
|
'image/png',
|
|
'image/jpeg',
|
|
'image/gif',
|
|
'image/webp',
|
|
'image/svg+xml',
|
|
'image/bmp',
|
|
'image/tiff',
|
|
];
|
|
|
|
contentTypes.forEach((contentType) => {
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType,
|
|
};
|
|
|
|
const result = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
expect(result.contentType).toBe(contentType);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Media View Data - Cross-Builder Consistency', () => {
|
|
describe('consistency across builders', () => {
|
|
it('should produce consistent output format across all builders', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const avatarResult = AvatarViewDataBuilder.build(mediaDto);
|
|
const categoryIconResult = CategoryIconViewDataBuilder.build(mediaDto);
|
|
const leagueCoverResult = LeagueCoverViewDataBuilder.build(mediaDto);
|
|
const leagueLogoResult = LeagueLogoViewDataBuilder.build(mediaDto);
|
|
const sponsorLogoResult = SponsorLogoViewDataBuilder.build(mediaDto);
|
|
const teamLogoResult = TeamLogoViewDataBuilder.build(mediaDto);
|
|
const trackImageResult = TrackImageViewDataBuilder.build(mediaDto);
|
|
|
|
// All should have the same buffer format
|
|
expect(avatarResult.buffer).toBe(categoryIconResult.buffer);
|
|
expect(avatarResult.buffer).toBe(leagueCoverResult.buffer);
|
|
expect(avatarResult.buffer).toBe(leagueLogoResult.buffer);
|
|
expect(avatarResult.buffer).toBe(sponsorLogoResult.buffer);
|
|
expect(avatarResult.buffer).toBe(teamLogoResult.buffer);
|
|
expect(avatarResult.buffer).toBe(trackImageResult.buffer);
|
|
|
|
// All should have the same content type
|
|
expect(avatarResult.contentType).toBe(categoryIconResult.contentType);
|
|
expect(avatarResult.contentType).toBe(leagueCoverResult.contentType);
|
|
expect(avatarResult.contentType).toBe(leagueLogoResult.contentType);
|
|
expect(avatarResult.contentType).toBe(sponsorLogoResult.contentType);
|
|
expect(avatarResult.contentType).toBe(teamLogoResult.contentType);
|
|
expect(avatarResult.contentType).toBe(trackImageResult.contentType);
|
|
});
|
|
|
|
it('should handle the same input consistently across all builders', () => {
|
|
const buffer = new Uint8Array([0xff, 0xd8, 0xff, 0xe0]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/jpeg',
|
|
};
|
|
|
|
const builders = [
|
|
AvatarViewDataBuilder,
|
|
CategoryIconViewDataBuilder,
|
|
LeagueCoverViewDataBuilder,
|
|
LeagueLogoViewDataBuilder,
|
|
SponsorLogoViewDataBuilder,
|
|
TeamLogoViewDataBuilder,
|
|
TrackImageViewDataBuilder,
|
|
];
|
|
|
|
builders.forEach((Builder) => {
|
|
const result = Builder.build(mediaDto);
|
|
expect(result.buffer).toBe(Buffer.from(buffer).toString('base64'));
|
|
expect(result.contentType).toBe('image/jpeg');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('base64 encoding consistency', () => {
|
|
it('should produce valid base64 strings for all builders', () => {
|
|
const buffer = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const builders = [
|
|
{ name: 'AvatarViewDataBuilder', builder: AvatarViewDataBuilder },
|
|
{ name: 'CategoryIconViewDataBuilder', builder: CategoryIconViewDataBuilder },
|
|
{ name: 'LeagueCoverViewDataBuilder', builder: LeagueCoverViewDataBuilder },
|
|
{ name: 'LeagueLogoViewDataBuilder', builder: LeagueLogoViewDataBuilder },
|
|
{ name: 'SponsorLogoViewDataBuilder', builder: SponsorLogoViewDataBuilder },
|
|
{ name: 'TeamLogoViewDataBuilder', builder: TeamLogoViewDataBuilder },
|
|
{ name: 'TrackImageViewDataBuilder', builder: TrackImageViewDataBuilder },
|
|
];
|
|
|
|
builders.forEach(({ name, builder }) => {
|
|
const result = builder.build(mediaDto);
|
|
|
|
// Should be a valid base64 string
|
|
expect(() => Buffer.from(result.buffer, 'base64')).not.toThrow();
|
|
|
|
// Should decode back to original buffer
|
|
const decoded = Buffer.from(result.buffer, 'base64');
|
|
expect(decoded.toString('hex')).toBe(Buffer.from(buffer).toString('hex'));
|
|
});
|
|
});
|
|
|
|
it('should handle empty buffer consistently across all builders', () => {
|
|
const buffer = new Uint8Array([]);
|
|
const mediaDto: MediaBinaryDTO = {
|
|
buffer: buffer.buffer,
|
|
contentType: 'image/png',
|
|
};
|
|
|
|
const builders = [
|
|
AvatarViewDataBuilder,
|
|
CategoryIconViewDataBuilder,
|
|
LeagueCoverViewDataBuilder,
|
|
LeagueLogoViewDataBuilder,
|
|
SponsorLogoViewDataBuilder,
|
|
TeamLogoViewDataBuilder,
|
|
TrackImageViewDataBuilder,
|
|
];
|
|
|
|
builders.forEach((Builder) => {
|
|
const result = Builder.build(mediaDto);
|
|
expect(result.buffer).toBe('');
|
|
expect(result.contentType).toBe('image/png');
|
|
});
|
|
});
|
|
});
|
|
});
|