: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { cleanEntityProperties } from './cleanProperties'
describe('cleanEntityProperties', () => {
it('handles empty properties', () => {
const properties = {}
const result = cleanEntityProperties(properties)
expect(result).toEqual(undefined)
})
it('handles old style properties', () => {
const properties = { utm_medium__icontains: 'email' }
const result = cleanEntityProperties(properties)
expect(result).toEqual([
{
key: 'utm_medium',
operator: 'icontains',
type: 'event',
value: 'email',
},
])
})
it('handles property filter lists', () => {
const properties = [
{ key: '$current_url', type: 'event', value: 'https://hedgebox.net/signup/', operator: 'exact' },
]
const result = cleanEntityProperties(properties)
expect(result).toEqual(properties)
})
it('handles property group values', () => {
const properties = {
type: 'AND',
values: [
{
key: '$current_url',
operator: 'exact',
type: 'event',
value: 'https://hedgebox.net/signup/',
},
],
}
const result = cleanEntityProperties(properties)
expect(result).toEqual([
{
key: '$current_url',
operator: 'exact',
type: 'event',
value: 'https://hedgebox.net/signup/',
},
])
})
it('leaves a behavioral filter without a count operator alone', () => {
const properties = [
{
key: '$pageview',
type: 'behavioral',
value: 'performed_event',
event_type: 'events',
time_value: 30,
time_interval: 'day',
},
]
const result = cleanEntityProperties(properties)
expect(result).toEqual([
{
key: '$pageview',
type: 'behavioral',
value: 'performed_event',
event_type: 'events',
time_value: 30,
time_interval: 'day',
},
])
})
it('handles negation for cohorts', () => {
let properties: any = [
{
key: 'id',
type: 'cohort',
value: 1,
operator: 'exact',
negation: false,
},
]
let result = cleanEntityProperties(properties)
expect(result).toEqual([{ key: 'id', type: 'cohort', value: 1, operator: 'exact' }])
properties = [{ key: 'id', type: 'cohort', value: 1, operator: 'exact', negation: true }]
result = cleanEntityProperties(properties)
expect(result).toEqual([{ key: 'id', type: 'cohort', value: 1, operator: 'not_in' }])
properties = [{ key: 'id', type: 'cohort', value: 1, negation: true }]
result = cleanEntityProperties(properties)
expect(result).toEqual([{ key: 'id', type: 'cohort', value: 1, operator: 'not_in' }])
})
})