Mostra anche la classifica di Coppa in Campionato > Classifica
parseClassifica() legge project-sheets.php?project_id=848 con lo stesso parsing del girone di campionato (stessa struttura di tabella), quindi nessun parser dedicato. La Coppa resta limitata alla fase a gironi: la finale secca vive in un project_id figlio non tracciato dal codice. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,6 +50,7 @@ try {
|
||||
assert.match(res.headers.get("content-type") ?? "", /application\/json/);
|
||||
csi = (await json(res)) as DatiCsi;
|
||||
assert.ok(Array.isArray(csi.classifica) && csi.classifica.length > 0);
|
||||
assert.ok(Array.isArray(csi.classificaCoppa));
|
||||
assert.ok(Array.isArray(csi.partite) && csi.partite.length > 0);
|
||||
assert.equal(csi.girone, "Girone B");
|
||||
assert.ok(!Number.isNaN(Date.parse(csi.aggiornato)), "timestamp valido");
|
||||
@@ -68,6 +69,12 @@ try {
|
||||
);
|
||||
});
|
||||
|
||||
await provaCsi("la classifica di Coppa, se presente, contiene la nostra squadra", () => {
|
||||
if ((csi?.classificaCoppa.length ?? 0) === 0) return; // fase a gironi finita, pagina cambiata
|
||||
const noi = csi?.classificaCoppa.find((r) => isNostraSquadra(r.squadra));
|
||||
assert.ok(noi, "C.R.A.P. Volley presente nel girone di Coppa");
|
||||
});
|
||||
|
||||
await provaCsi("ogni partita è coerente con il formato dell'app", () => {
|
||||
for (const p of csi?.partite ?? []) {
|
||||
assert.match(p.data, /^\d{4}-\d{2}-\d{2}$/, `${p.id}: data ISO`);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
CSI_COPPA_PROJECT_ID,
|
||||
isNostraSquadra,
|
||||
parseClassifica,
|
||||
partiteDaEventi,
|
||||
@@ -48,6 +49,20 @@ assert.deepEqual(righe[1], {
|
||||
assert.equal(righe[0]!.squadra, "Paolo Poggi Volley & C.", "decodifica le entità HTML");
|
||||
assert.deepEqual(parseClassifica("<p>pagina cambiata</p>"), [], "portale cambiato: nessun crash");
|
||||
|
||||
// La Coppa ha un girone più piccolo (poche squadre) ma la stessa struttura di tabella del
|
||||
// campionato: `parseClassifica()` funziona invariata, non serve un parser dedicato.
|
||||
const htmlCoppa = `
|
||||
<table class="ranking">
|
||||
<tr><th>Pos</th><th>Squadra</th></tr>
|
||||
<tr><td>1</td><td><a href="team_details.php?team_id=2">Set in the City</a></td>
|
||||
<td><b>7</b></td><td>3</td><td>2</td><td>1</td><td>0</td><td>0</td><td>8</td><td>4</td></tr>
|
||||
<tr><td>2</td><td><a href="team_details.php?team_id=3359">C.R.A.P. Volley</a></td>
|
||||
<td><b>6</b></td><td>3</td><td>2</td><td>1</td><td>0</td><td>0</td><td>8</td><td>5</td></tr>
|
||||
</table>`;
|
||||
const righeCoppa = parseClassifica(htmlCoppa);
|
||||
assert.equal(righeCoppa.length, 2, "girone di Coppa più piccolo del campionato: ok comunque");
|
||||
assert.equal(righeCoppa[1]!.squadra, "C.R.A.P. Volley");
|
||||
|
||||
assert.ok(isNostraSquadra("CRAP Volley") && isNostraSquadra("C.R.A.P. Volley "));
|
||||
assert.ok(!isNostraSquadra("CRAP Volley B"));
|
||||
|
||||
@@ -126,14 +141,20 @@ assert.equal(
|
||||
);
|
||||
|
||||
if (process.env["CSI_LIVE"]) {
|
||||
const [html, json] = await Promise.all([
|
||||
const [html, htmlCoppa, json] = await Promise.all([
|
||||
fetch(urlClassifica()).then((r) => r.text()),
|
||||
fetch(urlClassifica(CSI_COPPA_PROJECT_ID)).then((r) => r.text()),
|
||||
fetch(urlPartite()).then((r) => r.json()),
|
||||
]);
|
||||
const live = parseClassifica(html);
|
||||
const nostra = live.find((r) => isNostraSquadra(r.squadra));
|
||||
assert.ok(nostra, "la nostra squadra è in classifica");
|
||||
assert.ok(live.length >= 8 && nostra.giocate > 0);
|
||||
const liveCoppa = parseClassifica(htmlCoppa);
|
||||
assert.ok(
|
||||
liveCoppa.some((r) => isNostraSquadra(r.squadra)),
|
||||
"la nostra squadra è nel girone di Coppa",
|
||||
);
|
||||
const livePartite = partiteDaEventi(json);
|
||||
assert.ok(livePartite.length > 0 && partiteGiocate(livePartite).length > 0);
|
||||
console.log(`live: ${live.length} squadre, ${livePartite.length} partite, noi ${nostra.pos}°`);
|
||||
|
||||
Reference in New Issue
Block a user