mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
* fix(worker): CSV export kept negatives numeric; email previews anchor to latest data month - toCsv formula guard no longer prefixes plain numbers with a quote (negative balances exported as '-2392.21 text and broke numeric columns) - spending-report/budget-alert previews compute the latest month that has transactions instead of the (possibly empty) current month; subject now names the period, e.g. "[Test] Your spending report (March 2026)" * fix(receipts): surface uploaded receipts — table chip, view modal, edit-modal thumbnail Uploads worked but nothing ever showed the receipt again: - worker: transactions list + get now LEFT JOIN receipts (receipt_id, receipt_name); new GET /api/receipts/:id/file streams from R2 (the path the frontend client already used; only /file/:filename existed) - serverless: list enriches receipt_id/receipt_name from IndexedDB; upload accepts the 'receipt' form key the client sends (was 'file'-only, so demo uploads silently failed) and replaces the previous receipt like the worker; create/get responses normalized so schema validation passes - UI: Receipt chip in the transactions table opens the existing view modal; files load as authenticated blobs via api.getReceiptFile (the old relative /api img src bypassed API_BASE and cookies on deployed builds); PDFs render in an iframe; edit modal shows the attached receipt with delete/replace; delete asks for confirmation Verified end-to-end in chromium (demo mode: upload -> chip -> modal -> edit thumbnail) plus worker tests for the join, file route, cross-user 404, and re-upload replacement.
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { env, SELF } from 'cloudflare:test';
|
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
import { issueSessionCookie } from '../src/auth';
|
|
|
|
// CSV export: the formula-injection guard must quote attacker-shaped STRINGS but leave
|
|
// plain numbers alone — it used to turn every negative balance into text ("'-2392.21").
|
|
|
|
let cookie = '';
|
|
|
|
beforeEach(async () => {
|
|
for (const t of ['accounts', 'profiles', 'users']) {
|
|
await env.DB.prepare(`DELETE FROM ${t}`).run();
|
|
}
|
|
await env.DB.batch([
|
|
env.DB.prepare(
|
|
"INSERT INTO users (id, email, auth_provider, token_version) VALUES (60, 'csv@example.com', 'password', 1)"
|
|
),
|
|
env.DB.prepare("INSERT INTO profiles (id, user_id, name) VALUES (600, 60, 'Main')"),
|
|
env.DB.prepare(
|
|
"INSERT INTO accounts (profile_id, name, type, currency, balance) VALUES (600, 'WRev', 'giro', 'USD', -2392.21)"
|
|
),
|
|
env.DB.prepare(
|
|
"INSERT INTO accounts (profile_id, name, type, currency, balance) VALUES (600, '=HYPERLINK(\"http://evil\")', 'giro', 'USD', 10)"
|
|
),
|
|
]);
|
|
cookie = (await issueSessionCookie(60, 'password', env)).split(';')[0];
|
|
});
|
|
|
|
describe('GET /api/export/accounts (CSV)', () => {
|
|
it('exports negative balances as plain numbers, not quoted text', async () => {
|
|
const res = await SELF.fetch('https://example.com/api/export/accounts?format=csv', {
|
|
headers: { Cookie: cookie },
|
|
});
|
|
expect(res.status).toBe(200);
|
|
const csv = await res.text();
|
|
expect(csv).toContain('-2392.21');
|
|
expect(csv).not.toContain("'-2392.21");
|
|
});
|
|
|
|
it('still quotes formula-shaped strings', async () => {
|
|
const res = await SELF.fetch('https://example.com/api/export/accounts?format=csv', {
|
|
headers: { Cookie: cookie },
|
|
});
|
|
const csv = await res.text();
|
|
expect(csv).toContain("'=HYPERLINK");
|
|
});
|
|
});
|