Copre presenze, calendario e guardia admin con nuovi test.
Confrontando le funzioni esportate di src/lib/ con i riferimenti in test/, le uniche funzioni pure ancora scoperte erano i conteggi presenze, tre funzioni del calendario, i titoli MVP e i rifiuti della guardia notifiche. - unit: contaPresenzeGiocatore e totaliEventiGiocatore, compleanniEventi, convocatiEvento, eventoVuoto, mvpVintiPerGiocatore, e il nuovo auth-route.test.ts sui 401 di richiediAdmin (DD-024); - integration/permessi: badge_social_voti, che mancava tra le tabelle di M11, e le deroghe "Gli admin gestiscono tutti/e ...", mai verificate finora. Due modifiche al codice servivano per poter scrivere i test: - presenze.ts: i conteggi leggevano la data da dataOggi() e non erano verificabili; ora accettano oggi come parametro opzionale, come già facevano serieConsecutiva e serieConferme. Toglie anche la dipendenza dall'orologio che avrebbe cambiato i risultati dei test delle serie dal 10 settembre in poi; - auth-route.server.ts: "Bearer .." passava il pre-check con tre segmenti vuoti e arrivava fino alla chiamata di rete; ora i segmenti devono essere non vuoti. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,8 +18,9 @@ function tokenDaRichiesta(request: Request): string | null {
|
||||
const intestazione = request.headers.get("authorization");
|
||||
if (!intestazione?.startsWith("Bearer ")) return null;
|
||||
const token = intestazione.slice("Bearer ".length).trim();
|
||||
// Un JWT ha tre segmenti: scartarlo qui evita una chiamata di rete per ogni rumore.
|
||||
return token && token.split(".").length === 3 ? token : null;
|
||||
// Un JWT ha tre segmenti non vuoti: scartarlo qui evita una chiamata di rete per ogni rumore.
|
||||
const segmenti = token.split(".");
|
||||
return segmenti.length === 3 && segmenti.every(Boolean) ? token : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
-7
@@ -14,8 +14,7 @@ export type MappaPresenze = Record<string, Record<string, Stato>>;
|
||||
export type MappaTempiRisposta = Record<string, Record<string, string>>;
|
||||
|
||||
/** Allenamenti e partite CrAPP già passati, che contano per le statistiche di presenza. */
|
||||
function eventiContanoPresenze(eventi: Evento[], giocatoreId?: string) {
|
||||
const oggi = dataOggi();
|
||||
function eventiContanoPresenze(eventi: Evento[], giocatoreId?: string, oggi = dataOggi()) {
|
||||
return eventi.filter(
|
||||
(e) =>
|
||||
(e.tipo === "partita" || e.tipo === "allenamento") &&
|
||||
@@ -29,16 +28,21 @@ export function contaPresenzeGiocatore(
|
||||
giocatoreId: string,
|
||||
eventi: Evento[],
|
||||
presenze: MappaPresenze,
|
||||
oggi: string = dataOggi(),
|
||||
): number {
|
||||
return eventiContanoPresenze(eventi, giocatoreId).filter((e) => {
|
||||
return eventiContanoPresenze(eventi, giocatoreId, oggi).filter((e) => {
|
||||
const stato = presenze[e.id]?.[giocatoreId];
|
||||
return stato === "presente" || stato === "ritardo";
|
||||
}).length;
|
||||
}
|
||||
|
||||
/** Eventi CrAPP rilevanti per il denominatore presenze di un giocatore. */
|
||||
export function totaliEventiGiocatore(giocatoreId: string, eventi: Evento[]): number {
|
||||
return eventiContanoPresenze(eventi, giocatoreId).length;
|
||||
export function totaliEventiGiocatore(
|
||||
giocatoreId: string,
|
||||
eventi: Evento[],
|
||||
oggi: string = dataOggi(),
|
||||
): number {
|
||||
return eventiContanoPresenze(eventi, giocatoreId, oggi).length;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,8 +100,8 @@ function serieSu(
|
||||
tipo: "partita" | "allenamento" | undefined,
|
||||
onorato: (e: Evento) => boolean,
|
||||
): number {
|
||||
return eventiContanoPresenze(eventi, giocatoreId)
|
||||
.filter((e) => (tipo === undefined || e.tipo === tipo) && e.data <= oggi)
|
||||
return eventiContanoPresenze(eventi, giocatoreId, oggi)
|
||||
.filter((e) => tipo === undefined || e.tipo === tipo)
|
||||
.sort((a, b) => a.data.localeCompare(b.data))
|
||||
.reduce((serie, e) => aggiornaSerie(serie, onorato(e)), 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user