Add balance adjustments (M8)

- New balance_adjustments table with CRUD store, sync logging, and service methods
- SQL migrations restructured: embed fs.FS from internal/store/migrations/, apply in order via user_version
- WeekService.Balance combines closed-weeks delta + adjustments delta; BalanceSummary breakdown
- Four REST routes: GET/POST /api/balance/adjustments, PUT/DELETE /api/balance/adjustments/{id}
- Dexie schema v2 + sync apply cases for balance_adjustments
- API client: BalanceAdjustment type, balance namespace (list/create/update/delete)
- utils: composeDeltaMs / decomposeDeltaMs helpers + 8 new Vitest tests (19 total, all passing)
- History page: balance card breakdown line + full adjustments section with inline add/edit/delete
This commit is contained in:
2026-04-30 21:50:57 +02:00
parent 8ca838fa6e
commit 3214f48a6f
19 changed files with 1014 additions and 86 deletions
+33 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { dayCapabilities, weekDayKeys, isWorkday } from './utils';
import { dayCapabilities, weekDayKeys, isWorkday, composeDeltaMs, decomposeDeltaMs } from './utils';
describe('dayCapabilities', () => {
const today = '2026-04-30';
@@ -82,3 +82,35 @@ describe('isWorkday', () => {
it('Saturday is not a workday', () => expect(isWorkday('2026-05-02', monToFri)).toBe(false));
it('Sunday is not a workday', () => expect(isWorkday('2026-05-03', monToFri)).toBe(false));
});
describe('composeDeltaMs', () => {
it('positive: 2h 30m → +9000000', () => {
expect(composeDeltaMs('+', 2, 30)).toBe(9_000_000);
});
it('negative: 1h 15m → -4500000', () => {
expect(composeDeltaMs('-', 1, 15)).toBe(-4_500_000);
});
it('zero hours and minutes → 0', () => {
expect(composeDeltaMs('+', 0, 0)).toBe(0);
});
it('negative zero → 0 (no negative zero)', () => {
expect(composeDeltaMs('-', 0, 0)).toBe(0);
});
});
describe('decomposeDeltaMs', () => {
it('positive 3h 24m', () => {
expect(decomposeDeltaMs(12_240_000)).toEqual({ sign: '+', hours: 3, minutes: 24 });
});
it('negative 1h 30m', () => {
expect(decomposeDeltaMs(-5_400_000)).toEqual({ sign: '-', hours: 1, minutes: 30 });
});
it('zero', () => {
expect(decomposeDeltaMs(0)).toEqual({ sign: '+', hours: 0, minutes: 0 });
});
it('round-trips through compose', () => {
const original = -7_320_000; // -2h 2m
const { sign, hours, minutes } = decomposeDeltaMs(original);
expect(composeDeltaMs(sign, hours, minutes)).toBe(original);
});
});