31 lines
1020 B
TypeScript
31 lines
1020 B
TypeScript
import { analyticsEventRegistry, validateAnalyticsEvent } from '@/lib/analytics/events';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const context = {
|
|
routeId: 'home',
|
|
locale: 'en',
|
|
direction: 'ltr',
|
|
resolvedTheme: 'light',
|
|
source: 'hero',
|
|
} as const;
|
|
|
|
describe('analytics contract', () => {
|
|
it('accepts allowlisted non-personal demo events', () => {
|
|
expect(validateAnalyticsEvent('demo_open', context)).toEqual({ name: 'demo_open', context });
|
|
});
|
|
|
|
it('rejects unknown events and payload properties', () => {
|
|
expect(validateAnalyticsEvent('lead_created', context)).toBeNull();
|
|
expect(
|
|
validateAnalyticsEvent('demo_open', { ...context, email: 'person@example.test' }),
|
|
).toBeNull();
|
|
});
|
|
|
|
it('marks every registry entry as non-personal and consent-gated', () => {
|
|
expect(analyticsEventRegistry.every((event) => !event.personalData)).toBe(true);
|
|
expect(analyticsEventRegistry.every((event) => event.consentCategory === 'analytics')).toBe(
|
|
true,
|
|
);
|
|
});
|
|
});
|