import { describe, it, expect } from 'vitest';
import { pickMediaUrl } from './data-mode-store';

const upload = {
	id: 'abc-123',
	preview_url: '/api/v1/upload/abc-123/preview',
	thumbnail_url: '/api/v1/upload/abc-123/thumbnail'
};

describe('pickMediaUrl', () => {
	it('original mode → the original API route, ignoring preview/thumbnail', () => {
		expect(pickMediaUrl('original', upload)).toBe('/api/v1/upload/abc-123/original');
	});

	it('saver mode → preview_url when present', () => {
		expect(pickMediaUrl('saver', upload)).toBe('/api/v1/upload/abc-123/preview');
	});

	it('saver mode → thumbnail_url when preview is null', () => {
		expect(pickMediaUrl('saver', { ...upload, preview_url: null })).toBe(
			'/api/v1/upload/abc-123/thumbnail'
		);
	});

	it('saver mode → original route when both preview and thumbnail are null', () => {
		expect(pickMediaUrl('saver', { id: 'x', preview_url: null, thumbnail_url: null })).toBe(
			'/api/v1/upload/x/original'
		);
	});
});
