Files
sofa/packages/core/test/cache.test.ts
T
jakeandClaude Opus 4.6 373a5d3caf test: add integrations, cache, cron, and telemetry tests
- New integrations.test.ts: 13 tests covering CRUD, token generation,
  token lookup, regeneration, and multi-user isolation
- New cache.test.ts: 3 tests for purgeMetadataCache (shell title
  deletion, fully-fetched title preservation, empty case)
- New cron.test.ts: 5 tests for cron run lifecycle (start, complete,
  fail with Error and string)
- New telemetry.test.ts: 7 tests for isTelemetryEnabled toggle and
  performTelemetryReport (disabled skip, enabled send, 24h interval
  throttle, interval expiry, fetch failure resilience)

345 → 386 tests passing across 27 files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 12:39:04 -04:00

49 lines
1.3 KiB
TypeScript

import { beforeEach, describe, expect, test } from "vitest";
import { titles } from "@sofa/db/schema";
import { clearAllTables, insertTitle, testDb } from "@sofa/test/db";
import { purgeMetadataCache } from "../src/cache";
beforeEach(() => {
clearAllTables();
});
describe("purgeMetadataCache", () => {
test("deletes shell titles not in any user library", () => {
// Shell title (lastFetchedAt = null, no user status)
insertTitle({ id: "shell-1", tmdbId: 100, title: "Shell Movie" });
const result = purgeMetadataCache();
expect(result.deletedTitles).toBe(1);
const remaining = testDb.select().from(titles).all();
expect(remaining).toHaveLength(0);
});
test("preserves fully-fetched titles", () => {
testDb
.insert(titles)
.values({
id: "fetched-1",
tmdbId: 100,
type: "movie",
title: "Fetched Movie",
lastFetchedAt: new Date(),
})
.run();
const result = purgeMetadataCache();
expect(result.deletedTitles).toBe(0);
const remaining = testDb.select().from(titles).all();
expect(remaining).toHaveLength(1);
});
test("returns zero counts when nothing to purge", () => {
const result = purgeMetadataCache();
expect(result.deletedTitles).toBe(0);
expect(result.deletedPersons).toBe(0);
});
});