feat(flyer-import): add cheese variant splitting and normalization rules
- 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:
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user