From b1f0df9662563ff1cd835cb5b80c1625f19c33ba Mon Sep 17 00:00:00 2001 From: paula-alves Date: Wed, 18 Nov 2026 22:05:46 +0000 Subject: [PATCH] test(sports): cover 57P03 from personForIdentity sportsPlayer.findMany (BIT-32474) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BIT-32470 added 57P03 to isPrismaServerUnreachable and proved it for linkSquadPerson's person.findFirst (FPA licence lookup), but the error loop reported the same 57P03 one call deeper at personForIdentity's sportsPlayer.findMany — the path taken when a squad player has no externalId and is matched by birthDate/fullName. The same syncEventSquads catch covers it (the error propagates through linkSquadPerson without a catch), but no test exercised that path. Add a regression test that makes sportsPlayer.findMany throw 57P03 on the personForIdentity call and asserts the info-level stop-and-return zeros behaviour. Paperclip-Issue: BIT-32474 --- apps/api/src/sports/service.test.ts | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/apps/api/src/sports/service.test.ts b/apps/api/src/sports/service.test.ts index df9dfc5..170df98 100644 --- a/apps/api/src/sports/service.test.ts +++ b/apps/api/src/sports/service.test.ts @@ -24,6 +24,12 @@ const p57p03 = () => { code: "P2039" }, ); +const p57p03SportsPlayer = () => + Object.assign( + new Error("Invalid `prisma.sportsPlayer.findMany()` invocation:\n\nDatabase error. Code: `57P03`. Message: `the database system is shutting down`"), + { code: "P2039" }, + ); + const p57p01 = () => Object.assign( new Error("Invalid `prisma.$queryRaw()` invocation:\n\nRaw query failed. Code: `57P01`. Message: `terminating connection due to administrator command`"), @@ -144,6 +150,49 @@ describe("syncEventSquads downgrades a 57P03 database-shutting-down error (BIT-3 }); }); +describe("syncEventSquads downgrades a 57P03 from personForIdentity's sportsPlayer.findMany (BIT-32474)", () => { + it("logs at info and returns zeros when personForIdentity hits 57P03 on sportsPlayer.findMany", async () => { + // The error loop reported 57P03 escaping at personForIdentity → sportsPlayer.findMany, one call deeper than + // the BIT-32470 test's person.findFirst. The same syncEventSquads catch (isPrismaServerUnreachable, which + // matches 57P03 since BIT-32470) covers this path: the error propagates through linkSquadPerson (no catch) to + // the syncEventSquads wrapper. This test proves that coverage. + const fpaTeam = { + id: "t-fpa", + provider: "FPA", + externalId: "fpa-1", + name: "Team FPA", + abbreviation: "FPA", + logoUrl: null, + }; + let findManyCalls = 0; + const db = { + event: { findUnique: async () => makeEvent({ homeTeam: fpaTeam, awayTeam: null }) }, + sportsPlayer: { + findFirst: async () => ({ season: "2026" }), + // First call: squad() reads the team's players. Second call: personForIdentity looks up the same human + // by birthDate/fullName (no externalId on the player, so the FPA licence lookup is skipped) and hits 57P03. + findMany: async () => { + findManyCalls++; + if (findManyCalls === 1) + return [{ id: "pl-1", name: "Player 1", externalId: null, birthDate: "2000-01-01", fullName: "Player One", number: "1", photoUrl: null, season: "2026" }]; + throw p57p03SportsPlayer(); + }, + findUnique: async () => null, + }, + person: { + findUnique: async () => null, + findFirst: async () => null, + }, + }; + const service = new SportsService(makeDeps(db)); + const out = await service.syncEventSquads("evt-1"); + expect(out).toEqual({ created: 0, updated: 0, headshots: 0 }); + const log = (service as unknown as { deps: { log: { calls: LogCall[] } } }).deps.log; + expect(log.calls.some((c) => c.level === "info" && /database unreachable/.test(c.msg))).toBe(true); + expect(log.calls.some((c) => c.level === "warn")).toBe(false); + }); +}); + describe("linkStoredSquads downgrades a 57P01 admin-terminated connection (BIT-32471)", () => { it("logs at info and returns 0 when the raw query is terminated mid-flight (57P01)", async () => { const db = { -- 2.47.3