/** * @jest-environment jsdom * @jest-environment-options {"url": "https://go.servicetitan.com/"} */ import type { JourneyEvent } from '../../core/types'; import { sendToDatadog } from '../../sinks/datadog'; function sampleEvent(overrides: Partial = {}): JourneyEvent { return { journey: { name: 'test', team: 'test', group: 'test', service: 'test', outcome: 'good', durationMs: 120, steps: [], ...overrides, }, }; } describe('[journey] link visibility independent of failure reason', () => { const addAction = jest.fn(); const getUser = jest.fn(); beforeEach(() => { addAction.mockClear(); getUser.mockReset().mockReturnValue({ tenant: 'test_tenant', name: 'test-agent' }); (globalThis as Record).DD_RUM = { addAction, getUser }; }); afterEach(() => { delete (globalThis as Record).DD_RUM; }); test.each(['step-error', 'request-error', 'step-timeout', 'journey-timeout'])( 'always uses the same visible field for %s with host user context', reason => { sendToDatadog(sampleEvent({ outcome: 'bad', reason })); const j = addAction.mock.calls[0][1].journey; expect(j.kibana_url).toContain('https://kibana.st.dev/app/discover'); expect(j.kibana_scope).toBe('related_logs'); expect(j.failed_request_id).toBeUndefined(); expect(j.reason).toBe(reason); expect(j.outcome).toBe('bad'); } ); test('getUser failure does not lose an event without requests', () => { getUser.mockImplementation(() => { throw new Error('getUser unavailable'); }); expect(() => sendToDatadog(sampleEvent({ reason: 'step-error', outcome: 'bad' })) ).not.toThrow(); expect(addAction).toHaveBeenCalledTimes(1); expect(addAction.mock.calls[0][1].journey.outcome).toBe('bad'); }); });