Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.1 KB
Raw Blame
import { parseLogBodyForIngestion } from './log-body-parse'

describe('log-body-parse', () => {
    it('returns empty for null body', () => {
        expect(parseLogBodyForIngestion(null)).toEqual({ kind: 'empty' })
    })

    it('classifies JSON object', () => {
        const body = JSON.stringify({ a: 1 })
        const r = parseLogBodyForIngestion(body)
        expect(r).toEqual({ kind: 'json_object_or_array', value: { a: 1 } })
    })

    it('classifies JSON array', () => {
        const r = parseLogBodyForIngestion('[1,2]')
        expect(r).toEqual({ kind: 'json_object_or_array', value: [1, 2] })
    })

    it('classifies JSON string primitive', () => {
        const r = parseLogBodyForIngestion('"hi"')
        expect(r).toEqual({ kind: 'json_string', value: 'hi' })
    })

    it('classifies JSON number primitive', () => {
        const r = parseLogBodyForIngestion('42')
        expect(r).toEqual({ kind: 'json_primitive', parsed: 42 })
    })

    it('returns invalid_json on parse failure', () => {
        const raw = 'not json {'
        expect(parseLogBodyForIngestion(raw)).toEqual({ kind: 'invalid_json', raw })
    })
})