test(#223): add unit tests for data utils#528
Conversation
…, passwd, fetchJsonFromUrl) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Review notes: Tests cover happy path, error cases, and edge inputs for all four utils ( One minor observation: the Otherwise looks correct and ready for Arturas to approve. |
|
✓ src/test/data/utils/get-rrule.test.ts (4 tests) 2ms |
arturasmckwcz
left a comment
There was a problem hiding this comment.
Thanks @nadavosa — getRRULE and passwd suites are accurate and well-targeted (non-string guard, no-trim whitespace, case-insensitivity; salt-rounds + both error wrappers). Reviewed each assertion against the source. A few notes, mostly nits:
1. (medium) getStartEndDates validation is dead code — the tests don't reveal it. The guard startHour < endHour && startHour < 0 && startHour > 24 && endHour < 0 && endHour > 24 is unsatisfiable, so invalid hours never throw. The suite only covers valid inputs, so it implies validation works when it doesn't. Either fix the guard (startHour > endHour || startHour < 0 || endHour > 24) and test the throw, or add a test asserting invalid input currently does not throw, so the gap is explicit. (Happy to land a tiny follow-up for the guard.)
2. (low) get-start-end-dates.test.ts codifies a wrong map entry. getStartEnd's map has incorrect values (e.g. "8:00 - 10:00" → 8..11, and "17:00-20:00" → 14..17). The test asserts the 8:00-10:00 → 8..11 value as expected — fine as characterization (and the comment is honest), but it locks the bug in. Worth fixing the source map separately and updating the expectation.
3. (low) timezone-fragile date assertion. expect(end.getFullYear()).toBe(2024) where end = new Date(\"2024-01-01\") (ISO date-only → parsed as UTC). In a UTC-negative TZ that's 2023 and the test fails. Green in Berlin/UTC (project default), but brittle. The getHours() assertions are fine (local-time date form).
4. (low) leaked global stub. fetch-json.test.ts calls vi.unstubAllGlobals() inline; if an assertion throws first, the fetch stub leaks into later tests. Move to afterEach(() => vi.unstubAllGlobals()).
5. (low) branch is behind develop (forked ~#578) — test-only, so low risk, but a rebase before merge runs it against current utils.
Approvable after the nits; #1 is the one worth addressing (it's a real source bug the tests currently paper over).
Two problems with the validation in getStartEndDates: 1. The guard was unsatisfiable (`startHour < 0 && startHour > 24` AND-ed), so invalid hours never threw. Replaced with: throw unless 0 <= startHour < endHour <= 24. 2. It threw a raw Error, which the global handler maps to 500. Invalid hours are a bad-request case, so throw BadRequestError -> 400 (per the error-handling convention in CLAUDE.md). Source-only; getStartEndDates has no production callers today (surfaced while reviewing the unit tests in #528). Happy-path inputs still pass; the throw-path test belongs with the suite in #528. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
getStartEndDates had no production callers (referenced only by its own definition and the barrel re-export) and its validation guard was dead code. Rather than fix a dead function, remove it. Its sibling getStartEnd (4 callers) stays in the same file. Surfaced while reviewing the data-utils tests in #528 — the getStartEndDates tests there should be dropped (keep the getStartEnd ones). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Heads-up: |
Summary
get-rrule.test.ts— all 7 weekdays (case-insensitive), invalid names, non-string input, whitespace edge caseget-start-end-dates.test.ts—getStartEndDateshour/minute output;getStartEndlabel-to-hour mapping using.getHours()assertions (timezone-safe)passwd.test.ts— mocksbcryptto test call arguments and error-wrapping behaviour without slow 10-round hashingfetch-json.test.ts— file-path vs URL routing, explicitfs/promisesfactory mock for reliable Node built-in interceptionTest plan
yarn test:run src/test/data/utils/and confirm all tests pass without a DB connectionCloses #223
🤖 Generated with Claude Code