Copre la logica pura isolabile di avatar-store, error-capture, error-page, lovable-error-reporting, profili (validazione upload), push-client (guardie senza DOM), scout-stato e webpush.server (firma JWT VAPID con chiavi P-256 generate al volo, fetch intercettato). Alza i file di src/lib coperti da 19 a 28 su 37, senza introdurre nuove dipendenze. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
/**
|
|
* Check delle notifiche push lato client: `bun test/unit/push-client.test.ts`.
|
|
* Fuori dal browser (nessun `navigator.serviceWorker`) tutte le funzioni devono
|
|
* riconoscere l'assenza di supporto senza tentare rete o API del DOM.
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
attivaNotifiche,
|
|
disattivaNotifiche,
|
|
pushSupportato,
|
|
statoNotifiche,
|
|
} from "@/lib/push-client";
|
|
|
|
// --- pushSupportato: falso in ambiente server (nessun window) -----------------
|
|
assert.equal(typeof window, "undefined", "il test gira senza DOM");
|
|
assert.equal(pushSupportato(), false);
|
|
|
|
// --- statoNotifiche: nessun supporto -> nessuna sottoscrizione ----------------
|
|
assert.equal(await statoNotifiche(), false);
|
|
|
|
// --- attivaNotifiche: rifiuta subito, senza chiedere permessi o rete ----------
|
|
await assert.rejects(() => attivaNotifiche("g1"), /Notifiche non supportate su questo dispositivo/);
|
|
|
|
// --- disattivaNotifiche: no-op silenzioso, nessun errore ----------------------
|
|
await assert.doesNotReject(() => disattivaNotifiche());
|
|
|
|
console.log("push-client: ok");
|