Spaces:
Running
Running
assafvayner HF Staff
fix(photos,forms): own-property content types, dimension bounds, VP8L signature, trimmed inputs
fa363c5 Download tests/unit/forms/settlement-form.test.ts from assafvayner/splitwise: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/spaces/assafvayner/splitwise/resolve/main/tests/unit/forms/settlement-form.test.ts
- Command line
-
hf download hf://spaces/assafvayner/splitwise/tests/unit/forms/settlement-form.test.ts
-
curl -L -o settlement-form.test.ts https://huggingface.co/spaces/assafvayner/splitwise/resolve/main/tests/unit/forms/settlement-form.test.ts
2.02 kB
| import { describe, expect, it } from 'vitest'; | |
| import { buildSettlementBody, readSettlementForm, settlementFormFromQuery } from '../../../src/lib/server/forms/settlement-form'; | |
| const fd = (o: Record<string, string>) => { | |
| const f = new FormData(); | |
| for (const [k, v] of Object.entries(o)) f.append(k, v); | |
| return f; | |
| }; | |
| describe('settlement form', () => { | |
| it('reads and builds', () => { | |
| const values = readSettlementForm(fd({ from: 'u_b', to: 'u_a', amount: '12.5', date: '2026-08-02', note: ' thanks ' })); | |
| expect(buildSettlementBody(values, ['u_a', 'u_b'])).toEqual({ ok: true, body: { from: 'u_b', to: 'u_a', amountCents: 1250, date: '2026-08-02', note: 'thanks' } }); | |
| }); | |
| it('validates', () => { | |
| const good = readSettlementForm(fd({ from: 'u_b', to: 'u_a', amount: '5', date: '2026-08-02' })); | |
| const errs = (v: Partial<typeof good>) => { | |
| const r = buildSettlementBody({ ...good, ...v }, ['u_a', 'u_b']); | |
| return r.ok ? {} : r.errors; | |
| }; | |
| expect(errs({ to: 'u_b' })).toHaveProperty('to'); | |
| expect(errs({ from: 'u_x' })).toHaveProperty('from'); | |
| expect(errs({ amount: '-1' })).toHaveProperty('amount'); | |
| expect(errs({ date: 'nope' })).toHaveProperty('date'); | |
| }); | |
| it('prefills from query params with a safe fallback', () => { | |
| const q = new URLSearchParams({ from: 'u_b', to: 'u_a', amount: '90.00' }); | |
| expect(settlementFormFromQuery(q, 'u_b', '2026-08-29')).toEqual({ from: 'u_b', to: 'u_a', amount: '90.00', date: '2026-08-29', note: '' }); | |
| expect(settlementFormFromQuery(new URLSearchParams(), 'u_b', '2026-08-29')).toEqual({ from: 'u_b', to: '', amount: '', date: '2026-08-29', note: '' }); | |
| }); | |
| it('trims and truncates query-derived values', () => { | |
| const q = new URLSearchParams({ from: ' u_b ', to: ' u_a ', amount: ` ${'9'.repeat(200)} ` }); | |
| const values = settlementFormFromQuery(q, 'u_b', '2026-08-29'); | |
| expect(values.from).toBe('u_b'); | |
| expect(values.to).toBe('u_a'); | |
| expect(values.amount).toBe('9'.repeat(64)); | |
| expect(values.amount.length).toBe(64); | |
| }); | |
| }); | |