Compare commits

..

1 commit

Author SHA1 Message Date
le king fu
6c95e61d7f test: freeze CSV detection and amount parsing behaviour on a fixture corpus
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 1m42s
First link of the import-format stack. `autoDetectConfig`, `detectAmountMode`,
`detectSingleAmount`, `preprocessQuotedCSV` and `parseFrenchAmount` had no test
at all on a suite of 871, while carrying every imported amount. This adds the
reference the rewrite (#323-#332) measures itself against, before any of it
moves.

Corpus — 11 synthetic files under `src/__fixtures__/csv/`, no real statement
data, covering shapes a single real statement never contains at once: signed
amount, debit/credit, debit/credit in reversed column order, unused column
filled with `0,00`, preamble before the header, header carrying a number,
header cell starting with digits, no header row, all-positive amounts,
whole-line-quoted (Desjardins style), absolute amount + D/C indicator.

Every expectation was derived by running the code, not by reading it. Four
cases are frozen as DEFECTIVE, each named `KNOWN DEFECT` with the right answer
in a comment and the issue that owes the fix:

- reversed debit/credit — the pair is assigned by column position, never by
  label, so every sign is inverted while the total merely negates (#328)
- unused column at `0,00` — the rule branches on `isNaN(credit)` and `"0,00"`
  parses to 0, so every debit imports as zero (#325)
- header cell starting with digits — `parseFloat` returns the numeric prefix,
  `detectHeader` reads the header as data (#328/#325)
- absolute amount + D/C indicator — the indicator column is ignored entirely
  and every credit imports as an expense (#328)

`parseFrenchAmount` is pinned form by form, including the prefix-scan defect
the spec flagged: `"100,00 CAD"` yields 10000 and passes `isNaN`. Per the
/review-spec revision, the assertions reach the holdings call sites too, which
surfaced the same x100 leak in the #245 holdings import — a price cell of
`"150,25 CAD"` stores the position at 15025.

The end-to-end tests replay the wizard's row-mapping rule from a mirror, since
it still lives inside a `useCallback` and the repo has no jsdom. A guard test
asserts the production expressions are still literally present, so the mirror
cannot drift; #325 extracts `mapRow` and must then delete it.

No production file is modified. 924 vitest green (was 871), build clean.

Resolves #326
2026-08-13 12:33:45 -04:00

View file

@ -179,7 +179,7 @@ describe("parseFrenchAmount — call-site fallout (#326)", () => {
expect(drafts[0].unit_price).toBe("15025"); // DEFECT — should be "150.25" expect(drafts[0].unit_price).toBe("15025"); // DEFECT — should be "150.25"
expect(drafts[0].book_cost).toBe("1200"); // clean cell, correct today expect(drafts[0].book_cost).toBe("1200"); // clean cell, correct today
expect(drafts[1].unit_price).toBe("300.5"); // clean cell, correct today expect(drafts[1].unit_price).toBe("300.5"); // clean cell, correct today
expect(drafts[1].book_cost).toBe("140000"); // DEFECT — should be "1400" expect(drafts[1].book_cost).toBe("140000"); // DEFECT — should be 1400
}); });
it("drops an accounting-parenthesis price instead of reading it", () => { it("drops an accounting-parenthesis price instead of reading it", () => {