import { afterEach, describe, expect, it, vi } from 'vitest'; import { initEncryption, _resetEncryptor } from './field-encrypt.js'; describe('field encryption platform flag polling', () => { afterEach(() => { vi.unstubAllGlobals(); _resetEncryptor(); }); it('propagates x-request-id when polling platform-service flags', async () => { const fetchMock = vi.fn(async () => new Response(JSON.stringify({ flags: { encryption_enabled: true } }), { status: 200 })); vi.stubGlobal('fetch', fetchMock); await initEncryption('notelett', { info: vi.fn() }, 'platform-req-1'); expect(fetchMock).toHaveBeenCalledOnce(); const init = fetchMock.mock.calls[0]?.[1] as RequestInit; expect(init.headers).toMatchObject({ 'x-product-id': 'notelett', 'x-request-id': 'platform-req-1', }); }); });