competitor-listing-alerts.test.ts 1.1 KB

1234567891011
  1. import assert from 'node:assert/strict';
  2. import test from 'node:test';
  3. import { buildCompetitorListingAlerts } from '../src/modules/competitor-listing-monitor/alerts.js';
  4. import type { CompetitorListingChange } from '../src/modules/competitor-listing-monitor/domain.js';
  5. 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 }] });
  6. test('alerts emit field rules and a deterministic multi-competitor direction warning', () => {
  7. const alerts = buildCompetitorListingAlerts([change('a','c1',100,90), change('b','c2',200,180)]);
  8. assert.ok(alerts.some((alert) => alert.rule === 'price_change' && alert.productIds[0] === 'c1'));
  9. assert.ok(alerts.some((alert) => alert.rule === 'multi_competitor_direction' && alert.productIds.length === 2));
  10. assert.equal(buildCompetitorListingAlerts([change('a','c1',100,90)])[0]!.id.length, 32);
  11. });