Files
photoreport/apps/api/test/cross-sport.test.ts
sparkandClaude Opus 5.5 303aedef80
ci / rust (push) Successful in 4m19s
ci / typescript (push) Successful in 7m38s
Archive: both teams or no game, legends are events, every match redone; faces keep to the sport
A folder is matched to an official game only when both teams are recognised (never a first team for its B side); legends', veterans', charity and exhibition games never get a championship fixture; every match but a manual one is made again on start and every six hours (one failing folder never stops the rest), renaming events to clean team names. The viewer merges teams written with dates before them and known teams under one name. Faces are never suggested as someone of another sport, and old such suggestions are taken away. Visible loading in the archive site. More archive work at once (previews, images in flight, face processes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
2026-10-15 03:49:08 +01:00

38 lines
2.8 KiB
TypeScript

import { afterAll, beforeEach, describe, expect, it } from "vitest";
import { createDb } from "../src/db.js";
import { dropCrossSportSuggestions, eventSport, normSport, peopleSports } from "../src/faces/service.js";
import { resetDb, seedUser } from "./helpers.js";
/** A footballer is never suggested at a handball game, nor a handball player at a football game. */
describe("face suggestions keep to the event's sport", () => {
const db = createDb(process.env.DATABASE_URL_TEST ?? "");
afterAll(() => db.$disconnect());
beforeEach(() => resetDb(db));
it("knows each person's sport by their squad, and takes away suggestions of another sport", async () => {
const { org, user } = await seedUser(db, "[email protected]", { org: "fpa", role: "OWNER" });
const orgId = org!.id;
const football = await db.sportsTeam.create({ data: { provider: "LIGA", externalId: "est", sport: "futebol", name: "Estoril Praia", slug: "estoril" } });
const handball = await db.sportsTeam.create({ data: { provider: "FPA", externalId: "abc", sport: "andebol", name: "ABC de Braga", slug: "abc" } });
const xeka = await db.person.create({
data: { organizationId: orgId, name: "Xeka", sportsPlayerId: (await db.sportsPlayer.create({ data: { teamId: football.id, season: "20262027", externalId: "x", name: "Xeka" } })).id },
});
const ana = await db.person.create({
data: { organizationId: orgId, name: "Ana", sportsPlayerId: (await db.sportsPlayer.create({ data: { teamId: handball.id, season: "20262027", externalId: "a", name: "Ana" } })).id },
});
const typed = await db.person.create({ data: { organizationId: orgId, name: "Sem equipa" } });
const at = new Date("2026-10-04T18:00:00Z");
const game = await db.event.create({ data: { organizationId: orgId, home: "ABC de Braga", away: "CD Feirense", sport: "Andebol", startsAt: at, ingestFrom: at, ingestUntil: at, iptcTemplate: {}, createdById: user.id } });
expect(await eventSport(db, game.id)).toBe("andebol");
expect(normSport("Football")).toBe("futebol");
const sports = await peopleSports(db, [xeka, ana, typed]);
expect([sports.get(xeka.id), sports.get(ana.id), sports.get(typed.id)]).toEqual(["futebol", "andebol", undefined]);
const group = (personId: string) => db.faceGroup.create({ data: { organizationId: orgId, eventId: game.id, centroid: [1, 0], model: "m", size: 2, suggestedPersonId: personId, suggestionScore: 0.7 } });
const [g1, g2, g3] = [await group(xeka.id), await group(ana.id), await group(typed.id)];
expect(await dropCrossSportSuggestions(db)).toBe(1);
const after = await db.faceGroup.findMany({ where: { id: { in: [g1.id, g2.id, g3.id] } }, orderBy: { createdAt: "asc" } });
expect(after.map((g) => g.suggestedPersonId)).toEqual([null, ana.id, typed.id]);
});
});