feat(library): generic per-type sync engine + resolve
This commit is contained in:
parent
c14da19c47
commit
278f009a9b
5 changed files with 571 additions and 13 deletions
34
tests/watchlist-patch-frontmatter.test.ts
Normal file
34
tests/watchlist-patch-frontmatter.test.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { describe, expect, test } from 'bun:test';
|
||||
import { patchFrontmatter } from 'packages/obsidian/src/watchlist/patchFrontmatter';
|
||||
|
||||
describe('patchFrontmatter', () => {
|
||||
test('inserts patches right after the type: line when frontmatter exists', () => {
|
||||
const content = '---\ntype: watchlist_item\ntitle: Loki\n---\n\nbody';
|
||||
const out = patchFrontmatter(content, { tmdb_id: '84958', media_type: 'TV Series' });
|
||||
expect(out).toBe('---\ntype: watchlist_item\ntmdb_id: 84958\nmedia_type: TV Series\ntitle: Loki\n---\n\nbody');
|
||||
});
|
||||
|
||||
test('no type: line -> patches prepended before existing frontmatter', () => {
|
||||
const content = '---\ntitle: Loki\n---\n\nbody';
|
||||
const out = patchFrontmatter(content, { tmdb_id: '1' });
|
||||
expect(out).toBe('---\ntmdb_id: 1\ntitle: Loki\n---\n\nbody');
|
||||
});
|
||||
|
||||
test('no frontmatter at all -> creates block with defaultType', () => {
|
||||
const content = '# Loki\n\nbody';
|
||||
const out = patchFrontmatter(content, { tmdb_id: '1' }, { defaultType: 'watchlist_item' });
|
||||
expect(out).toBe('---\ntype: watchlist_item\ntmdb_id: 1\n---\n\n# Loki\n\nbody');
|
||||
});
|
||||
|
||||
test('no frontmatter, no defaultType -> no type line inserted', () => {
|
||||
const content = 'body only';
|
||||
const out = patchFrontmatter(content, { mal_id: '5' });
|
||||
expect(out).toBe('---\nmal_id: 5\n---\n\nbody only');
|
||||
});
|
||||
|
||||
test('multiple patch keys preserve insertion order', () => {
|
||||
const content = '---\ntype: manga_item\n---\n';
|
||||
const out = patchFrontmatter(content, { mal_id: '5', mangadex_id: 'abc' });
|
||||
expect(out).toContain('mal_id: 5\nmangadex_id: abc');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue