Part number now picks the longest hyphenated candidate instead of the first one, matching the documented intent and preventing a short unrelated token from being reported as the part number (which feeds the fingerprint used for sorting). Date code now only accepts YYWW candidates with a plausible year (10-39) and valid calendar week (01-53), taking the last match when several qualify; otherwise it stays null instead of guessing wrong, since a wrong value is worse than a missing one. Adds regression tests for both cases plus a no-plausible-candidate case that must yield null.
72 lines
2.4 KiB
JavaScript
72 lines
2.4 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { extractFields } from '../src/ocr-extract.js';
|
|
|
|
const REFERENZ = `SAMSUNG
|
|
Made in Philippines
|
|
K136000908252DF287
|
|
64GB 4DRx4 PC4-2400T-LD1-11-MC0
|
|
M386A8K40BM1-CRC4Y S
|
|
1908`;
|
|
|
|
test('liest alle Felder aus dem Referenz-Etikett', () => {
|
|
const spec = extractFields(REFERENZ);
|
|
assert.equal(spec.capacityGb, 64);
|
|
assert.equal(spec.rank, '4DRx4');
|
|
assert.equal(spec.speed, 'PC4-2400');
|
|
assert.equal(spec.partNumber, 'M386A8K40BM1-CRC4Y');
|
|
assert.equal(spec.dateCode, '1908');
|
|
});
|
|
|
|
test('repariert eine Verwechslung in der Geschwindigkeit', () => {
|
|
const spec = extractFields('64GB 4DRx4 PC4-24O0T-LD1-11-MC0');
|
|
assert.equal(spec.speed, 'PC4-2400');
|
|
});
|
|
|
|
test('repariert eine Verwechslung in der Kapazitaet', () => {
|
|
const spec = extractFields('BGB 1Rx8 PC4-2400');
|
|
assert.equal(spec.capacityGb, 8, 'B wird als 8 gelesen');
|
|
assert.equal(spec.rank, '1Rx8');
|
|
});
|
|
|
|
test('erkennt die Bauform aus dem Klartext, wenn vorhanden', () => {
|
|
const spec = extractFields('32GB 2Rx4 PC4-2666 RDIMM');
|
|
assert.equal(spec.formFactor, 'RDIMM');
|
|
});
|
|
|
|
test('laesst Felder offen, die nicht im Text stehen', () => {
|
|
const spec = extractFields('Oracle PN: 7325773');
|
|
assert.equal(spec.capacityGb, null);
|
|
assert.equal(spec.speed, null);
|
|
assert.equal(spec.rank, null);
|
|
});
|
|
|
|
test('unbekannte Geschwindigkeit bleibt null statt falsch geraten', () => {
|
|
const spec = extractFields('64GB 4DRx4 PC4-9999');
|
|
assert.equal(spec.speed, null);
|
|
assert.equal(spec.capacityGb, 64);
|
|
});
|
|
|
|
test('leerer Text liefert ein leeres Spec', () => {
|
|
const spec = extractFields('');
|
|
assert.equal(spec.capacityGb, null);
|
|
assert.equal(spec.partNumber, null);
|
|
});
|
|
|
|
test('waehlt bei der Teilenummer den laengsten Bindestrich-Kandidaten, nicht den ersten', () => {
|
|
const spec = extractFields(
|
|
'SAMSUNG\nAB1234SN-001\n64GB 4DRx4 PC4-2400\nM386A8K40BM1-CRC4Y\n1908',
|
|
);
|
|
assert.equal(spec.partNumber, 'M386A8K40BM1-CRC4Y');
|
|
});
|
|
|
|
test('verwirft den Datumscode, wenn mehrere vierstellige Bloecke vorkommen und nur einer plausibel ist', () => {
|
|
const spec = extractFields('SAMSUNG\n1234 5678\n64GB 2Rx4 PC4-2666\n9012\n1908');
|
|
assert.equal(spec.dateCode, '1908');
|
|
});
|
|
|
|
test('laesst den Datumscode null, wenn kein Kandidat als Jahr-Woche plausibel ist', () => {
|
|
const spec = extractFields('SAMSUNG\n9999 0060\n64GB 2Rx4 PC4-2666');
|
|
assert.equal(spec.dateCode, null);
|
|
});
|