Skip to content

test: add coverage for CSV import route - #288

Open
Spaceben123 wants to merge 1 commit into
outerbase:mainfrom
Spaceben123:test/csv-import-coverage
Open

test: add coverage for CSV import route#288
Spaceben123 wants to merge 1 commit into
outerbase:mainfrom
Spaceben123:test/csv-import-coverage

Conversation

@Spaceben123

Copy link
Copy Markdown

/claim #71

What

src/import/csv.ts (the text/csv, JSON-wrapped, and multipart CSV import route) was the one import module without a dedicated test file — json.test.ts and dump.test.ts already existed for its siblings, csv.test.ts did not.

Adds src/import/csv.test.ts, following the existing mocking pattern from json.test.ts (mocks executeOperation and createResponse), covering:

  • Unsupported Content-Type
  • Empty request body
  • Missing file in multipart/form-data
  • Empty CSV content and header-only CSV (no data rows)
  • Successful import via raw text/csv body
  • Successful import via JSON-wrapped CSV with columnMapping
  • Successful import via multipart/form-data file upload
  • Rows whose column count doesn't match the header being silently skipped (a real behavior of parseCSV worth locking in)
  • Partial success when some inserts fail
  • All inserts failing
  • Malformed JSON payload when Content-Type: application/json is set but the body isn't valid JSON

Demo

No screen-recording tool available in this environment, so here's the actual vitest run instead of a video:

```
$ pnpm exec vitest run src/import/csv.test.ts

✓ src/import/csv.test.ts (12 tests) 17ms

Test Files 1 passed (1)
Tests 12 passed (12)
```

Full suite (pnpm exec vitest run) is unaffected: 163 passed both before and after this change, plus the 12 new ones. The 4 pre-existing failures in src/rls/index.test.ts are unrelated to this change (multi-table/subquery RLS SQL-rewriting assertions) and are present on main without this PR.

This PR was written with AI assistance (Claude Code) and verified by running the actual test suite locally — happy to adjust naming/style or add cases if anything's off.

Covers importTableFromCsvRoute (src/import/csv.ts), which previously had
no dedicated test file: unsupported content-type, empty body, missing
multipart file, empty/header-only CSV, raw text/csv and JSON-wrapped CSV
ingestion, column mapping, malformed rows being skipped, partial insert
failures, and malformed JSON payloads.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MQvd9avZenwbcumQHWuusX
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.

1 participant