Files
jackwener__opencli/clis/linkedin/timeline.test.ts
jackwener 314bc6f231 refactor: simplify core modules — remove root shims, consolidate error classification, streamline cascade/interceptor, clean up synthesize
1. Remove root-level shim files (errors.ts, logger.ts, registry.ts, types.ts, utils.ts, launcher.ts) — update all ~840 adapter imports to reference src/ directly
2. Consolidate interceptor: reuse shared DISGUISE_FN in tap interceptor instead of reimplementing
3. Unify error classification: single ClassifiedError type with icon/exitCode/hint lookup table, eliminating duplicated pattern matching between resolveExitCode and renderError
4. Simplify cascade probe: replace repetitive switch cases with PROBE_OPTIONS lookup map
12. Clean up synthesize.ts: remove deprecated snake_case field aliases (recommended_args, recommended_columns, recommendedColumnsLegacy) and unnecessary constant aliases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-05 03:06:47 +08:00

100 lines
2.7 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { getRegistry } from '../../src/registry.js';
import './timeline.js';
const { parseMetric, buildPostId, mergeTimelinePosts } = await import('./timeline.js').then(
(m) => (m as any).__test__,
);
describe('linkedin timeline adapter', () => {
const command = getRegistry().get('linkedin/timeline');
it('registers the command with correct shape', () => {
expect(command).toBeDefined();
expect(command!.site).toBe('linkedin');
expect(command!.name).toBe('timeline');
expect(command!.domain).toBe('www.linkedin.com');
expect(command!.strategy).toBe('cookie');
expect(command!.browser).toBe(true);
expect(typeof command!.func).toBe('function');
});
it('has limit arg with default 20', () => {
const limitArg = command!.args.find((a) => a.name === 'limit');
expect(limitArg).toBeDefined();
expect(limitArg!.default).toBe(20);
});
it('includes expected columns', () => {
expect(command!.columns).toEqual(
expect.arrayContaining(['author', 'text', 'reactions', 'comments', 'url']),
);
});
});
describe('parseMetric', () => {
it('parses plain numbers', () => {
expect(parseMetric('42')).toBe(42);
expect(parseMetric('1,234')).toBe(1234);
});
it('handles k/m suffixes', () => {
expect(parseMetric('2.5k')).toBe(2500);
expect(parseMetric('1.2M')).toBe(1200000);
});
it('returns 0 for empty/undefined', () => {
expect(parseMetric('')).toBe(0);
expect(parseMetric(undefined)).toBe(0);
expect(parseMetric(null)).toBe(0);
});
});
describe('buildPostId', () => {
it('uses url when present', () => {
expect(buildPostId({ url: 'https://linkedin.com/post/123' })).toBe(
'https://linkedin.com/post/123',
);
});
it('falls back to composite key', () => {
const id = buildPostId({ author: 'Alice', posted_at: '2h', text: 'Hello world' });
expect(id).toBe('Alice::2h::Hello world');
});
});
describe('mergeTimelinePosts', () => {
it('deduplicates by url', () => {
const url = 'https://linkedin.com/post/1';
const a = {
id: url,
author: 'Alice',
author_url: '',
headline: '',
text: 'Hello',
posted_at: '1h',
reactions: 5,
comments: 1,
url,
};
const result = mergeTimelinePosts([a], [a]);
expect(result).toHaveLength(1);
});
it('skips posts without author or text', () => {
const empty = {
id: '2',
author: '',
author_url: '',
headline: '',
text: 'some text',
posted_at: '',
reactions: 0,
comments: 0,
url: '',
};
const result = mergeTimelinePosts([], [empty]);
expect(result).toHaveLength(0);
});
});