fix(watchlist): strip surrounding quotes from prev user fields (notion_url round-trip)
This commit is contained in:
parent
eeaa37469c
commit
e8cb9b93fe
3 changed files with 16 additions and 5 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import type { WatchlistRecord } from 'packages/obsidian/src/watchlist/schema';
|
import type { WatchlistRecord } from 'packages/obsidian/src/watchlist/schema';
|
||||||
|
import { stripQuotes } from 'packages/obsidian/src/watchlist/parse';
|
||||||
|
|
||||||
export type TmdbDetail = Record<string, any>;
|
export type TmdbDetail = Record<string, any>;
|
||||||
|
|
||||||
|
|
@ -136,10 +137,10 @@ export function buildRecord(details: TmdbDetail, isMovie: boolean, prev: Record<
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- preserve user-managed fields ----
|
// ---- preserve user-managed fields ----
|
||||||
let watchStatus = prev['watch_status'] || 'Unwatched';
|
let watchStatus = stripQuotes(prev['watch_status']) || 'Unwatched';
|
||||||
const rating = prev['rating'] || '0';
|
const rating = stripQuotes(prev['rating']) || '0';
|
||||||
const ratingStars = prev['rating_stars'] ?? '';
|
const ratingStars = stripQuotes(prev['rating_stars']);
|
||||||
const rawNotionUrl = prev['notion_url'] || '';
|
const rawNotionUrl = stripQuotes(prev['notion_url']);
|
||||||
const notionUrl = rawNotionUrl === 'null' ? '' : rawNotionUrl; // quotedOrNull renders empty as literal `null` — don't round-trip it as a value
|
const notionUrl = rawNotionUrl === 'null' ? '' : rawNotionUrl; // quotedOrNull renders empty as literal `null` — don't round-trip it as a value
|
||||||
|
|
||||||
// ---- TV watch-status rule: new episode aired since last sync ----
|
// ---- TV watch-status rule: new episode aired since last sync ----
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ export function extractMyNotes(body: string): string {
|
||||||
return m ? m[1].trim() : '';
|
return m ? m[1].trim() : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function stripQuotes(s: string | undefined): string {
|
export function stripQuotes(s: string | undefined): string {
|
||||||
return (s ?? '').trim().replace(/^"|"$/g, '');
|
return (s ?? '').trim().replace(/^"|"$/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,16 @@ describe('user-field preservation', () => {
|
||||||
expect(r.ratingStars).toBe('⭐️⭐️⭐️⭐️');
|
expect(r.ratingStars).toBe('⭐️⭐️⭐️⭐️');
|
||||||
expect(r.notionUrl).toBe('https://notion.so/x');
|
expect(r.notionUrl).toBe('https://notion.so/x');
|
||||||
});
|
});
|
||||||
|
test('quoted notion_url from raw frontmatter capture → quotes stripped', () => {
|
||||||
|
const prev = { notion_url: '"https://www.notion.so/x"' };
|
||||||
|
const r = buildRecord(tvDetail, false, prev);
|
||||||
|
expect(r.notionUrl).toBe('https://www.notion.so/x');
|
||||||
|
});
|
||||||
|
test('null-sentinel notion_url still normalizes to empty', () => {
|
||||||
|
const prev = { notion_url: 'null' };
|
||||||
|
const r = buildRecord(tvDetail, false, prev);
|
||||||
|
expect(r.notionUrl).toBe('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('watch-status rule (TV)', () => {
|
describe('watch-status rule (TV)', () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue