/ tests / compliance / sync-unsubscribes-no-config.test.js
sync-unsubscribes-no-config.test.js
 1  /**
 2   * Test for sync-unsubscribes module without UNSUBSCRIBE_WORKER_URL configured
 3   *
 4   * sync-unsubscribes.js reads UNSUBSCRIBE_WORKER_URL at call time (inside fetchUnsubscribes).
 5   * We temporarily delete the env var during the test and restore it after.
 6   */
 7  
 8  import { test } from 'node:test';
 9  import assert from 'node:assert';
10  
11  const { syncUnsubscribes } = await import('../../src/utils/sync-unsubscribes.js');
12  
13  test('should throw error when UNSUBSCRIBE_WORKER_URL not configured', async () => {
14    // Temporarily clear the env var so fetchUnsubscribes() throws
15    const saved = process.env.UNSUBSCRIBE_WORKER_URL;
16    delete process.env.UNSUBSCRIBE_WORKER_URL;
17    try {
18      await assert.rejects(
19        async () => syncUnsubscribes(),
20        {
21          message: 'UNSUBSCRIBE_WORKER_URL not configured in .env',
22        },
23        'Should throw error when UNSUBSCRIBE_WORKER_URL is missing'
24      );
25    } finally {
26      if (saved !== undefined) process.env.UNSUBSCRIBE_WORKER_URL = saved;
27    }
28  });