Files
siftlode/frontend/src/lib/plexRating.test.ts
T
peter 9fb4db2546 fix(plex): address S6 code-review — 5 findings
1. (correctness) Show hero rating regression: PlexBrowse's show hero rendered a
   rating only when show.imdb_rating was set, so after the S6 IMDb-only change a
   show with no imdb:// entry showed no rating. Now falls back to the audience
   `rating` like PlexInfo.
2. (correctness) ratingMin column mismatch: the rating filter and the /facets
   rating_max now key off coalesce(imdb_rating, rating) — the SAME "best score"
   the badge displays — so a ratingMin picked from a shown IMDb score narrows the
   right column instead of the raw audience `rating`.
3. (altitude) HU search gap: new query.vector_match() matches EITHER vector in HU
   (or_(search_vector_hu, search_vector)) so a row with no HU twin stays findable
   by its English title; ranking still uses the HU vector. field_recheck unions
   the HU+EN per-field tsvectors in HU, staying a strict subset of the prefilter.
4. (test-coverage) Extracted the badge logic to lib/plexRating.pickRatingBadge
   (shared by PlexInfo + the show hero) with a unit test (imdb-preferred, audience
   fallback, 0-score, none). Backend tests added for the HU union search + the
   IMDb-preferred rating filter.
5. (efficiency) Language switch no longer double-fetches the grid: browseQ is
   gated on a committedLang state that lags `lang` by one render, so the
   genre-clear effect settles into a single fetch instead of one throwaway fetch
   with stale-language genres plus a second.

DB-lane suite 295 passed / 2 skip; FE tsc/knip/lint clean, 217 vitest pass.
2026-08-17 20:41:13 +02:00

23 lines
915 B
TypeScript

import { describe, expect, it } from "vitest";
import { pickRatingBadge } from "./plexRating";
describe("pickRatingBadge", () => {
it("prefers the IMDb score and marks it as IMDb (gets the imdb.com link)", () => {
expect(pickRatingBadge(8.6, 6.0)).toEqual({ score: 8.6, isImdb: true });
});
it("falls back to the audience score without IMDb branding when there's no IMDb score", () => {
expect(pickRatingBadge(null, 7.2)).toEqual({ score: 7.2, isImdb: false });
expect(pickRatingBadge(undefined, 7.2)).toEqual({ score: 7.2, isImdb: false });
});
it("treats a 0 IMDb score as present (not falsy-skipped)", () => {
expect(pickRatingBadge(0, 5)).toEqual({ score: 0, isImdb: true });
});
it("returns null when neither score exists (no badge rendered)", () => {
expect(pickRatingBadge(null, null)).toBeNull();
expect(pickRatingBadge(undefined, undefined)).toBeNull();
});
});