mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
* fix: charted PDFs in server mode; iOS calendar-tap crash; working unsubscribe page Three user-reported issues: - Reports: the Settings PDF downloads hit the worker's /api/reports/*-pdf in self-hosted mode, which can only produce text (Workers have no canvas) — the 'Annual Financial Report' lost its charts on the dev domain. Rich PDFs are now always composed client-side (jsPDF + Chart.js worker); loadReportSource feeds the generators from IndexedDB in serverless mode or from the HTTP API (/api/transactions + /api/categories) in self-hosted mode. Verified: annual PDF ~1.9MB with charts vs the old ~4KB text-only. - iOS 'script error' crash on bills-calendar day tap: the global ErrorBoundary escalated EVERY window error to a full-screen crash modal — including the opaque 'Script error.' fired by cross-origin scripts (Cloudflare Bot Fight Mode's injected /cdn-cgi/ challenge, extensions). Third-party/opaque errors are now logged but never take over the app; real same-origin errors still show the crash modal. Bonus: the day popover is a bottom sheet on phone widths (cell-anchored placement ran off-screen on lower calendar rows) and clamps to the viewport on desktop. - Unsubscribe: the email footer linked the SPA origin (CORS_ORIGIN), so the click landed on the static-asset fallback — no page, and nobody was actually unsubscribed. New API_PUBLIC_ORIGIN var (dev + prod + local) targets the worker itself; the endpoint now renders a branded confirmation page, a distinct 'link not recognized' page for stale tokens (no fake success), and links back to the app. Re-enable any time under Settings, Notifications. Worker: 49 tests (3 new unsubscribe). Frontend: 375 tests. Chromium-verified: PDF size/magic-bytes, synthetic Script error./cdn-cgi events leave the app alive while a real error still crashes properly, calendar bottom sheet fully on-screen at 375x812. * fix(dashboard): show the Views modal close X; drop redundant footer divider The modal-close SVG had no width/height so it rendered 0x0 — the X was in the DOM but invisible. Set it to 20x20 (and add aria-label). Also remove the border-top divider above the Save & Close button in the widget settings footer.
49 lines
1.9 KiB
TypeScript
49 lines
1.9 KiB
TypeScript
import { env, SELF } from 'cloudflare:test';
|
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
// One-click unsubscribe from email footers: must flip the user's flag and render a
|
|
// human-readable confirmation page (the old link pointed at the SPA host and did
|
|
// neither). Unknown/missing tokens get a distinct error page, not a fake success.
|
|
|
|
beforeEach(async () => {
|
|
await env.DB.prepare('DELETE FROM users').run();
|
|
await env.DB.prepare(
|
|
"INSERT INTO users (id, email, auth_provider, token_version, unsubscribe_token) VALUES (90, 'unsub@example.com', 'password', 1, 'tok-abc-123')"
|
|
).run();
|
|
});
|
|
|
|
describe('GET /api/notifications/unsubscribe', () => {
|
|
it('unsubscribes the matching user and shows a confirmation page', async () => {
|
|
const res = await SELF.fetch(
|
|
'https://example.com/api/notifications/unsubscribe?token=tok-abc-123'
|
|
);
|
|
expect(res.status).toBe(200);
|
|
const html = await res.text();
|
|
expect(html).toContain('You are unsubscribed');
|
|
expect(html).toContain('Settings');
|
|
|
|
const row = await env.DB.prepare(
|
|
'SELECT notifications_unsubscribed FROM users WHERE id = 90'
|
|
).first<{ notifications_unsubscribed: number }>();
|
|
expect(row?.notifications_unsubscribed).toBe(1);
|
|
});
|
|
|
|
it('rejects an unknown token without unsubscribing anyone', async () => {
|
|
const res = await SELF.fetch(
|
|
'https://example.com/api/notifications/unsubscribe?token=wrong-token'
|
|
);
|
|
expect(res.status).toBe(400);
|
|
expect(await res.text()).toContain('not recognized');
|
|
|
|
const row = await env.DB.prepare(
|
|
'SELECT notifications_unsubscribed FROM users WHERE id = 90'
|
|
).first<{ notifications_unsubscribed: number | null }>();
|
|
expect(row?.notifications_unsubscribed ?? 0).toBe(0);
|
|
});
|
|
|
|
it('rejects a missing token', async () => {
|
|
const res = await SELF.fetch('https://example.com/api/notifications/unsubscribe');
|
|
expect(res.status).toBe(400);
|
|
});
|
|
});
|