feat(flyer-import): add cheese variant splitting and normalization rules
Test Suite / backend-pr-quick (push) Has been skipped
Test Suite / quick-import-pr-quick (push) Has been skipped
Test Suite / backend-full (push) Successful in 5m48s
Test Suite / flutter-quality (push) Failing after 1m9s

- Add logic to split Swedish cheese variants (Präst, Herrgård, Grevé) into separate products
- Implement brand normalization for "Arla Ko" and category assignment to "Hårdost"
- Update flyer parser with detailed rules for bundle/group announcements
- Add unit tests for variant splitting and brand/category normalization
- Replace single-item return with flatMap for expanded product lists
This commit is contained in:
Nils-Johan Gynther
2026-05-21 14:44:37 +02:00
parent 47c89c9915
commit 2d94a83e73
3 changed files with 161 additions and 9 deletions
@@ -105,5 +105,41 @@ describe('FlyerNormalizerService', () => {
const result2 = service.normalize(undefined as any);
expect(result2).toEqual([]);
});
it('splits listed cheese variants into separate products', () => {
const items = [
{
rawName: 'PRÄST®, HERRGÅRD®, GREVÉ®',
brand: 'ARLA KO',
unit: 'kg',
comparisonPrice: '79,90',
offer: ['Max 3 förp/hushåll'],
},
];
const result = service.normalize(items);
expect(result).toHaveLength(3);
expect(result.map((item) => item.rawName)).toEqual(['Prastost', 'Herrgardsost', 'Greveost']);
expect(result.every((item) => item.brand === 'Arla Ko')).toBe(true);
expect(result.every((item) => item.categoryHint === 'Hårdost')).toBe(true);
expect(result[0].parseReasons).toContain('split_cheese_variants');
});
it('keeps single cheese item unsplit but normalizes brand/category', () => {
const items = [
{
rawName: 'Prästost',
brand: 'arla ko',
},
];
const result = service.normalize(items);
expect(result).toHaveLength(1);
expect(result[0].rawName).toBe('Prästost');
expect(result[0].brand).toBe('Arla Ko');
expect(result[0].categoryHint).toBe('Hårdost');
});
});
});