fix(watchlist): TV country full name + tmdb_rating precision rounding
TMDB's origin_country returns ISO codes (KR), not full names, causing a vault regression from South Korea to KR. buildRecord now prefers production_countries[0].name, falling back to the raw origin_country code only when absent. TMDB also now returns vote_average at full precision (6.537), causing mass diff noise against the vault's 1-decimal convention and spurious rewrites on precision drift alone. tmdb_rating is now rounded to 1 decimal place. Loki fixture updated to realistic TMDB shapes (ISO country code + production_countries) to catch this regression going forward.
This commit is contained in:
parent
fb3f52e4b0
commit
e0e0462836
3 changed files with 38 additions and 4 deletions
|
|
@ -117,8 +117,9 @@ export function buildRecord(details: TmdbDetail, isMovie: boolean, prev: Record<
|
||||||
runtime = rt.length > 0 ? rt[0] : null;
|
runtime = rt.length > 0 ? rt[0] : null;
|
||||||
status = details.status ?? '';
|
status = details.status ?? '';
|
||||||
contentRating = usCertFromContentRatings(details.content_ratings ?? {});
|
contentRating = usCertFromContentRatings(details.content_ratings ?? {});
|
||||||
const countries: string[] = details.origin_country ?? [];
|
const prodCountries: any[] = details.production_countries ?? [];
|
||||||
country = countries[0] ?? '';
|
const originCountries: string[] = details.origin_country ?? [];
|
||||||
|
country = prodCountries[0]?.name ?? originCountries[0] ?? '';
|
||||||
seasons = details.number_of_seasons ?? null;
|
seasons = details.number_of_seasons ?? null;
|
||||||
episodes = details.number_of_episodes ?? null;
|
episodes = details.number_of_episodes ?? null;
|
||||||
vod = (details.networks ?? []).map((n: any) => n.name);
|
vod = (details.networks ?? []).map((n: any) => n.name);
|
||||||
|
|
@ -166,7 +167,7 @@ export function buildRecord(details: TmdbDetail, isMovie: boolean, prev: Record<
|
||||||
watchStatus, rating, ratingStars,
|
watchStatus, rating, ratingStars,
|
||||||
year: yearDisp, runtime, seasons, episodes, vod, genre: genres, status,
|
year: yearDisp, runtime, seasons, episodes, vod, genre: genres, status,
|
||||||
language, country, director, writer, producer, contentRating,
|
language, country, director, writer, producer, contentRating,
|
||||||
tmdbRating: details.vote_average ?? null, tmdbId: String(details.id),
|
tmdbRating: details.vote_average != null ? Math.round(details.vote_average * 10) / 10 : null, tmdbId: String(details.id),
|
||||||
imdbId, releaseDate, lastAirDate, nextAirDate, lastEpisode, upcomingEpisode: upEpisode,
|
imdbId, releaseDate, lastAirDate, nextAirDate, lastEpisode, upcomingEpisode: upEpisode,
|
||||||
poster, trailer, homepage: details.homepage ?? '',
|
poster, trailer, homepage: details.homepage ?? '',
|
||||||
imdbPage: imdbId ? `https://www.imdb.com/title/${imdbId}/` : '',
|
imdbPage: imdbId ? `https://www.imdb.com/title/${imdbId}/` : '',
|
||||||
|
|
|
||||||
8
tests/fixtures/tmdb-tv-loki.json
vendored
8
tests/fixtures/tmdb-tv-loki.json
vendored
|
|
@ -33,7 +33,13 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"origin_country": [
|
"origin_country": [
|
||||||
"United States of America"
|
"US"
|
||||||
|
],
|
||||||
|
"production_countries": [
|
||||||
|
{
|
||||||
|
"iso_3166_1": "US",
|
||||||
|
"name": "United States of America"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"created_by": [
|
"created_by": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,33 @@ describe('TV crew preservation', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('TV country derivation', () => {
|
||||||
|
test('prefers production_countries full name over raw origin_country code', () => {
|
||||||
|
const r = buildRecord(tvDetail, false, EMPTY_PREV);
|
||||||
|
expect(r.country).toBe('United States of America');
|
||||||
|
});
|
||||||
|
test('no production_countries → falls back to raw origin_country code', () => {
|
||||||
|
const { production_countries, ...noProdCountries } = tvDetail as any;
|
||||||
|
const r = buildRecord(noProdCountries, false, EMPTY_PREV);
|
||||||
|
expect(r.country).toBe('US');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('tmdb_rating rounding', () => {
|
||||||
|
test('6.537 → 6.5', () => {
|
||||||
|
expect(buildRecord({ ...tvDetail, vote_average: 6.537 }, false, EMPTY_PREV).tmdbRating).toBe(6.5);
|
||||||
|
});
|
||||||
|
test('7.854 → 7.9', () => {
|
||||||
|
expect(buildRecord({ ...tvDetail, vote_average: 7.854 }, false, EMPTY_PREV).tmdbRating).toBe(7.9);
|
||||||
|
});
|
||||||
|
test('8.2 → 8.2 (unaffected)', () => {
|
||||||
|
expect(buildRecord(tvDetail, false, EMPTY_PREV).tmdbRating).toBe(8.2);
|
||||||
|
});
|
||||||
|
test('null → null', () => {
|
||||||
|
expect(buildRecord({ ...tvDetail, vote_average: null }, false, EMPTY_PREV).tmdbRating).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('eng_name derivation', () => {
|
describe('eng_name derivation', () => {
|
||||||
test('non-Latin original → engName = localized title', () => {
|
test('non-Latin original → engName = localized title', () => {
|
||||||
const jp = { ...movieDetail, title: 'A Silent Voice: The Movie', original_title: '映画 聲の形' };
|
const jp = { ...movieDetail, title: 'A Silent Voice: The Movie', original_title: '映画 聲の形' };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue