9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
58 lines
2.0 KiB
JavaScript
58 lines
2.0 KiB
JavaScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { formatDuration, formatDate, itunesFetch } from './utils.js';
|
|
describe('formatDuration', () => {
|
|
it('formats typical duration in ms', () => {
|
|
expect(formatDuration(3661000)).toBe('61:01');
|
|
});
|
|
it('pads single-digit seconds', () => {
|
|
expect(formatDuration(65000)).toBe('1:05');
|
|
});
|
|
it('formats exact minutes', () => {
|
|
expect(formatDuration(3600000)).toBe('60:00');
|
|
});
|
|
it('rounds fractional milliseconds', () => {
|
|
expect(formatDuration(3600500)).toBe('60:01');
|
|
});
|
|
it('returns dash for zero', () => {
|
|
expect(formatDuration(0)).toBe('-');
|
|
});
|
|
it('returns dash for NaN', () => {
|
|
expect(formatDuration(NaN)).toBe('-');
|
|
});
|
|
});
|
|
describe('formatDate', () => {
|
|
it('extracts YYYY-MM-DD from ISO string', () => {
|
|
expect(formatDate('2026-03-19T12:00:00.000Z')).toBe('2026-03-19');
|
|
});
|
|
it('handles date-only string', () => {
|
|
expect(formatDate('2025-01-01')).toBe('2025-01-01');
|
|
});
|
|
it('returns dash for empty string', () => {
|
|
expect(formatDate('')).toBe('-');
|
|
});
|
|
it('returns dash for undefined', () => {
|
|
expect(formatDate(undefined)).toBe('-');
|
|
});
|
|
});
|
|
describe('itunesFetch', () => {
|
|
beforeEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
it('returns parsed JSON on success', async () => {
|
|
const mockData = { resultCount: 1, results: [{ collectionId: 123 }] };
|
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
|
|
ok: true,
|
|
json: () => Promise.resolve(mockData),
|
|
}));
|
|
const result = await itunesFetch('/search?term=test&media=podcast&limit=1');
|
|
expect(result).toEqual(mockData);
|
|
});
|
|
it('throws CliError on HTTP error', async () => {
|
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
|
|
ok: false,
|
|
status: 403,
|
|
}));
|
|
await expect(itunesFetch('/search?term=test')).rejects.toThrow('iTunes API HTTP 403');
|
|
});
|
|
});
|