| 1234567891011 |
- import assert from 'node:assert/strict';
- import test from 'node:test';
- import { buildCompetitorListingAlerts } from '../src/modules/competitor-listing-monitor/alerts.js';
- import type { CompetitorListingChange } from '../src/modules/competitor-listing-monitor/domain.js';
- const change = (id: string, productId: string, before: number, after: number): CompetitorListingChange => ({ id, naturalKey: id, workspaceId: 'ws', platform: 'jd', productId, previousSnapshotId: 'p', currentSnapshotId: 'c', detectedAt: '2026-01-01T00:00:00.000Z', changeTypes: ['price'], changes: [{ field: 'priceCents', before, after }] });
- test('alerts emit field rules and a deterministic multi-competitor direction warning', () => {
- const alerts = buildCompetitorListingAlerts([change('a','c1',100,90), change('b','c2',200,180)]);
- assert.ok(alerts.some((alert) => alert.rule === 'price_change' && alert.productIds[0] === 'c1'));
- assert.ok(alerts.some((alert) => alert.rule === 'multi_competitor_direction' && alert.productIds.length === 2));
- assert.equal(buildCompetitorListingAlerts([change('a','c1',100,90)])[0]!.id.length, 32);
- });
|