mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
Three rows of a 5,194-row sheet were rejected for "Could not read amount_local"
— values like 754.312, left by a currency conversion that multiplies and never
rounds. Losing a transaction over a tenth of a cent is the wrong trade.
Separator rules, now in shared/importNumber.ts:
1,234.56 both separators -> the LAST one is the decimal point
1.234.567 one char, repeated -> grouping, an integer
1.234 exactly one -> a decimal point, always
1234 none -> an integer
Rule 3 is the change. A lone separator used to be rejected as ambiguous; it now
reads as money, because prices carry cents. It is also the rule that can be
wrong — `1.000` as European thousands means 1000 and this reads it as 1.00 — so
that exact shape is flagged and surfaced rather than decided silently. Grouping
structure is still validated strictly: relaxing which separator means "decimal"
is deliberate, accepting `1,2,3` is not.
Fractions longer than two digits round to cents, and the flag for that fires on
the amount actually moving by half a cent or more rather than on the digit
count. A sheet that multiplies to convert a currency stores binary-float residue
in hundreds of rows; on the reported sheet 250 rows carry residue, 7 carry real
extra precision, and only those 7 are flagged.
A row with no date imports dated today and warns, in BOTH runtimes, instead of
being rejected locally and silently stamped today by the Worker. A date the user
can correct beats a transaction that never arrived. Its dedup behaviour is
pinned: the sync runs daily, and a row failing to match its stored copy would
pile up one duplicate per day.
Warnings are a channel of their own alongside skipped_items and never deselect a
row — the row imports either way; the note is how the user knows to look at it.
Rejections are numbered as the spreadsheet numbers them. Every parser consumes
the first record as the header, so rows[0] is the second line of the source and
`index + 1` named the line above the one the user had to open.
Both runtimes now share importNumber.ts and importRowChecks.ts. The two number
parsers were byte-identical apart from a doc comment, and the row checks are
exactly where the runtimes drifted last time, costing 291 rows.
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { parseImportNumber } from '../src/import-number';
|
|
|
|
describe('parseImportNumber', () => {
|
|
it.each([
|
|
['2,468.13', 2468.13],
|
|
['2.468,13', 2468.13],
|
|
['1,234,567.89', 1234567.89],
|
|
['1.234.567,89', 1234567.89],
|
|
['1234,56', 1234.56],
|
|
['1 234,56', 1234.56],
|
|
['1 234 567,89', 1234567.89],
|
|
['1\u202f234.56', 1234.56],
|
|
['-1.234,56', -1234.56],
|
|
['(1,234.56)', -1234.56],
|
|
[' 42.50 ', 42.5],
|
|
[1234.56, 1234.56],
|
|
])('parses %j', (input, expected) => {
|
|
expect(parseImportNumber(input)).toBeCloseTo(expected as number, 8);
|
|
});
|
|
|
|
// A lone separator is a decimal point now, so these parse rather than reject — see
|
|
// shared/importNumber.ts. They carry the `ambiguous-separator` flag, which the import surfaces.
|
|
it.each([
|
|
['1,234', 1.23],
|
|
['1.234', 1.23],
|
|
['12,345', 12.35],
|
|
['1.000', 1],
|
|
['754.312', 754.31],
|
|
])('reads a lone separator as a decimal point: %j', (input, expected) => {
|
|
expect(parseImportNumber(input as string)).toBeCloseTo(expected as number, 8);
|
|
});
|
|
|
|
it.each([
|
|
'',
|
|
'abc',
|
|
'1,2,3',
|
|
'1,23,456',
|
|
'1.234,567.89',
|
|
'1 234',
|
|
'12 34',
|
|
'Infinity',
|
|
'(-1,234.56)',
|
|
])('rejects ambiguous or invalid %j', (input) => {
|
|
expect(parseImportNumber(input)).toBeNull();
|
|
});
|
|
});
|