mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-07-14 18:15:56 -04:00
- Replace bun:test with Vitest across all 22 test files - Create @sofa/test package with shared setup and DB test helpers - setup.ts: vi.mock for @sofa/db/client, Bun.randomUUIDv7 polyfill - db.ts: in-memory SQLite via better-sqlite3, seed helpers - Add per-project vitest configs (packages/core, apps/web) - Add root vitest.config.ts with projects and v8 coverage - Set up @vitest/browser + Playwright for web component tests - Move validateBackupDatabase from core/backup.ts to @sofa/db/client - Derive required backup tables from schema instead of hard-coded list - Update CI workflow with Playwright install and Codecov upload - Update CLAUDE.md documentation for Vitest Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
86 lines
2.6 KiB
TypeScript
86 lines
2.6 KiB
TypeScript
import { beforeEach, describe, expect, test } from "vitest";
|
|
|
|
import { personFilmography, persons } from "@sofa/db/schema";
|
|
import { clearAllTables, insertTitle, testDb } from "@sofa/test/db";
|
|
|
|
import { getLocalFilmography } from "../src/person";
|
|
|
|
beforeEach(() => {
|
|
clearAllTables();
|
|
});
|
|
|
|
function insertPerson(id: string, tmdbId: number, name: string) {
|
|
testDb.insert(persons).values({ id, tmdbId, name }).run();
|
|
return id;
|
|
}
|
|
|
|
function insertFilmographyEntry(
|
|
titleId: string,
|
|
personId: string,
|
|
overrides: {
|
|
character?: string | null;
|
|
department?: string;
|
|
job?: string | null;
|
|
displayOrder?: number;
|
|
} = {},
|
|
) {
|
|
testDb
|
|
.insert(personFilmography)
|
|
.values({
|
|
titleId,
|
|
personId,
|
|
character: overrides.character ?? "Character",
|
|
department: overrides.department ?? "Acting",
|
|
job: overrides.job ?? null,
|
|
displayOrder: overrides.displayOrder ?? 0,
|
|
})
|
|
.run();
|
|
}
|
|
|
|
describe("getLocalFilmography", () => {
|
|
test("returns filmography for a person", () => {
|
|
insertTitle({ id: "m1", tmdbId: 1, title: "Movie One" });
|
|
insertTitle({ id: "m2", tmdbId: 2, title: "Movie Two" });
|
|
insertPerson("p1", 100, "Test Actor");
|
|
insertFilmographyEntry("m1", "p1", { character: "Hero" });
|
|
insertFilmographyEntry("m2", "p1", { character: "Sidekick" });
|
|
|
|
const filmography = getLocalFilmography("p1");
|
|
expect(filmography).toHaveLength(2);
|
|
expect(filmography.map((f) => f.title).sort()).toEqual(["Movie One", "Movie Two"]);
|
|
});
|
|
|
|
test("includes crew roles", () => {
|
|
insertTitle({ id: "m1", tmdbId: 1, title: "Directed Movie" });
|
|
insertPerson("p1", 100, "Director Person");
|
|
insertFilmographyEntry("m1", "p1", {
|
|
character: null,
|
|
department: "Directing",
|
|
job: "Director",
|
|
});
|
|
|
|
const filmography = getLocalFilmography("p1");
|
|
expect(filmography).toHaveLength(1);
|
|
expect(filmography[0].department).toBe("Directing");
|
|
expect(filmography[0].job).toBe("Director");
|
|
});
|
|
|
|
test("returns empty for person with no credits", () => {
|
|
insertPerson("p1", 100, "Unknown Actor");
|
|
const filmography = getLocalFilmography("p1");
|
|
expect(filmography).toHaveLength(0);
|
|
});
|
|
|
|
test("returns correct title types", () => {
|
|
insertTitle({ id: "m1", tmdbId: 1, type: "movie", title: "A Movie" });
|
|
insertTitle({ id: "tv1", tmdbId: 2, type: "tv", title: "A Show" });
|
|
insertPerson("p1", 100, "Versatile Actor");
|
|
insertFilmographyEntry("m1", "p1");
|
|
insertFilmographyEntry("tv1", "p1");
|
|
|
|
const filmography = getLocalFilmography("p1");
|
|
const types = filmography.map((f) => f.type).sort();
|
|
expect(types).toEqual(["movie", "tv"]);
|
|
});
|
|
});
|