← back to Homesonspec

apps/mobile/lib/tracker-policy.test.mjs

32 lines

import assert from 'node:assert/strict';
import test from 'node:test';

import { isTrackerUrl } from './tracker-policy.ts';

test('blocks known analytics and advertising hosts and subdomains', () => {
  const blocked = [
    'https://www.googletagmanager.com/gtm.js?id=GTM-123',
    'https://region1.google-analytics.com/g/collect',
    'https://connect.facebook.net/en_US/fbevents.js',
    'https://www.facebook.com/tr?id=123',
    'https://stats.g.doubleclick.net/j/collect',
    'HTTPS://GOOGLESYNDICATION.COM/pagead/id',
  ];

  for (const url of blocked) assert.equal(isTrackerUrl(url), true, url);
});

test('allows first-party, lookalike, relative, and malformed URLs', () => {
  const allowed = [
    'https://homesonspec.com/',
    'https://homesonspec.com/homes/abc?next=google-analytics.com',
    'https://google-analytics.com.example.org/collect',
    'https://notfacebook.com/tr',
    '/homes/abc',
    '',
    'not a URL',
  ];

  for (const url of allowed) assert.equal(isTrackerUrl(url), false, url);
});