92 lines
3.3 KiB
TypeScript
92 lines
3.3 KiB
TypeScript
import { parseActionListing } from './action';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { dirkItem } from './dirk';
|
|
import { hoogvlietCategory, hoogvlietItem } from './hoogvliet';
|
|
|
|
describe('dirk', () => {
|
|
it('maps a product with an offer', () => {
|
|
const it = dirkItem(
|
|
{
|
|
productId: 1,
|
|
normalPrice: 2.85,
|
|
offerPrice: 1.39,
|
|
endDate: '2026-10-27T00:00:00',
|
|
productInformation: {
|
|
headerText: 'Alpro Vanille',
|
|
packaging: '1 l',
|
|
brand: 'Alpro',
|
|
department: 'Zuivel & kaas',
|
|
webgroup: 'Melk'
|
|
}
|
|
},
|
|
4,
|
|
60
|
|
);
|
|
expect(it).toMatchObject({
|
|
priceCents: 285,
|
|
promoPriceCents: 139,
|
|
category: 'Zuivel & eieren',
|
|
promoLabel: 'Actie · t/m 27-10'
|
|
});
|
|
});
|
|
it('flags drugstore as non-food but baby food as food', () => {
|
|
const base = { productId: 2, normalPrice: 1, productInformation: { headerText: 'x' } };
|
|
expect(dirkItem(base, 10, 120)?.isFood).toBe(false);
|
|
expect(dirkItem(base, 10, 100)?.isFood).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('hoogvliet', () => {
|
|
it('prefers a real tree over theme trees and keeps the deepest path', () => {
|
|
expect(
|
|
hoogvlietCategory(['aanbiedingen', 'huishouden-non-food', 'huishouden-non-food/schoonmaken'])
|
|
).toEqual({
|
|
category: 'Huishouden & dieren',
|
|
isFood: false,
|
|
path: 'huishouden-non-food/schoonmaken'
|
|
});
|
|
});
|
|
it('drops in-store EANs and skips promotion groups', () => {
|
|
const p = {
|
|
sku: '980498000',
|
|
name: 'Casino wit',
|
|
url_key: 'hoogvliet-casino-wit-980498000',
|
|
metadata: JSON.stringify({ ean: '2140040000000', merk: 'Hoogvliet' }),
|
|
price_range: {
|
|
minimum_price: { regular_price: { value: 1.48 }, final_price: { value: 1.48 } }
|
|
},
|
|
categories: [{ level: 2, url_path: 'bakkerij' }]
|
|
};
|
|
expect(hoogvlietItem(p, new Map())).toMatchObject({
|
|
gtin: null,
|
|
name: 'Hoogvliet Casino wit',
|
|
url: 'https://hoogvliet.nl/product/hoogvliet-casino-wit-980498000'
|
|
});
|
|
expect(
|
|
hoogvlietItem({ ...p, metadata: JSON.stringify({ promo_products: '["1"]' }) }, new Map())
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('action', () => {
|
|
const card = `<div data-testid="product-card" data-content-king="product-card"><a class="g" href="/nl-nl/p/3223916/natural-happiness-pittenmix/" data-testid="product-card-link"><span><img data-testid="product-card-image" alt="" srcSet="x 128w" src="https://asset.action.com/image/upload/t_digital_product_image/w_1920/3223916_8711299010862-111_01_h7ywzh.webp"/></span><span><span data-testid="product-card-title">Natural Happiness pittenmix & zo</span><span class="x" data-testid="product-card-description">300 gram</span></span><span aria-label="€\u00a01,99 €\u00a06,63/kg" class="flex"><span data-testid="product-card-price-description" class="m">€\u00a06,63/kg</span></span></a></div>`;
|
|
it('parses a listing card', () => {
|
|
const [it] = parseActionListing(
|
|
card + card,
|
|
{ category: 'Snoep, koek & chips', isFood: true },
|
|
'eten--drinken/noten--snacks'
|
|
);
|
|
expect(it).toMatchObject({
|
|
storeProductId: '3223916',
|
|
name: 'Natural Happiness pittenmix & zo',
|
|
sizeText: '300 gram',
|
|
priceCents: 199,
|
|
storeUnitPrice: { cents: 663, unit: 'kg' },
|
|
gtin: '8711299010862',
|
|
url: 'https://www.action.com/nl-nl/p/3223916/natural-happiness-pittenmix/',
|
|
categoryPath: 'eten & drinken > noten & snacks',
|
|
isFood: true
|
|
});
|
|
});
|
|
});
|