Files
jackwener__opencli/clis/xiaoyuzhou/utils.test.js
Kagura ab44d9f542 fix(xiaoyuzhou): migrate from broken SSR scraping to authenticated API (fixes #1023) (#1059)
* fix(xiaoyuzhou): migrate from broken SSR scraping to authenticated API (fixes #1023)

Xiaoyuzhou removed SSR rendering — /podcast/<id> and /episode/<id> pages
now return 404, breaking fetchPageProps() which scraped __NEXT_DATA__.

Migrate podcast, podcast-episodes, episode, and download commands to use
the existing authenticated API client (requestXiaoyuzhouJson) that
transcript.js already uses successfully.

Changes:
- podcast.js: use /v1/podcast/get API endpoint
- podcast-episodes.js: use /v1/podcast/listEpisode API endpoint
- episode.js: use /v1/episode/get API endpoint
- download.js: use /v1/episode/get API endpoint
- utils.js: remove unused fetchPageProps, keep format helpers
- Update all affected tests (download.test.js, utils.test.js)
- Change strategy from PUBLIC to LOCAL (requires credentials)

* fix(xiaoyuzhou): align local strategy contract

* fix(xiaoyuzhou): align local api metadata

---------

Co-authored-by: jackwener <jakevingoo@gmail.com>
2026-04-16 23:15:40 +08:00

40 lines
1.3 KiB
JavaScript

import { describe, it, expect } from 'vitest';
import { formatDuration, formatDate } from './utils.js';
describe('formatDuration', () => {
it('formats typical duration', () => {
expect(formatDuration(3890)).toBe('64:50');
});
it('formats zero seconds', () => {
expect(formatDuration(0)).toBe('0:00');
});
it('pads single-digit seconds', () => {
expect(formatDuration(62)).toBe('1:02');
});
it('handles exact minutes', () => {
expect(formatDuration(120)).toBe('2:00');
});
it('rounds fractional seconds', () => {
expect(formatDuration(65.7)).toBe('1:06');
});
it('returns dash for NaN', () => {
expect(formatDuration(NaN)).toBe('-');
});
it('returns dash for negative', () => {
expect(formatDuration(-1)).toBe('-');
});
it('returns dash for Infinity', () => {
expect(formatDuration(Infinity)).toBe('-');
});
});
describe('formatDate', () => {
it('slices ISO string to date', () => {
expect(formatDate('2026-03-15T12:00:00Z')).toBe('2026-03-15');
});
it('returns dash for empty string', () => {
expect(formatDate('')).toBe('-');
});
it('returns dash for undefined', () => {
expect(formatDate(undefined)).toBe('-');
});
});