2026-09-02 11:34:09 +02:00
|
|
|
/**
|
|
|
|
|
* Check dell'avatar giocatore: `bun test/unit/avatar-store.test.ts`.
|
2026-09-11 14:58:54 +02:00
|
|
|
* `urlAvatarDaRiga` è puro (il campo non è protetto, nessuna richiesta di rete): qui
|
|
|
|
|
* verifichiamo solo la forma dell'URL a partire da una riga finta, non serve un database.
|
2026-09-02 11:34:09 +02:00
|
|
|
*/
|
|
|
|
|
import assert from "node:assert/strict";
|
2026-09-11 14:58:54 +02:00
|
|
|
import { urlAvatarDaRiga } from "@/lib/avatar-store";
|
2026-09-02 11:34:09 +02:00
|
|
|
|
2026-09-11 14:58:54 +02:00
|
|
|
const riga = { id: "rec1", giocatore: "g1", foto: "avatar_abc123.jpg" };
|
2026-09-02 11:34:09 +02:00
|
|
|
|
2026-09-11 14:58:54 +02:00
|
|
|
const url = urlAvatarDaRiga(riga);
|
|
|
|
|
|
|
|
|
|
assert.ok(url.includes("avatar_giocatori"), "punta alla collection degli avatar");
|
|
|
|
|
assert.ok(url.includes("rec1"), "contiene l'id del record");
|
|
|
|
|
assert.ok(url.includes("avatar_abc123.jpg"), "contiene il nome del file");
|
|
|
|
|
assert.equal(
|
|
|
|
|
urlAvatarDaRiga(riga),
|
|
|
|
|
url,
|
|
|
|
|
"deterministico a parità di riga: nessuna chiamata di rete",
|
|
|
|
|
);
|
|
|
|
|
assert.notEqual(
|
|
|
|
|
urlAvatarDaRiga({ ...riga, foto: "altro.jpg" }),
|
|
|
|
|
url,
|
|
|
|
|
"file diverso -> URL diverso",
|
|
|
|
|
);
|
2026-09-02 11:34:09 +02:00
|
|
|
|
|
|
|
|
console.log("avatar-store: ok");
|