Skip to content

test(csv-parser): add unit tests for parseCsvBatch, parseDuration and resolveCliffTime - #627

Merged
Austinaminu2 merged 1 commit into
FlowwStar:mainfrom
brightfootlimited-collab:test/499-csv-parser-unit-tests
Aug 25, 2026
Merged

Austinaminu2 merged 1 commit into
FlowwStar:mainfrom
brightfootlimited-collab:test/499-csv-parser-unit-tests

Conversation

@brightfootlimited-collab

Copy link
Copy Markdown
Contributor

Summary

Closes #499

Adds comprehensive unit tests for lib/csv-parser.ts, covering all three exported functions across three input categories.

What was tested

Valid rows

  • Multi-row parsing with auto-detected and aliased headers (address, total_amount, start_date, end_date, cliff_period)
  • Optional columns: cliff_time, cliff_amount, cliff_duration
  • CRLF line endings
  • Whitespace trimming from cell values
  • Blank lines interspersed in data (filtered out)
  • Extra columns beyond the header (silently ignored)
  • Header-only CSV with no data rows → zero rows, no errors
  • Custom column mapping bypass

Invalid rows

  • Missing required columns: recipient, amount, start_time/start_date, end_time/end_date
  • Returns a descriptive error message and zero rows when required columns are absent

Malformed CSV input

  • Unclosed quoted field → entire remainder of line consumed as one field, other fields default to ""
  • Row shorter than expected → missing fields default to ""
  • Row that is only commas → all fields are ""
  • Blank lines after the header → zero rows, no errors
  • Header with completely unrecognised column names → treated as data rows, no crash
  • Quoted field containing literal \n text → parsed without crashing

parseDuration

  • Plain integer seconds, all unit suffixes (s, m, h, d, w)
  • Case-insensitive + surrounding whitespace tolerance
  • Returns null for empty, non-numeric, float, negative, and unknown-suffix inputs

resolveCliffTime

  • Absolute cliff_time, relative cliff_duration (duration suffixes + plain seconds)
  • Priority: cliff_time wins over cliff_duration when both present
  • Returns null when startTime is null (duration path)
  • Returns null for unparseable cliff_time / cliff_duration
  • End-to-end round-trips: CSV parsed by parseCsvBatch then cliff resolved by resolveCliffTime

Testing

Tests use Vitest + jsdom (existing project setup). No new dependencies added.

…d resolveCliffTime - Cover valid rows: multi-row parsing, optional columns (cliff_time, cliff_amount, cliff_duration), CRLF line endings, whitespace trimming, blank line filtering, extra columns, header-only CSV - Cover invalid rows: missing required columns (recipient, amount, start_time, end_time), zero rows returned on validation error - Cover malformed CSV: unclosed quoted field, row too short, all-empty fields (just commas), blank lines after header, unrecognised headers treated as data rows, quoted field with literal backslash-n text - Cover header aliases: address, total_amount, start_date / end_date, cliff_period, and custom column mapping - Cover parseDuration: plain seconds, all unit suffixes (s/m/h/d/w), case-insensitive + whitespace tolerance, null for unparseable values - Cover resolveCliffTime: absolute cliff_time, relative cliff_duration, priority of cliff_time over cliff_duration, null start_time guard, unparseable inputs, and end-to-end round-trip through parseCsvBatch Closes FlowwStar#499
@Austinaminu2
Austinaminu2 merged commit 9844a9e into FlowwStar:main Aug 25, 2026
2 of 6 checks passed

This branch had an error being deployed

1 failed deployment
staging — 55c12926 Deployed Aug 25, 2026 by brightfootlimited-collab via deploy-staging #194
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for lib/csv-parser.ts

2 participants